💾 OLE File Container Format
Go to file
2017-11-27 00:41:39 -05:00
bin version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
bits version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
dist version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
misc version bump 0.14.0: removed FullPathDir 2017-11-04 20:15:50 -04:00
types version bump 0.14.0: removed FullPathDir 2017-11-04 20:15:50 -04:00
.eslintrc version bump 0.12.0: refresh 2017-07-28 13:53:08 -04:00
.flowconfig version bump 0.13.2 2017-10-20 16:36:54 -04:00
.gitignore version bump 0.13.0: write 2017-09-14 17:14:22 -04:00
.jscs.json version bump 0.10.0: performance 2014-06-24 00:00:39 -04:00
.jshintrc version bump 0.6.0: case insensitive find 2013-10-29 11:54:56 -07:00
.spelling version bump 0.13.2 2017-10-20 16:36:54 -04:00
.travis.yml version bump 0.14.0: removed FullPathDir 2017-11-04 20:15:50 -04:00
cfb.flow.js version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
cfb.js version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
CHANGELOG.md version bump 1.0.0: walk minifat 2017-11-05 11:54:11 -05:00
fails.lst version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
index.html version bump 0.13.2 2017-10-20 16:36:54 -04:00
LICENSE version bump 0.10.3: ignore bad FAT 2017-02-23 21:11:45 -08:00
Makefile version bump 0.13.2 2017-10-20 16:36:54 -04:00
package.json version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
README.md version bump 0.13.2 2017-10-20 16:36:54 -04:00
shim.js added shim to html 2017-09-28 02:20:50 -04:00
test.js version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
xlscfb.flow.js version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00
xlscfb.js version bump 1.0.1: find multiple \x01-\x06 chars 2017-11-27 00:41:39 -05:00

Compound File Binary Format

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)

Build Status Coverage Status Dependencies Status NPM Downloads ghit.me Analytics

Installation

In the browser:

<script src="dist/cfb.min.js" type="text/javascript"></script>

With npm:

$ npm install cfb

The xlscfb.js file is designed to be embedded in js-xlsx

Library Usage

In node:

var CFB = require('cfb');

For example, to get the Workbook content from an Excel 2003 XLS file:

var cfb = CFB.read(filename, {type: 'file'});
var workbook = CFB.find(cfb, 'Workbook');
var data = workbook.content;

Command-Line Utility Usage

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 files:

  • cfb file [names...] extracts the contents of the file. If additional names are supplied, only the listed files will be extracted.

  • cfb -l file lists the contained files (following unzip -l "short format")

  • cfb -r file attempts to repair by reading and re-writing the file. This fixes some issues with files generated by non-standard tools.

  • cfb -c file [files...] creates a new file containing the listed files. The default root entry name is Root Entry.

  • cfb -a file [files...] adds the listed files to the original file.

  • cfb -d file [files...] deletes the listed files from the original file.

JS API

TypeScript definitions are maintained in types/index.d.ts.

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 parse. opts.type controls the behavior:

type expected input
"base64" string: Base64 encoding of the file
"binary" string: binary string (byte n is data.charCodeAt(n))
"file" string: path of file that will be read (nodejs only)
(default) buffer or array of 8-bit unsigned int (byte n is data[n])

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. opts.type controls the behavior:

type output
"base64" string: Base64 encoding of the file
"binary" string: binary string (byte n is data.charCodeAt(n))
(default) buffer if available, array of 8-bit unsigned int otherwise

CFB.writeFile(cfb, filename, opts) creates a file with the specified name.

Utility Functions

The utility functions are available in the CFB.utils object. Functions that accept a 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.
  • .cfb_del(cfb, name) deletes the specified file
  • .cfb_mov(cfb, old_name, new_name) moves the old file to new path and name

Container Object Description

The objects returned by parse and 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)

  • .FileIndex is an array, in the same order as .FullPaths, whose values are objects following the schema:

interface CFBEntry {
  name: string; /** Case-sensitive internal name */
  type: number; /** 1 = dir, 2 = file, 5 = root ; see [MS-CFB] 2.6.1 */
  content: Buffer | number[] | Uint8Array; /** Raw Content */
  ct?: Date; /** Creation Time */
  mt?: Date; /** Modification Time */
}

License

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.

References

OSP-covered Specifications (click to show)
  • [MS-CFB]: Compound File Binary File Format