Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

💾 OLE File Container Format

License

NotificationsYou must be signed in to change notification settings

SheetJS/js-cfb

Repository files navigation

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

Build StatusCoverage StatusDependencies StatusNPM DownloadsAnalytics

Installation

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

Library Usage

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;

Command-Line Utility Usage

Thecfb-cli module ships with a CLItool for manipulating and inspecting supported files.

JS API

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.

Parse Options

CFB.read takes an options argument.opts.type controls the behavior:

typeexpected 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])

Write Options

CFB.write andCFB.writeFile take options argument.

opts.type controls the behavior:

typeoutput
"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:

fileTypeoutput
'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 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.

Container Object Description

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) */}

License

Please consult the attached LICENSE file for details. All rights not explicitlygranted by the Apache 2.0 License are reserved by the Original Author.

References

Packages

No packages published

Contributors8


[8]ページ先頭

©2009-2025 Movatter.jp