💾 OLE File Container Format
Go to file
SheetJS 0e33eb6e13 unify changes with main sheetjs project
- Fixed issue #14 h/t @wisekaa03
- CFB write truncate file names exceeding 32 characters

Co-authored-by: Stanislav Vyaliy <wisekaa03@gmail.com>
2022-03-31 04:57:58 -04:00
.github/workflows testing 2022-03-30 13:27:33 -04:00
bits unify changes with main sheetjs project 2022-03-31 04:57:58 -04:00
dist version bump 1.2.1: DEFLATE 2021-09-06 15:53:23 -04:00
misc version bump 1.2.0: MAD 2020-07-09 02:20:52 -04:00
packages/cfb-cli version bump 1.2.0: MAD 2020-07-09 02:20:52 -04:00
types version bump 1.2.0: MAD 2020-07-09 02:20:52 -04:00
.eslintrc version bump 1.05: non-display char strict search 2018-03-04 22:49:40 -05:00
.flowconfig flow switch to module.exports 2018-04-21 10:16:31 -04:00
.gitignore version bump 1.2.0: MAD 2020-07-09 02:20:52 -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 1.2.0: MAD 2020-07-09 02:20:52 -04:00
cfb.flow.js version bump 1.2.1: DEFLATE 2021-09-06 15:53:23 -04:00
cfb.js unify changes with main sheetjs project 2022-03-31 04:57:58 -04:00
CHANGELOG.md version bump 1.2.1: DEFLATE 2021-09-06 15:53:23 -04:00
fails.lst version bump 1.1.0: zip support 2018-09-04 03:16:24 -04:00
index.html version bump 1.2.1: DEFLATE 2021-09-06 15:53:23 -04:00
LICENSE Included full license text [ci skip] 2019-10-07 23:13:37 -04:00
Makefile version bump 1.2.0: MAD 2020-07-09 02:20:52 -04:00
package.json Remove unused dependency 2022-03-30 09:51:13 +02:00
README.md version bump 1.2.1: DEFLATE 2021-09-06 15:53:23 -04:00
shim.js version bump 1.0.6: performance 2018-04-09 02:33:22 -04:00
test.js version bump 1.1.4: detect sector cycle (fixes #8) 2020-03-13 01:58:41 -04:00
xlscfb.flow.js version bump 1.2.1: DEFLATE 2021-09-06 15:53:23 -04:00
xlscfb.js version bump 1.2.1: DEFLATE 2021-09-06 15:53:23 -04:00

Container File Blobs

Pure JS implementation of various container file formats, including ZIP and CFB.

Build Status Coverage Status Dependencies Status NPM Downloads 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

The cfb-cli module ships with a CLI tool for manipulating and inspecting supported files.

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.

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.

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

Parse Options

CFB.read takes an options argument. 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))
"buffer" nodejs Buffer
"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])

Write Options

CFB.write and CFB.writeFile take options argument.

opts.type controls the behavior:

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

opts.fileType controls the output file type:

fileType output
'cfb' (default) CFB container
'zip' ZIP file
'mad' MIME aggregate document

opts.compression enables DEFLATE compression for ZIP file type.

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. Set the option {unsafe:true} to skip existence checks (for bulk additions)
  • .cfb_del(cfb, name) deletes the specified file
  • .cfb_mov(cfb, old_name, new_name) moves the old file to new path and name
  • .use_zlib(require("zlib")) loads a nodejs zlib instance.

By default, the library uses a pure JS inflate/deflate implementation. NodeJS zlib.InflateRaw exposes the number of bytes read in versions after 8.11.0. If a supplied zlib does not support the required features, a warning will be displayed in the console and the pure JS fallback will be used.

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 */
  ctype?: String; /** Content-Type (for MAD) */
}

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