Pure-JS implementation of MS-CFB: Compound File Binary File Format, a container format used in many Microsoft file types (XLS, DOC, VBA blobs in XLSX and XLSB)
In the browser:
$ npm install cfb
xlscfb.js file is designed to be embedded in js-xlsx
var CFB = ;
For example, to get the Workbook content from an XLS file:
var cfb = CFB;var workbook = CFB;var data = workbookcontent;
It is preferable to install the library globally with npm:
$ npm install -g cfb
The global installation adds a command
cfb which can work with existing files:
cfb filewill extract the contents of the file to the current directory. It will make the corresponding subdirectories.
cfb --list-files filewill show a listing of the contained files. The format follows the
unzip -l"short format".
cfb --repair filewill attempt to repair by reading and re-writing the file. This fixes some issues with files generated by non-standard tools.
TypeScript definitions are maintained in
The CFB object exposes the following methods and properties:
CFB.parse(blob) takes a nodejs Buffer or an array of bytes and returns an
parsed representation of the data.
CFB.read(blob, opts) wraps
opts.type controls the behavior:
blobis interpreted as a file name that will be read
blobis interpreted as base64 string
blobis interpreted as binary string
blobis interpreted as nodejs buffer or array of bytes
CFB.find(cfb, path) performs a case-insensitive match for the path (or file
name, if there are no slashes) and returns an entry object or null if not found.
CFB.write(cfb, opts) generates a file based on the container.
controls the behavior:
base64: returns a base64 string
binary: returns a binary string
CFB.writeFile(cfb, filename, opts) creates a file with the specified name.
The utility functions are available in the
CFB.utils object. Functions that
name argument strictly deal with absolute file names:
.cfb_new(?opts)creates a new container object.
.cfb_add(cfb, name, ?content, ?opts)adds a new file to the
.cfb_del(cfb, name)deletes the specified file
.cfb_mov(cfb, old_name, new_name)moves the old file to new path and name
The objects returned by
read have the following properties:
.FullPaths is an array of the names of all of the streams (files) and
storages (directories) in the container. The paths are properly prefixed from
the root entry (so the entries are unique)
.FullPathDir is an object whose keys are entries in
.FullPaths and whose
values are objects with metadata and content (described below)
.FileIndex is an array of the objects from
.FullPathDir, in the same order
.raw contains the raw header and sectors
The entry objects are available from
FileIndex elements of
the container object:
Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 License are reserved by the Original Author.