Skip to content

feat(datamap): write msgpack via ant_core::data::write_datamap#97

Open
Nic-dorman wants to merge 1 commit into
mainfrom
feat/datamap-msgpack-write
Open

feat(datamap): write msgpack via ant_core::data::write_datamap#97
Nic-dorman wants to merge 1 commit into
mainfrom
feat/datamap-msgpack-write

Conversation

@Nic-dorman
Copy link
Copy Markdown
Contributor

Summary

Closes the ant-gui → ant-cli round-trip gap. The read side already delegates to `ant_core::data::read_datamap` (sniffs first byte: msgpack canonical, JSON legacy), but the write side was still on the local JSON path — so a datamap produced by ant-gui couldn't be opened by `ant file download --datamap` (msgpack-only).

After this PR, ant-gui uploads produce `..datamap` (e.g. `holiday.jpg.datamap`), msgpack-encoded, and read back cleanly in any consumer of `ant_core::data`.

Changes

  • `src-tauri/src/config.rs` — `write_datamap_for` now takes `&DataMap` and delegates to `ant_core::data::write_datamap`. Drops the local sanitize-stem helper, the `MAX_COLLISION_ATTEMPTS` loop, the `DATAMAP_EXTENSION` constant, and the `std::io::Write` / `std::path::Path` imports. Upstream handles sanitization, atomic tempfile-and-rename, parent-dir fsync on Unix, and the `NumericSuffix` collision policy.
  • `src-tauri/src/autonomi_ops.rs` — three call sites in `confirm_upload`, `confirm_upload_merkle`, and `wallet_upload` pass `&result.data_map` instead of the JSON string. The `data_map_json` re-encoding and SHA-derived `address` stay; only the on-disk encoding moves.

Net diff: -47 lines.

Compatibility

Existing `upload_history.json` entries reference JSON datamaps on disk via their `data_map_file` path. Those keep working — `read_datamap_file` already accepts both formats. New uploads write msgpack with the extension-preserved naming. Coexistence is intentional; no migration is needed.

Test plan

  • Build clean: `cargo check` passes (verified locally — 0 warnings)
  • CI vitest (no JS changes in this PR; existing tests should pass)
  • Manual: upload a small file (e.g. `test.pdf`). Confirm `%APPDATA%\autonomi\ant-gui\test.pdf.datamap` exists, content's first byte is not `0x7B` (`{`).
  • Manual: open the same datamap via Download by Datamap inside ant-gui → should download successfully.
  • Manual round-trip: copy the new `test.pdf.datamap` to a machine with `ant-cli`, run `ant file download --datamap test.pdf.datamap` → should succeed (this is the gap this PR closes).
  • Regression: download an existing entry from before this PR (the old `.datamap` JSON files) → should still work.
  • Collision: upload two files named `test.pdf` in succession; second produces `test.pdf-2.datamap` (or upstream's actual suffix scheme), not an overwrite.

🤖 Generated with Claude Code

The read side already delegates to ant_core::data::read_datamap (sniffs
the first byte, msgpack canonical / JSON legacy). The write side was
still on the local JSON path, which left ant-gui-produced datamaps
unreadable by ant-cli's msgpack-only deserializer — closing this gap
makes the on-disk format round-trip across tools.

Three changes:

1. config::write_datamap_for now takes &DataMap (not the JSON string)
   and delegates to ant_core::data::write_datamap. msgpack on disk,
   <name>.<ext>.datamap naming (extension preserved), and upstream's
   CollisionPolicy::NumericSuffix replaces the local collision loop.

2. Drop sanitize_stem, MAX_COLLISION_ATTEMPTS, DATAMAP_EXTENSION, and
   std::io::Write / std::path::Path imports. Upstream handles
   sanitization + atomic tempfile-and-rename + parent-dir fsync on Unix.

3. The three call sites in autonomi_ops.rs pass &result.data_map
   directly. The data_map_json and SHA-derived address derivations are
   unchanged — only the on-disk encoding moves.

Existing upload_history.json entries keep working: their data_map_file
paths still point at JSON datamaps on disk, and read_datamap accepts
both formats. New uploads write msgpack with the new naming. No
migration needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant