Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
The cfb npm package is a library designed for handling CFB (Compound File Binary) files, also known as Microsoft Compound Document File Format. This format is commonly used in older Microsoft Office documents like .doc, .xls, and .ppt files. The package allows for the creation, manipulation, and extraction of data from these files.
Reading CFB files
This code demonstrates how to read a CFB file from the filesystem. It uses the `read` method of the cfb package to load a file named 'test.xls' and logs the resulting data structure to the console.
const CFB = require('cfb');
const cfb = CFB.read('test.xls', {type: 'file'});
console.log(cfb);
Creating CFB files
This example shows how to create a new CFB file with a file named 'newfile.txt' inside it. It demonstrates creating a new CFB structure, adding a file to it, and then writing the CFB structure to a file named 'output.cfb'.
const CFB = require('cfb');
const cfb = CFB.utils.cfb_new();
CFB.utils.cfb_add(cfb, 'newfile.txt', new Uint8Array([1, 2, 3, 4, 5]));
CFB.write(cfb, 'output.cfb');
Extracting files from CFB containers
This snippet illustrates how to extract a file from a CFB container. It reads a CFB file named 'container.cfb', searches for a file named '/WordDocument' within the container, and logs its content.
const CFB = require('cfb');
const cfb = CFB.read('container.cfb', {type: 'file'});
const fileContent = CFB.find(cfb, '/WordDocument');
console.log(fileContent);
js-xlsx is a comprehensive library for parsing and writing spreadsheets in various formats including XLSX/XLSM/XLSB/XLS/ODS. It offers broader functionality for spreadsheet manipulation compared to cfb, which is focused on the CFB file format.
This is a Pure-JS implementation of MS-CFB: Compound File Binary File Format, a format used in many Microsoft file types (such as XLS, DOC, and other Microsoft Office file types).
The package is available on NPM:
$ npm install -g cfb
$ cfb path/to/CFB/file
The command will extract the storages and streams in the container, generating files that line up with the tree-based structure of the storage. Metadata such as the red-black tree are discarded (and in the future, new CFB containers will exclusively use black nodes)
In the browser:
<script src="cfb.js" type="text/javascript"></script>
In node:
var CFB = require('cfb');
For example, to get the Workbook content from an XLS file:
var cfb = CFB.read(filename, {type: 'file'});
var workbook = cfb.find('Workbook')
Typescript definitions are maintained in misc/cfb.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, options)
wraps parse
. options.type
controls the behavior:
file
: blob
should be a file namebase64
: blob
should be a base64 stringbinary
: blob
should be a binary stringThe object returned by parse
and read
can be found in the source (rval
).
It has the following properties and methods:
.find(path)
performs a case-insensitive match for the path (or file name, if
there are no slashes) and returns an entry object (described later) or null if
not found
.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
as .FullPaths
.
.raw
contains the raw header and sectors
The entry objects are available from FullPathDir
and FileIndex
elements of
the container object.
.name
is the (case sensitive) internal name.type
is the type as defined in "Object Type" in [MS-CFB] 2.6.1:
2 (stream)
for files, 1 (storage)
for dirs, 5 (root)
for root).content
is a Buffer/Array with the raw content.ct
/.mt
are the creation and modification time (if provided in file)Case comparison has not been verified for non-ASCII characters
Writing is not supported. It is in the works, but it has not yet been released.
The xlscfb.js
file is designed to be embedded in js-xls
This implementation is covered under Apache 2.0 license. It complies with the Open Specifications Promise
FAQs
Compound File Binary File Format extractor
The npm package cfb receives a total of 1,708,362 weekly downloads. As such, cfb popularity was classified as popular.
We found that cfb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.