- Notifications
You must be signed in to change notification settings - Fork15
💾 OLE File Container Format
License
SheetJS/js-cfb
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Pure JS implementation of various container file formats, including ZIP and CFB.
In the browser:
<scriptsrc="dist/cfb.min.js"type="text/javascript"></script>
Withnpm:
$ npm install cfb
Thexlscfb.js
file is designed to be embedded injs-xlsx
In node:
varCFB=require('cfb');
For example, to get the Workbook content from an Excel 2003 XLS file:
varcfb=CFB.read(filename,{type:'file'});varworkbook=CFB.find(cfb,'Workbook');vardata=workbook.content;
Thecfb-cli
module ships with a CLItool for manipulating and inspecting supported files.
TypeScript definitions are maintained intypes/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 anparsed representation of the data.
CFB.read(blob, opts)
wrapsparse
.
CFB.find(cfb, path)
performs a case-insensitive match for the path (or filename, 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.
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 (byten isdata.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 (byten isdata[n] ) |
CFB.write
andCFB.writeFile
take options argument.
opts.type
controls the behavior:
type | output |
---|---|
"base64" | string: Base64 encoding of the file |
"binary" | string: binary string (byten isdata.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.
The utility functions are available in theCFB.utils
object. Functions thataccept aname
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 thecfb
.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 nodejszlib
instance.
By default, the library uses a pure JS inflate/deflate implementation. NodeJSzlib.InflateRaw
exposes the number of bytes read in versions after8.11.0
.If a suppliedzlib
does not support the required features, a warning will bedisplayed in the console and the pure JS fallback will be used.
The objects returned byparse
andread
have the following properties:
.FullPaths
is an array of the names of all of the streams (files) andstorages (directories) in the container. The paths are properly prefixed fromthe root entry (so the entries are unique).FileIndex
is an array, in the same order as.FullPaths
, whose values areobjects following the schema:
interfaceCFBEntry{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) */}
Please consult the attached LICENSE file for details. All rights not explicitlygranted by the Apache 2.0 License are reserved by the Original Author.
MS-CFB
: Compound File Binary File Format- ZIP
APPNOTE.TXT
: .ZIP File Format Specification - RFC1951:https://www.ietf.org/rfc/rfc1951.txt
- RFC2045:https://www.ietf.org/rfc/rfc2045.txt
- RFC2557:https://www.ietf.org/rfc/rfc2557.txt
About
💾 OLE File Container Format
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.