Binary Property List Parser

0.3.2 · maintenance · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

This example demonstrates how to parse a binary Property List (bplist) file using `bplist-parser`. It shows both CommonJS `require` usage (implicitly via `import * as`) and the `parseFile` and `parseBuffer` methods, including basic TypeScript type usage. A dummy binary plist buffer is used for direct `parseBuffer` demonstration, as creating a valid binary plist file dynamically is outside the scope of a 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);
  }
})();

view raw JSON →