CFB container API
XLSX.CFB works with Compound File Binary containers used by legacy Office
formats. Container operations do not convert worksheet cells. For spreadsheet
input/output, use XLSX.read and XLSX.write instead.
The namespace is typed as any in the bundled declarations. A container has
parallel FullPaths and FileIndex arrays. Stream entries have a name, type,
size and byte content; storage/root entries represent directories.
Read, find and write
Section titled “Read, find and write”| Signature | Parameters and semantics | Returns |
|---|---|---|
read(data, options?) |
Parse data according to options.type; default input representation is base64 |
Container |
parse(bytes, options?) |
Parse raw byte input; for ZIP input, supply an options object even if empty | Container |
find(container, path) |
Find a stream/storage entry by container path | Entry, or null if absent |
write(container, options?) |
Serialize a container; default output representation is buffer | Serialized data |
writeFile(container, filename, options?) |
Serialize and save a file in Node | No result to consume |
version |
Container-library version | String |
Input type values include "base64", "binary", "buffer", "array",
and "file". File input reads a Node filesystem path. Unlike top-level
XLSX.read, prefer an explicit type for a clear container-input contract.
Output type can be "buffer", "array", "binary", "base64", or "file".
File mode uses options.filename; prefer writeFile for clarity.
fileType chooses a container representation such as "cfb" or "zip";
compression: true requests ZIP compression. Reading a ZIP container here does
not automatically parse it as a spreadsheet workbook.
const XLSX = require("@agent-sheet/wasm");const assert = require("node:assert/strict");const CFB = XLSX.CFB;const container = CFB.utils.cfb_new();CFB.utils.cfb_add(container, "note.txt", Buffer.from("Hello", "utf8"));const bytes = CFB.write(container, { type: "buffer" });const result = CFB.read(bytes, { type: "buffer" });const entry = CFB.find(result, "note.txt");assert.equal(Buffer.from(entry.content).toString("utf8"), "Hello");assert.equal(CFB.find(result, "missing.txt"), null);Container utilities
Section titled “Container utilities”These functions are under XLSX.CFB.utils.
| Signature | Parameters and semantics | Returns |
|---|---|---|
cfb_new(options?) |
Create an empty container; root can name the root storage |
Container |
cfb_add(container, path, content, options?) |
Add or replace a stream at path using byte content |
Stream entry |
cfb_del(container, path) |
Delete a matching entry | Boolean indicating success |
cfb_mov(container, oldPath, newPath) |
Rename/move an entry | Boolean indicating success |
cfb_gc(container) |
Rebuild container ordering and directory metadata after changes | No result to consume |
These operations mutate the container. Use paths relative to its root, such as
"documents/note.txt". cfb_add can take entry options such as creation and
modification dates. Writing performs the container preparation needed for output.
const XLSX = require("@agent-sheet/wasm");const assert = require("node:assert/strict");const CFB = XLSX.CFB;const container = CFB.utils.cfb_new();CFB.utils.cfb_add(container, "draft.txt", Buffer.from("Draft"));assert.equal(CFB.utils.cfb_mov(container, "draft.txt", "final.txt"), true);assert.equal(CFB.find(container, "final.txt").name, "final.txt");assert.equal(CFB.utils.cfb_del(container, "final.txt"), true);assert.equal(CFB.find(container, "final.txt"), null);Byte utilities
Section titled “Byte utilities”These are low-level utilities, not workbook functions:
| Signature | Meaning | Returns |
|---|---|---|
bconcat(chunks) |
Concatenate byte chunks | Byte data |
prep_blob(blob, position) |
Add cursor-based read/write methods to a byte object and set its starting cursor | No result to consume |
ReadShift(size, type?) |
Read from a prepared byte object’s cursor; call as its method | Decoded value |
CheckField(hex, field?) |
Check bytes at the current cursor against expected hex | No result to consume; throws on mismatch |
use_zlib(zlib) |
Supply compatible Node zlib routines for compression | No result to consume |
utils.consts exposes CFB sector and entry-type constants. Underscore-prefixed
compression routines are also exposed; prefer container read/write options over
calling them directly.
Scope and limits
Section titled “Scope and limits”CFB does not provide encrypted-workbook support. Preserving a macro stream is
not the same as executing it. To parse a BIFF workbook already stored in a CFB
container, the full distribution offers XLSX.parse_xlscfb(container, options);
this parser is absent from mini. See Top-level API.