Files
craft-libs/crates/doc-binary
aiongg ca58dfe6c9 Merge storytold main into next (19 Nov sync)
Merges main at d7c9632bfb.

- Cargo.toml: both sides' new workspace crates (next's font-subset, harfbuzz-subset-sys and
  host; main's gpu, gpu-null, gpu-providers and gpu-wgpu).
- crates/jpeg: next split lib.rs into modules; main's reduced-size decoding goes to them: the
  scaled IDCT, reconstruction and render_scaled to idct.rs, MAX_SHRINK, reduced_estimate and
  decode_reduced stay public in lib.rs. Main's new test added; the frame test next removed
  stays removed.
- crates/audio, crates/media: next builds the integration tests into the library's test
  executable (autotests off, tests/main.rs); main's new DSD and MPEG-TS mux tests are modules
  there behind their features instead of [[test]] targets, and the mux tests reach their shared
  helper module through the integration module.
- crates/media/src/matroska/track.rs: main's new FFV1 codec-parameter test added; the test
  modules next removed stay removed.
- crates/file-formats: main's JXL capability test, which asks the codec whether JXL reads,
  replaces next's interim check.
2026-11-19 16:22:24 +00:00
..

craft-doc-binary

Reader and writer for the Word 97-2003 binary file format (.doc, [MS-DOC]) and the craft-wordmodel document model. It is WordCraft's reader and writer, on craft-cfb for the compound file and craft-codepage for 8-bit text.

// Not a compound file: an error, never a panic.
assert!(craft_doc_binary::read(b"not a .doc").is_err());
assert!(!craft_doc_binary::is_encrypted(b"not a .doc"));

// A document written as a .doc reads back.
let bytes = craft_doc_binary::write(&craft_wordmodel::Document::from_text("Hello")).unwrap();
let doc = craft_doc_binary::read(&bytes).unwrap();
assert_eq!(doc.body[0].as_para().map(|p| p.text.as_str()), Some("Hello"));
  • read(bytes), read_with_password(bytes, Option<&str>), is_encrypted(bytes), write(&document).
  • Text in pieces (8-bit and UTF-16), paragraph and character formatting, styles, lists, tables, sections, headers and footers, notes, comments, fields, bookmarks, pictures and OfficeArt shapes, document properties.
  • XOR obfuscation, RC4 and RC4 CryptoAPI password protection.
  • Tracked insertions and deletions, with their author and time.

write produces a Word 97-2003 file (nFib 0x00C1, a version 3 compound file): text, character and paragraph formatting, styles, fonts, lists, tables, sections with headers and footers, footnotes and endnotes, fields and hyperlinks, bookmarks, inline pictures, tracked insertions and deletions, and the document properties. Floating pictures are written in line, nested tables become paragraphs of their cell, and shapes, charts, text boxes and comments are left out, each kind logged once per save. It never writes a password-protected file.

Limits

Streams (1 GiB each, refused by craft-cfb before anything is allocated), paragraphs, pieces, property counts, table nesting and drawing records are capped; the constants are in the source next to what they bound, and each has a test. Hostile input gives an error or a best-effort document, never a panic.