Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

296 changes: 0 additions & 296 deletions .eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
.lock*
npm-debug.log
.idea
/dist/
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,50 @@ $ npm install bplist-parser

## Quick Examples

This package ships both ES module and CommonJS builds, so either import style works.

```javascript
// ESM
import { parseFile } from 'bplist-parser';

const [obj] = await parseFile('myPlist.bplist');
console.log(JSON.stringify(obj));
```

```javascript
// CommonJS
const bplist = require('bplist-parser');

(async () => {
const [obj] = await bplist.parseFile('myPlist.bplist');
console.log(JSON.stringify(obj));
})();
```

const obj = await bplist.parseFile('myPlist.bplist');
`parseFileSync` and `parseBuffer` are also exported, and both return an array of
the plist's root objects.

console.log(JSON.stringify(obj));
## Limits

})();
The parser refuses plists that would allocate more than `maxObjectSize` bytes or
contain more than `maxObjectCount` objects. Both are readable as exports and
adjusted through setters:

```javascript
import { setMaxObjectSize, setMaxObjectCount } from 'bplist-parser';

setMaxObjectSize(200 * 1000 * 1000);
setMaxObjectCount(65536);
```

> **Note:** before 0.4.0 these were assignable (`bplist.maxObjectSize = n`).
> Exported bindings are read-only in both module systems now, so assignment must
> be replaced with the setters above.

## Requirements

Node.js 20.19 or newer.

## License

(The MIT License)
Expand Down
33 changes: 25 additions & 8 deletions bplistParser.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
export declare namespace bPlistParser {
var maxObjectCount: number;
var maxObjectSize: number;
type CallbackFunction<T = any> = (error: Error|null, result: [T]) => void
export function parseFile<T = any>(fileNameOrBuffer: string|Buffer, callback?: CallbackFunction<T>): Promise<[T]>
export function parseFileSync<T = any>(fileNameOrBuffer: string|Buffer): [T]
export function parseBuffer<T = any>(buffer: string|Buffer): [T]
export type CallbackFunction<T = any> = (error: Error | null, result: [T]) => void;

/** Maximum size, in bytes, of an object the parser will allocate. Read-only; use {@link setMaxObjectSize}. */
export declare const maxObjectSize: number;

/** Maximum number of objects the parser will read from a plist. Read-only; use {@link setMaxObjectCount}. */
export declare const maxObjectCount: number;

export declare function setMaxObjectSize(value: number): void;

export declare function setMaxObjectCount(value: number): void;

/** Wrapper for a CoreFoundation keyed-archiver UID value. */
export declare class UID {
constructor(id: number);
UID: number;
}
export default bPlistParser;

export declare function parseFile<T = any>(
fileNameOrBuffer: string | Buffer,
callback?: CallbackFunction<T>
): Promise<[T]>;

export declare function parseFileSync<T = any>(fileNameOrBuffer: string | Buffer): [T];

export declare function parseBuffer<T = any>(buffer: string | Buffer): [T];
Loading
Loading