Binary Property List Parser
bplist-parser is a JavaScript library designed to parse Apple's binary Property List (.bplist) files. These files are a compact, binary representation often used by macOS and iOS for storing structured data, as an alternative to XML plists. The current stable version is 0.3.2, which was last published to npm approximately four years ago, indicating a very slow or effectively halted release cadence. While the GitHub repository shows some minimal activity related to ESM conversion more recently, the published npm package remains CommonJS-centric. The package includes TypeScript type definitions. Its key differentiator is its singular focus on parsing binary plists, without support for XML or OpenStep plist formats, making it suitable for applications specifically dealing with this file type, though users should be aware of its infrequent updates.
Common errors
-
Error: Invalid binary plist. Expected 'bplist' at offset 0.
cause The file or buffer provided to `parseFile` or `parseBuffer` is either not a valid binary plist file, is corrupted, or is in an unexpected format (e.g., an XML plist). The parser checks for the 'bplist' magic bytes at the beginning of the file/buffer.fixEnsure the input file is indeed a binary plist (.bplist) and not an XML plist (.plist) or any other file type. Validate the file's integrity. If you're dealing with XML plists, you need a different parser (e.g., `plist` npm package). -
TypeError: Cannot read properties of undefined (reading 'parseFile') at Object.<anonymous>
cause This typically occurs in an ESM environment when attempting to destructure named exports from a CommonJS module imported with `import bplist from 'bplist-parser';`, or when accessing properties on `undefined` if the import failed.fixIn ESM, use `import * as bplist from 'bplist-parser';` to import the entire module as a namespace object. Then access `bplist.parseFile`. Alternatively, if your project supports it, use `const bplist = require('bplist-parser');`.
Warnings
- gotcha The `bplist-parser` package (version 0.3.2) is primarily a CommonJS module. Attempting to use `import bplist from 'bplist-parser';` directly in a pure ESM environment may lead to unexpected behavior or require specific build tool configurations, as default ESM imports of CJS modules often result in the entire module object being imported as the default. The recommended approach for ESM is `import * as bplist from 'bplist-parser';` or explicit `require` if supported by your runtime.
- breaking The package has not had a new release in approximately four years (as of 2026), with the latest version being 0.3.2. This means it may not be actively maintained for new Node.js versions, performance improvements, or potential security vulnerabilities discovered in binary plist parsing or its dependencies. Users should be aware that significant changes in Node.js runtime or underlying file system APIs might not be directly supported without manual intervention.
- gotcha The library's internal `maxObjectSize` and `maxObjectCount` limits (100MB and 32768 objects respectively) are hardcoded. Parsing extremely large or deeply nested binary plist files may hit these limits, leading to errors or incomplete parsing without providing explicit configuration options.
Install
-
npm install bplist-parser -
yarn add bplist-parser -
pnpm add bplist-parser
Imports
- bplist
import bplist from 'bplist-parser';
const bplist = require('bplist-parser'); - parseFile
import { parseFile } from 'bplist-parser';const { parseFile } = require('bplist-parser'); - PlistObject
import type { PlistObject } from 'bplist-parser';
Quickstart
import { readFile } from 'fs/promises';
import { join } from 'path';
import type { PlistObject } from 'bplist-parser';
// Assuming bplist-parser is a CJS module, we import it this way for ESM interop.
// In a pure CJS environment, 'const bplist = require("bplist-parser");' is correct.
import * as bplist from 'bplist-parser';
const createDummyPlistFile = async (filepath: string) => {
// In a real scenario, you'd have an actual .bplist file.
// This is a minimal example; creating a real binary plist is complex.
// For demonstration, we simulate reading a file that *would* be a bplist.
console.log(`Simulating parsing of a binary plist file: ${filepath}`);
// In a real app, you would read an actual .bplist buffer.
// For this example, we'll use a very small, known valid bplist header as a placeholder.
// A minimal valid binary plist is much larger, this is just to show the API.
const dummyBuffer = Buffer.from('bplist00\xd1\x01\x02\x10\x11Hello World!\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17', 'latin1');
// Using parseBuffer for a direct buffer, as parseFile expects a file path.
const parsedObj: PlistObject[] = await (bplist as any).parseBuffer(dummyBuffer);
console.log('Parsed Plist Object:', JSON.stringify(parsedObj, null, 2));
};
(async () => {
const plistPath = join(process.cwd(), 'myPlist.bplist');
try {
// The parseFile function takes a file path directly.
// Since we're simulating, we'll demonstrate parseBuffer directly.
// If a real file existed, you'd do:
// const obj = await bplist.parseFile(plistPath);
await createDummyPlistFile(plistPath);
} catch (error) {
console.error('Error parsing plist:', error);
}
})();