pdfium-native 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/README.md +41 -0
- package/dist/document.d.ts +16 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +21 -0
- package/dist/document.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/lib/document.ts +34 -1
- package/lib/index.ts +2 -0
- package/lib/types.ts +20 -0
- package/package.json +4 -4
- package/scripts/gen-prebuild-manifest.mjs +59 -0
- package/scripts/generate-fixtures.mjs +50 -0
- package/scripts/install.mjs +31 -1
- package/scripts/lib/integrity.mjs +23 -0
- package/scripts/native-deps.json +11 -11
- package/scripts/prebuilds.json +12 -0
- package/scripts/update-native-deps.mjs +129 -0
- package/src/attachments_worker.h +242 -0
- package/src/document.h +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.7.0] - 2026-08-05
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Embedded-file (attachment) API on `PDFiumDocument`: `getAttachments()` lists every embedded file in the `/EmbeddedFiles` name tree (name, MIME type, dates) without decoding streams, and `getAttachment(index, options?)` reads the raw bytes as a `Buffer` (or writes them to `options.output`). Wraps PDFium's `FPDFDoc_GetAttachment` / `FPDFAttachment_GetFile`. This closes the gap where `metadata.attachmentCount` could detect attachments but nothing could read them — enabling extraction of the embedded `factur-x.xml` / `zugferd-invoice.xml` / `xrechnung.xml` from ZUGFeRD / Factur-X / XRechnung PDF/A-3 e-invoices.
|
|
14
|
+
- `Attachment` and `GetAttachmentOptions` types are exported from the package root.
|
|
15
|
+
|
|
16
|
+
## [0.6.1] - 2026-07-15
|
|
17
|
+
|
|
18
|
+
### Security
|
|
19
|
+
|
|
20
|
+
- Verify the downloaded prebuilt binary against a per-platform SHA-256 pin shipped in the package before use, falling back to the checksum-pinned source build on mismatch or a missing pin. Closes the prebuilt-binary trust gap where a swapped GitHub release asset could be executed unverified.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- The `update-native-deps` PR body now describes `verify-checksums` as a consistency check against the same source rather than "independent" verification.
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- Hermetic test coverage for prebuilt verification and manifest generation (`test/prebuild.test.ts`).
|
|
29
|
+
|
|
9
30
|
## [0.6.0] - 2026-06-27
|
|
10
31
|
|
|
11
32
|
### Added
|
|
@@ -272,7 +293,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
|
|
|
272
293
|
- GitHub Actions publish workflow with test gate
|
|
273
294
|
- TypeScript type declarations for JS consumers
|
|
274
295
|
|
|
275
|
-
[Unreleased]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.
|
|
296
|
+
[Unreleased]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.7.0...HEAD
|
|
297
|
+
[0.7.0]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.6.1...v0.7.0
|
|
298
|
+
[0.6.1]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.6.0...v0.6.1
|
|
276
299
|
[0.6.0]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.6...v0.6.0
|
|
277
300
|
[0.5.6]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.5...v0.5.6
|
|
278
301
|
[0.5.5]: https://github.com/xonaman/nodejs-pdfium-native/compare/v0.5.4...v0.5.5
|
package/README.md
CHANGED
|
@@ -65,6 +65,7 @@ doc.destroy();
|
|
|
65
65
|
| Bookmarks | ✅ | ❌ | ✅ |
|
|
66
66
|
| Links | ✅ | ❌ | ✅ |
|
|
67
67
|
| Form fields | ✅ | ❌ | ✅ |
|
|
68
|
+
| Attachments | ✅ Embedded files | ❌ | ✅ |
|
|
68
69
|
| Async I/O | ✅ libuv workers | ❌ Sync | ❌ Main thread |
|
|
69
70
|
| Platforms | macOS/Linux/Windows | Any (WASM) | Any |
|
|
70
71
|
|
|
@@ -216,6 +217,46 @@ interface Bookmark {
|
|
|
216
217
|
}
|
|
217
218
|
```
|
|
218
219
|
|
|
220
|
+
#### `getAttachments()`
|
|
221
|
+
|
|
222
|
+
Lists every embedded file (attachment) in the document's `/EmbeddedFiles` name tree. Returns `Promise<Attachment[]>`. This reads only dictionary metadata — it does **not** decode the file streams; use [`getAttachment(index)`](#getattachmentindex-options) to read the bytes.
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
interface Attachment {
|
|
226
|
+
index: number; // 0-based index in the embedded-files name tree
|
|
227
|
+
name: string; // file name, e.g. 'factur-x.xml'
|
|
228
|
+
mimeType: string; // /Subtype, e.g. 'text/xml' ('' if the PDF omits it)
|
|
229
|
+
creationDate?: string; // PDF date string, e.g. 'D:20250101120000Z'
|
|
230
|
+
modDate?: string; // PDF date string
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### `getAttachment(index, options?)`
|
|
235
|
+
|
|
236
|
+
Reads the raw bytes of the attachment at `index`. Returns `Promise<Buffer>`, or `Promise<void>` when `options.output` is a file path (the bytes are written there instead).
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
// Extract the embedded XML from a ZUGFeRD / Factur-X / XRechnung PDF/A-3 e-invoice.
|
|
240
|
+
// The PDF stays the display artifact; the XML is the structured source of truth.
|
|
241
|
+
const E_INVOICE_NAMES = ['factur-x.xml', 'zugferd-invoice.xml', 'xrechnung.xml'];
|
|
242
|
+
|
|
243
|
+
const doc = await loadDocument('invoice.pdf');
|
|
244
|
+
const attachments = await doc.getAttachments();
|
|
245
|
+
const entry = attachments.find((a) => E_INVOICE_NAMES.includes(a.name.toLowerCase()));
|
|
246
|
+
|
|
247
|
+
if (entry) {
|
|
248
|
+
const xml = await doc.getAttachment(entry.index); // Buffer of the exact embedded bytes
|
|
249
|
+
console.log(xml.toString('utf8'));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// or write straight to disk:
|
|
253
|
+
await doc.getAttachment(0, { output: 'attachment.xml' });
|
|
254
|
+
|
|
255
|
+
doc.destroy();
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Rejects if `index` is out of range (`0 … attachmentCount - 1`). `metadata.attachmentCount` gives the count without loading anything.
|
|
259
|
+
|
|
219
260
|
#### `destroy()`
|
|
220
261
|
|
|
221
262
|
Closes the document and frees all native resources. Must be called when done.
|
package/dist/document.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PDFiumPage } from './page.js';
|
|
2
|
-
import type { Bookmark, DocumentMetadata, NativeDocument } from './types.js';
|
|
2
|
+
import type { Attachment, Bookmark, DocumentMetadata, GetAttachmentOptions, NativeDocument } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* A loaded PDF document.
|
|
5
5
|
*/
|
|
@@ -19,5 +19,20 @@ export declare class PDFiumDocument {
|
|
|
19
19
|
destroy(): void;
|
|
20
20
|
/** Returns the bookmark/outline tree. */
|
|
21
21
|
getBookmarks(): Promise<Bookmark[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns metadata for every embedded file (attachment) in the document —
|
|
24
|
+
* name, MIME type and dates — without reading the file bytes.
|
|
25
|
+
*
|
|
26
|
+
* For ZUGFeRD / Factur-X / XRechnung PDF/A-3 e-invoices, the structured
|
|
27
|
+
* invoice lives here (e.g. `factur-x.xml`); pass its `index` to
|
|
28
|
+
* {@link getAttachment} to read the bytes.
|
|
29
|
+
*/
|
|
30
|
+
getAttachments(): Promise<Attachment[]>;
|
|
31
|
+
/** Writes the attachment at `index` to a file path. */
|
|
32
|
+
getAttachment(index: number, options: GetAttachmentOptions & {
|
|
33
|
+
output: string;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
/** Reads the raw bytes of the attachment at `index`. */
|
|
36
|
+
getAttachment(index: number, options?: GetAttachmentOptions): Promise<Buffer>;
|
|
22
37
|
}
|
|
23
38
|
//# sourceMappingURL=document.d.ts.map
|
package/dist/document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,cAAc;IAOb,OAAO,CAAC,MAAM;IAN1B,6BAA6B;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB;gBACI,MAAM,EAAE,cAAc;IAK1C,oCAAoC;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjD,4EAA4E;IACrE,KAAK,IAAI,cAAc,CAAC,UAAU,CAAC;IAM1C,mDAAmD;IACnD,OAAO,IAAI,IAAI;IAIf,yCAAyC;IACzC,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAInC;;;;;;;OAOG;IACH,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAIvC,uDAAuD;IACvD,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAC/F,wDAAwD;IACxD,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;CAW9E"}
|
package/dist/document.js
CHANGED
|
@@ -33,5 +33,26 @@ export class PDFiumDocument {
|
|
|
33
33
|
getBookmarks() {
|
|
34
34
|
return withConcurrency(() => this.native.getBookmarks());
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns metadata for every embedded file (attachment) in the document —
|
|
38
|
+
* name, MIME type and dates — without reading the file bytes.
|
|
39
|
+
*
|
|
40
|
+
* For ZUGFeRD / Factur-X / XRechnung PDF/A-3 e-invoices, the structured
|
|
41
|
+
* invoice lives here (e.g. `factur-x.xml`); pass its `index` to
|
|
42
|
+
* {@link getAttachment} to read the bytes.
|
|
43
|
+
*/
|
|
44
|
+
getAttachments() {
|
|
45
|
+
return withConcurrency(() => this.native.getAttachments());
|
|
46
|
+
}
|
|
47
|
+
getAttachment(index, options) {
|
|
48
|
+
// Guard non-integer indices here: the native layer coerces with ToInt32, so
|
|
49
|
+
// a NaN/Infinity/fractional index (e.g. from `Number(userInput)`) would
|
|
50
|
+
// otherwise silently alias onto a valid attachment and return the wrong
|
|
51
|
+
// embedded file. Integer out-of-range is still handled natively.
|
|
52
|
+
if (!Number.isInteger(index)) {
|
|
53
|
+
return Promise.reject(new RangeError(`Attachment index must be an integer, got ${index}`));
|
|
54
|
+
}
|
|
55
|
+
return withConcurrency(() => this.native.getAttachment(index, options?.output));
|
|
56
|
+
}
|
|
36
57
|
}
|
|
37
58
|
//# sourceMappingURL=document.js.map
|
package/dist/document.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW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D,CAAC;IAMD,aAAa,CAAC,KAAa,EAAE,OAA8B;QACzD,4EAA4E;QAC5E,wEAAwE;QACxE,wEAAwE;QACxE,iEAAiE;QACjE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,4CAA4C,KAAK,EAAE,CAAC,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAClF,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,5 +24,5 @@ export { concurrency } from './concurrency.js';
|
|
|
24
24
|
export { PDFiumDocument } from './document.js';
|
|
25
25
|
export { PDFiumError, PDFiumFileError, PDFiumFormatError, PDFiumPasswordError, PDFiumSecurityError, } from './errors.js';
|
|
26
26
|
export { PDFiumPage } from './page.js';
|
|
27
|
-
export type { Annotation, AnnotationBorder, AnnotationType, Bookmark, DocumentMetadata, DocumentPermissions, FormField, FormFieldOption, FormFieldType, ImageColorspace, ImagePageObject, ImageRenderOptions, Link, LinkActionType, MergeDocumentInput, MergeDocumentsOptions, OtherPageObject, PageObject, PageObjectBounds, PageRenderOptions, QuadPoints, RGBA, SearchMatch, SearchOptions, SearchRect, SplitDocumentOptions, TextPageObject, TextRenderMode, } from './types.js';
|
|
27
|
+
export type { Annotation, AnnotationBorder, AnnotationType, Attachment, Bookmark, DocumentMetadata, DocumentPermissions, FormField, FormFieldOption, FormFieldType, GetAttachmentOptions, ImageColorspace, ImagePageObject, ImageRenderOptions, Link, LinkActionType, MergeDocumentInput, MergeDocumentsOptions, OtherPageObject, PageObject, PageObjectBounds, PageRenderOptions, QuadPoints, RGBA, SearchMatch, SearchOptions, SearchRect, SplitDocumentOptions, TextPageObject, TextRenderMode, } from './types.js';
|
|
28
28
|
//#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GAC7B,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAarB;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,kBAAkB,CAAC,EAC5C,OAAO,EAAE,qBAAqB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClD,OAAO,CAAC,IAAI,CAAC,CAAC;AACjB,wBAAsB,cAAc,CAClC,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,kBAAkB,CAAC,EAC5C,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAAC;AAYnB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,IAAI,EACJ,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -309,6 +309,22 @@ export interface DocumentMetadata {
|
|
|
309
309
|
/** Changing file identifier (hex string, updated on each save). */
|
|
310
310
|
changingId?: string;
|
|
311
311
|
}
|
|
312
|
+
export interface Attachment {
|
|
313
|
+
/** 0-based index of the attachment in the document's embedded-files name tree. */
|
|
314
|
+
index: number;
|
|
315
|
+
/** File name as stored in the /EmbeddedFiles name tree (e.g. 'factur-x.xml'). */
|
|
316
|
+
name: string;
|
|
317
|
+
/** MIME type (/Subtype), e.g. 'text/xml'. Empty string if the PDF omits it. */
|
|
318
|
+
mimeType: string;
|
|
319
|
+
/** Creation date as a PDF date string (e.g. 'D:20250101120000Z'). Absent if not set. */
|
|
320
|
+
creationDate?: string;
|
|
321
|
+
/** Modification date as a PDF date string. Absent if not set. */
|
|
322
|
+
modDate?: string;
|
|
323
|
+
}
|
|
324
|
+
export interface GetAttachmentOptions {
|
|
325
|
+
/** Write the attachment bytes to this file path instead of returning a Buffer. */
|
|
326
|
+
output?: string;
|
|
327
|
+
}
|
|
312
328
|
export interface NativePage {
|
|
313
329
|
readonly number: number;
|
|
314
330
|
readonly width: number;
|
|
@@ -334,6 +350,8 @@ export interface NativeDocument {
|
|
|
334
350
|
readonly metadata: DocumentMetadata;
|
|
335
351
|
getPage(index: number): Promise<NativePage>;
|
|
336
352
|
getBookmarks(): Promise<Bookmark[]>;
|
|
353
|
+
getAttachments(): Promise<Attachment[]>;
|
|
354
|
+
getAttachment(index: number, outputPath?: string): Promise<Buffer | undefined>;
|
|
337
355
|
destroy(): void;
|
|
338
356
|
}
|
|
339
357
|
export interface SplitDocumentOptions {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACxB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,C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AM,EAAE,GAAG,SAAS,CAAC,CAAC;IACjC,cAAc,CACZ,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,EAC9E,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAChC"}
|
package/lib/document.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { withConcurrency } from './concurrency.js';
|
|
2
2
|
import { PDFiumPage } from './page.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
Attachment,
|
|
5
|
+
Bookmark,
|
|
6
|
+
DocumentMetadata,
|
|
7
|
+
GetAttachmentOptions,
|
|
8
|
+
NativeDocument,
|
|
9
|
+
} from './types.js';
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* A loaded PDF document.
|
|
@@ -38,4 +44,31 @@ export class PDFiumDocument {
|
|
|
38
44
|
getBookmarks(): Promise<Bookmark[]> {
|
|
39
45
|
return withConcurrency(() => this.native.getBookmarks());
|
|
40
46
|
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns metadata for every embedded file (attachment) in the document —
|
|
50
|
+
* name, MIME type and dates — without reading the file bytes.
|
|
51
|
+
*
|
|
52
|
+
* For ZUGFeRD / Factur-X / XRechnung PDF/A-3 e-invoices, the structured
|
|
53
|
+
* invoice lives here (e.g. `factur-x.xml`); pass its `index` to
|
|
54
|
+
* {@link getAttachment} to read the bytes.
|
|
55
|
+
*/
|
|
56
|
+
getAttachments(): Promise<Attachment[]> {
|
|
57
|
+
return withConcurrency(() => this.native.getAttachments());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Writes the attachment at `index` to a file path. */
|
|
61
|
+
getAttachment(index: number, options: GetAttachmentOptions & { output: string }): Promise<void>;
|
|
62
|
+
/** Reads the raw bytes of the attachment at `index`. */
|
|
63
|
+
getAttachment(index: number, options?: GetAttachmentOptions): Promise<Buffer>;
|
|
64
|
+
getAttachment(index: number, options?: GetAttachmentOptions): Promise<Buffer | void> {
|
|
65
|
+
// Guard non-integer indices here: the native layer coerces with ToInt32, so
|
|
66
|
+
// a NaN/Infinity/fractional index (e.g. from `Number(userInput)`) would
|
|
67
|
+
// otherwise silently alias onto a valid attachment and return the wrong
|
|
68
|
+
// embedded file. Integer out-of-range is still handled natively.
|
|
69
|
+
if (!Number.isInteger(index)) {
|
|
70
|
+
return Promise.reject(new RangeError(`Attachment index must be an integer, got ${index}`));
|
|
71
|
+
}
|
|
72
|
+
return withConcurrency(() => this.native.getAttachment(index, options?.output));
|
|
73
|
+
}
|
|
41
74
|
}
|
package/lib/index.ts
CHANGED
|
@@ -103,12 +103,14 @@ export type {
|
|
|
103
103
|
Annotation,
|
|
104
104
|
AnnotationBorder,
|
|
105
105
|
AnnotationType,
|
|
106
|
+
Attachment,
|
|
106
107
|
Bookmark,
|
|
107
108
|
DocumentMetadata,
|
|
108
109
|
DocumentPermissions,
|
|
109
110
|
FormField,
|
|
110
111
|
FormFieldOption,
|
|
111
112
|
FormFieldType,
|
|
113
|
+
GetAttachmentOptions,
|
|
112
114
|
ImageColorspace,
|
|
113
115
|
ImagePageObject,
|
|
114
116
|
ImageRenderOptions,
|
package/lib/types.ts
CHANGED
|
@@ -384,6 +384,24 @@ export interface DocumentMetadata {
|
|
|
384
384
|
changingId?: string;
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
+
export interface Attachment {
|
|
388
|
+
/** 0-based index of the attachment in the document's embedded-files name tree. */
|
|
389
|
+
index: number;
|
|
390
|
+
/** File name as stored in the /EmbeddedFiles name tree (e.g. 'factur-x.xml'). */
|
|
391
|
+
name: string;
|
|
392
|
+
/** MIME type (/Subtype), e.g. 'text/xml'. Empty string if the PDF omits it. */
|
|
393
|
+
mimeType: string;
|
|
394
|
+
/** Creation date as a PDF date string (e.g. 'D:20250101120000Z'). Absent if not set. */
|
|
395
|
+
creationDate?: string;
|
|
396
|
+
/** Modification date as a PDF date string. Absent if not set. */
|
|
397
|
+
modDate?: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface GetAttachmentOptions {
|
|
401
|
+
/** Write the attachment bytes to this file path instead of returning a Buffer. */
|
|
402
|
+
output?: string;
|
|
403
|
+
}
|
|
404
|
+
|
|
387
405
|
// native addon bindings (internal)
|
|
388
406
|
export interface NativePage {
|
|
389
407
|
readonly number: number;
|
|
@@ -411,6 +429,8 @@ export interface NativeDocument {
|
|
|
411
429
|
readonly metadata: DocumentMetadata;
|
|
412
430
|
getPage(index: number): Promise<NativePage>;
|
|
413
431
|
getBookmarks(): Promise<Bookmark[]>;
|
|
432
|
+
getAttachments(): Promise<Attachment[]>;
|
|
433
|
+
getAttachment(index: number, outputPath?: string): Promise<Buffer | undefined>;
|
|
414
434
|
destroy(): void;
|
|
415
435
|
}
|
|
416
436
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfium-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Native Node.js bindings for PDFium",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -95,16 +95,16 @@
|
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@eslint/js": "^10.0.1",
|
|
98
|
-
"@types/node": "^
|
|
98
|
+
"@types/node": "^22.0.0",
|
|
99
99
|
"@vitest/coverage-v8": "^4.1.2",
|
|
100
100
|
"eslint": "^10.1.0",
|
|
101
101
|
"eslint-config-prettier": "^10.1.8",
|
|
102
102
|
"globals": "^17.0.0",
|
|
103
103
|
"husky": "^9.1.7",
|
|
104
|
-
"lint-staged": "^
|
|
104
|
+
"lint-staged": "^17.0.8",
|
|
105
105
|
"node-gyp": "^13.0.0",
|
|
106
106
|
"prettier": "^3.8.1",
|
|
107
|
-
"typescript": "^
|
|
107
|
+
"typescript": "^6.0.3",
|
|
108
108
|
"typescript-eslint": "^8.57.2",
|
|
109
109
|
"vitest": "^4.1.2"
|
|
110
110
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate `scripts/prebuilds.json`: a map of "<platform>-<arch>" -> SHA-256 of
|
|
3
|
+
* each prebuilt release tarball.
|
|
4
|
+
*
|
|
5
|
+
* Run in the release workflow AFTER the prebuild artifacts are downloaded and
|
|
6
|
+
* BEFORE `npm publish`, so the pins ship *inside* the published (SLSA-attested)
|
|
7
|
+
* npm package. `install.mjs` then verifies a downloaded prebuilt against the
|
|
8
|
+
* pin baked into the package, closing the prebuilt-binary trust gap: a swapped
|
|
9
|
+
* GitHub release asset will not match the pin and falls back to the
|
|
10
|
+
* checksum-pinned source build.
|
|
11
|
+
*
|
|
12
|
+
* Usage: node scripts/gen-prebuild-manifest.mjs <artifacts-dir>
|
|
13
|
+
*/
|
|
14
|
+
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { pathToFileURL } from 'node:url';
|
|
17
|
+
import { sha256File } from './lib/integrity.mjs';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Map every "<prefix>-v<version>-<platform>-<arch>.tar.gz" in `artifactsDir` to
|
|
21
|
+
* its SHA-256, keyed by "<platform>-<arch>" (matching install.mjs's lookup).
|
|
22
|
+
*
|
|
23
|
+
* @param {string} artifactsDir
|
|
24
|
+
* @param {string} version
|
|
25
|
+
* @returns {Promise<Record<string, string>>}
|
|
26
|
+
*/
|
|
27
|
+
export async function computePins(artifactsDir, version) {
|
|
28
|
+
// strip the "<prefix>-v<version>-" head and ".tar.gz" tail to recover the key
|
|
29
|
+
const headRe = new RegExp('^.*-v' + version.replace(/[.]/g, '\\.') + '-');
|
|
30
|
+
const files = readdirSync(artifactsDir)
|
|
31
|
+
.filter((f) => f.endsWith('.tar.gz'))
|
|
32
|
+
.sort();
|
|
33
|
+
const pins = {};
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
const key = file.replace(/\.tar\.gz$/, '').replace(headRe, '');
|
|
36
|
+
pins[key] = await sha256File(join(artifactsDir, file));
|
|
37
|
+
}
|
|
38
|
+
return pins;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// CLI entrypoint (skipped when this module is imported, e.g. by tests)
|
|
42
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
43
|
+
const artifactsDir = process.argv[2];
|
|
44
|
+
if (!artifactsDir) {
|
|
45
|
+
console.error('usage: node scripts/gen-prebuild-manifest.mjs <artifacts-dir>');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const root = join(import.meta.dirname, '..');
|
|
49
|
+
const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
50
|
+
const pins = await computePins(artifactsDir, version);
|
|
51
|
+
if (Object.keys(pins).length === 0) {
|
|
52
|
+
console.error(`No .tar.gz artifacts found in ${artifactsDir}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
for (const [key, sha] of Object.entries(pins)) console.log(` ${key} ${sha}`);
|
|
56
|
+
const out = join(root, 'scripts', 'prebuilds.json');
|
|
57
|
+
writeFileSync(out, JSON.stringify(pins, null, 2) + '\n');
|
|
58
|
+
console.log(`Wrote ${Object.keys(pins).length} prebuild pin(s) to ${out}`);
|
|
59
|
+
}
|
|
@@ -444,6 +444,55 @@ async function createBorderAnnotationPdf() {
|
|
|
444
444
|
return doc.save();
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
+
// --- ZUGFeRD / Factur-X PDF/A-3 with an embedded invoice XML ---
|
|
448
|
+
// The structured invoice (factur-x.xml) is embedded in the /EmbeddedFiles name
|
|
449
|
+
// tree; a second plain-text attachment exercises multi-attachment enumeration.
|
|
450
|
+
const FACTUR_X_XML = `<?xml version="1.0" encoding="UTF-8"?>
|
|
451
|
+
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100">
|
|
452
|
+
<rsm:ExchangedDocumentContext>
|
|
453
|
+
<ram:GuidelineSpecifiedDocumentContextParameter>
|
|
454
|
+
<ram:ID>urn:cen.eu:en16931:2017</ram:ID>
|
|
455
|
+
</ram:GuidelineSpecifiedDocumentContextParameter>
|
|
456
|
+
</rsm:ExchangedDocumentContext>
|
|
457
|
+
<rsm:ExchangedDocument>
|
|
458
|
+
<ram:ID>RE-2025-0001</ram:ID>
|
|
459
|
+
<ram:TypeCode>380</ram:TypeCode>
|
|
460
|
+
<ram:IssueDateTime>
|
|
461
|
+
<ram:DateTimeString format="102">20250101</ram:DateTimeString>
|
|
462
|
+
</ram:IssueDateTime>
|
|
463
|
+
</rsm:ExchangedDocument>
|
|
464
|
+
</rsm:CrossIndustryInvoice>
|
|
465
|
+
`;
|
|
466
|
+
|
|
467
|
+
async function createEInvoicePdf() {
|
|
468
|
+
const { AFRelationship } = await import('pdf-lib');
|
|
469
|
+
const doc = await PDFDocument.create();
|
|
470
|
+
doc.setTitle('ZUGFeRD / Factur-X invoice');
|
|
471
|
+
doc.setProducer('pdfium-native test');
|
|
472
|
+
const page = doc.addPage([612, 792]);
|
|
473
|
+
const font = await doc.embedFont(StandardFonts.Helvetica);
|
|
474
|
+
page.drawText('Invoice RE-2025-0001', { x: 50, y: 700, size: 16, font });
|
|
475
|
+
page.drawText('Structured data embedded as factur-x.xml', { x: 50, y: 670, size: 11, font });
|
|
476
|
+
|
|
477
|
+
await doc.attach(Buffer.from(FACTUR_X_XML, 'utf8'), 'factur-x.xml', {
|
|
478
|
+
mimeType: 'text/xml',
|
|
479
|
+
description: 'Factur-X invoice',
|
|
480
|
+
creationDate: new Date('2025-01-01T12:00:00Z'),
|
|
481
|
+
modificationDate: new Date('2025-01-01T12:00:00Z'),
|
|
482
|
+
afRelationship: AFRelationship.Alternative,
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
await doc.attach(Buffer.from('Human-readable notes.\n', 'utf8'), 'notes.txt', {
|
|
486
|
+
mimeType: 'text/plain',
|
|
487
|
+
description: 'Supplementary notes',
|
|
488
|
+
creationDate: new Date('2025-01-01T12:00:00Z'),
|
|
489
|
+
modificationDate: new Date('2025-01-01T12:00:00Z'),
|
|
490
|
+
afRelationship: AFRelationship.Supplement,
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
return doc.save();
|
|
494
|
+
}
|
|
495
|
+
|
|
447
496
|
// --- PDF with form fields ---
|
|
448
497
|
async function createFormFieldsPdf() {
|
|
449
498
|
const doc = await PDFDocument.create();
|
|
@@ -518,6 +567,7 @@ const fixtures = [
|
|
|
518
567
|
['rich-bookmarks.pdf', createRichBookmarkPdf],
|
|
519
568
|
['border-annotations.pdf', createBorderAnnotationPdf],
|
|
520
569
|
['form-fields.pdf', createFormFieldsPdf],
|
|
570
|
+
['einvoice-zugferd.pdf', createEInvoicePdf],
|
|
521
571
|
];
|
|
522
572
|
|
|
523
573
|
for (const [name, generator] of fixtures) {
|
package/scripts/install.mjs
CHANGED
|
@@ -11,12 +11,25 @@ import { createWriteStream, existsSync, mkdirSync, readFileSync, unlinkSync } fr
|
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
import { Readable } from 'node:stream';
|
|
13
13
|
import { pipeline } from 'node:stream/promises';
|
|
14
|
-
import { extractTarball } from './lib/integrity.mjs';
|
|
14
|
+
import { extractTarball, verifyPrebuild } from './lib/integrity.mjs';
|
|
15
15
|
|
|
16
16
|
const root = join(import.meta.dirname, '..');
|
|
17
17
|
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
18
18
|
const version = pkg.version;
|
|
19
19
|
|
|
20
|
+
// Per-platform SHA-256 pins for the prebuilt tarballs, generated at release
|
|
21
|
+
// time (scripts/gen-prebuild-manifest.mjs) and shipped inside this package.
|
|
22
|
+
// The prebuilt binary is the code that actually runs, so it is verified against
|
|
23
|
+
// this pin before use; a swapped release asset fails the check and we fall back
|
|
24
|
+
// to the checksum-pinned source build.
|
|
25
|
+
function loadPrebuildPins() {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(readFileSync(join(import.meta.dirname, 'prebuilds.json'), 'utf8'));
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
// validate version to prevent SSRF via malicious package.json
|
|
21
34
|
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/.test(version)) {
|
|
22
35
|
console.error(`Invalid version format: ${version}`);
|
|
@@ -74,6 +87,23 @@ async function tryDownload() {
|
|
|
74
87
|
|
|
75
88
|
await pipeline(Readable.fromWeb(body), fileStream);
|
|
76
89
|
|
|
90
|
+
// verify the prebuilt against the pinned checksum before trusting it
|
|
91
|
+
const pinKey = `${platformKey}-${arch}`;
|
|
92
|
+
const check = await verifyPrebuild(tmpTar, pinKey, loadPrebuildPins());
|
|
93
|
+
if (!check.ok) {
|
|
94
|
+
if (check.reason === 'no-pin') {
|
|
95
|
+
console.log(
|
|
96
|
+
`No pinned checksum for ${pinKey}; refusing unverified prebuilt, will compile from source.`,
|
|
97
|
+
);
|
|
98
|
+
} else {
|
|
99
|
+
console.log(
|
|
100
|
+
`Prebuilt checksum mismatch for ${pinKey} (expected ${check.expected}, got ${check.actual}); will compile from source.`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
unlinkSync(tmpTar);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
77
107
|
// extract tar.gz into project root (hardened: no -P, no archived ownership)
|
|
78
108
|
extractTarball(tmpTar, root);
|
|
79
109
|
unlinkSync(tmpTar);
|
|
@@ -32,6 +32,29 @@ export async function sha256File(path) {
|
|
|
32
32
|
return hash.digest('hex');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Decide whether a downloaded prebuilt tarball is trusted by comparing its
|
|
37
|
+
* SHA-256 to the pin recorded for `pinKey` in `pins` (scripts/prebuilds.json).
|
|
38
|
+
* Returns a discriminated result so the installer can log and fall back to a
|
|
39
|
+
* source build instead of running an unverified binary.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} tarPath
|
|
42
|
+
* @param {string} pinKey e.g. "darwin-arm64" / "linux-musl-x64"
|
|
43
|
+
* @param {Record<string, string>} pins
|
|
44
|
+
* @returns {Promise<{ok: true, pinKey: string, sha256: string}
|
|
45
|
+
* | {ok: false, reason: 'no-pin', pinKey: string}
|
|
46
|
+
* | {ok: false, reason: 'mismatch', pinKey: string, expected: string, actual: string}>}
|
|
47
|
+
*/
|
|
48
|
+
export async function verifyPrebuild(tarPath, pinKey, pins) {
|
|
49
|
+
const expected = pins[pinKey];
|
|
50
|
+
if (!expected) return { ok: false, reason: 'no-pin', pinKey };
|
|
51
|
+
const actual = await sha256File(tarPath);
|
|
52
|
+
if (actual !== expected.toLowerCase()) {
|
|
53
|
+
return { ok: false, reason: 'mismatch', pinKey, expected, actual };
|
|
54
|
+
}
|
|
55
|
+
return { ok: true, pinKey, sha256: actual };
|
|
56
|
+
}
|
|
57
|
+
|
|
35
58
|
/** Read the native-dependency manifest (scripts/native-deps.json). */
|
|
36
59
|
export function loadManifest() {
|
|
37
60
|
return JSON.parse(readFileSync(join(import.meta.dirname, '..', 'native-deps.json'), 'utf8'));
|
package/scripts/native-deps.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"pdfium": {
|
|
3
|
-
"version": "chromium/
|
|
3
|
+
"version": "chromium/7920",
|
|
4
4
|
"origin": "https://github.com",
|
|
5
5
|
"baseUrl": "https://github.com/bblanchon/pdfium-binaries/releases/download",
|
|
6
6
|
"checksumSource": "Sigstore SLSA provenance attestation (pdfium-attestation.json) attached to the bblanchon/pdfium-binaries release",
|
|
7
7
|
"targets": {
|
|
8
8
|
"darwin-arm64": {
|
|
9
9
|
"asset": "pdfium-mac-arm64.tgz",
|
|
10
|
-
"sha256": "
|
|
10
|
+
"sha256": "c032aa59be58b0f12e41e76a8ef707e347b9841b0426446f646b2568d350ec4f"
|
|
11
11
|
},
|
|
12
12
|
"darwin-x64": {
|
|
13
13
|
"asset": "pdfium-mac-x64.tgz",
|
|
14
|
-
"sha256": "
|
|
14
|
+
"sha256": "0c78b8d55a4c97e02c9bb516997253cb972739373009cf29554c959a2f6b194a"
|
|
15
15
|
},
|
|
16
16
|
"linux-x64": {
|
|
17
17
|
"asset": "pdfium-linux-x64.tgz",
|
|
18
|
-
"sha256": "
|
|
18
|
+
"sha256": "49ab3afbd4e6c1e284b5f2898129c8bb8a10fd785c1c5392c8c1fc70242f9ced"
|
|
19
19
|
},
|
|
20
20
|
"linux-arm64": {
|
|
21
21
|
"asset": "pdfium-linux-arm64.tgz",
|
|
22
|
-
"sha256": "
|
|
22
|
+
"sha256": "00551476a77fbc1a31c37573eadc9b63f1c366f65ad727539326927da083bb4d"
|
|
23
23
|
},
|
|
24
24
|
"linux-arm": {
|
|
25
25
|
"asset": "pdfium-linux-arm.tgz",
|
|
26
|
-
"sha256": "
|
|
26
|
+
"sha256": "b430bb61d27fee059a80f3219921daf30ac021acda2696f41e0d15b236d38569"
|
|
27
27
|
},
|
|
28
28
|
"linux-ppc64": {
|
|
29
29
|
"asset": "pdfium-linux-ppc64.tgz",
|
|
30
|
-
"sha256": "
|
|
30
|
+
"sha256": "56bb7196e36b219c2a5ebc54c7f140a84b10458911fe16cee2b88e50644684d3"
|
|
31
31
|
},
|
|
32
32
|
"linux-musl-x64": {
|
|
33
33
|
"asset": "pdfium-linux-musl-x64.tgz",
|
|
34
|
-
"sha256": "
|
|
34
|
+
"sha256": "4471ccd9d4f64ff16ac592d97016e404ec888d1c17fc1b3d0cd6e4763b47275c"
|
|
35
35
|
},
|
|
36
36
|
"linux-musl-arm64": {
|
|
37
37
|
"asset": "pdfium-linux-musl-arm64.tgz",
|
|
38
|
-
"sha256": "
|
|
38
|
+
"sha256": "62e75cd629dc6a810d4f72ea864d2ba2f41b7e2141920161868869c8cc2c5912"
|
|
39
39
|
},
|
|
40
40
|
"win32-x64": {
|
|
41
41
|
"asset": "pdfium-win-x64.tgz",
|
|
42
|
-
"sha256": "
|
|
42
|
+
"sha256": "bf25149815b34b00042f48a886653d469c817529dd9cccabb4b509b6465a9526"
|
|
43
43
|
},
|
|
44
44
|
"win32-arm64": {
|
|
45
45
|
"asset": "pdfium-win-arm64.tgz",
|
|
46
|
-
"sha256": "
|
|
46
|
+
"sha256": "7d580ba612765063f9bb76b5c6571db5144714a4dc9cd6d448763d788de8f9fb"
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"darwin-arm64": "5a1d1596a29cb892dc9b813d32f17f4026a93b1dcdc82157df367be1ac3fb351",
|
|
3
|
+
"darwin-x64": "870c4133cbb1a43da0fa1698b455c1fec9e497e909c6f30b4d74f348673f0cb1",
|
|
4
|
+
"linux-arm": "9993cdebe939c30f812bac0ad66f5c2c46720270dc946c6bb384f3707d04fc0d",
|
|
5
|
+
"linux-arm64": "f7d7891e304a1d727e5ab3d57d5b6f832dd1c1176cb12a1d0c2349b17b1f694e",
|
|
6
|
+
"linux-musl-arm64": "0480aa7c1b692f641f6469d42764bf023bc121eaa2e20e210150e74a210789bb",
|
|
7
|
+
"linux-musl-x64": "88c0c447f99cbb0ca0be062f81b4eb81f26a0a5f2215e64951a98ade54a46bf0",
|
|
8
|
+
"linux-ppc64": "faf22918964ab4a4efb175b2edc500f455d69e5623c17dd9aaff53d4e62aaa78",
|
|
9
|
+
"linux-x64": "f1710cb87a37e4bee4d3d97c5e5d143e519de18c8f4a9a8a44685bceb88d15de",
|
|
10
|
+
"win32-arm64": "99f688bc3b398e57eec49b9763beaa0007a137e6518f2e69207a9c07879519f6",
|
|
11
|
+
"win32-x64": "4c90fb7893b530c3c4b9771e9514cd52076072722764adc9f2725fadaf83073b"
|
|
12
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check each native dependency in native-deps.json for a newer upstream GitHub
|
|
3
|
+
* release and, when found, re-pin the version and re-hash the asset(s).
|
|
4
|
+
*
|
|
5
|
+
* This is the piece Dependabot cannot do: the prebuilt/source native libraries
|
|
6
|
+
* are upstream release tarballs, not a package-manager ecosystem. Runs in CI
|
|
7
|
+
* (see .github/workflows/update-native-deps.yml) and emits a markdown summary
|
|
8
|
+
* for the pull-request body via GITHUB_OUTPUT.
|
|
9
|
+
*
|
|
10
|
+
* Supports both manifest shapes:
|
|
11
|
+
* - per-platform "targets" (baseUrl + { asset, sha256 } map), version == full tag
|
|
12
|
+
* - single "url" + "sha256", version == numeric (tag with any v/n prefix stripped)
|
|
13
|
+
*
|
|
14
|
+
* Only upstreams that publish a GitHub Release are tracked; a dependency whose
|
|
15
|
+
* repo has no usable release is skipped with a warning (kept manual) rather than
|
|
16
|
+
* guessed from noisy git tags.
|
|
17
|
+
*/
|
|
18
|
+
import { createHash } from 'node:crypto';
|
|
19
|
+
import { appendFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { Readable } from 'node:stream';
|
|
22
|
+
import { pipeline } from 'node:stream/promises';
|
|
23
|
+
|
|
24
|
+
const manifestPath = join(import.meta.dirname, 'native-deps.json');
|
|
25
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
26
|
+
|
|
27
|
+
const token = process.env.GITHUB_TOKEN;
|
|
28
|
+
const apiHeaders = {
|
|
29
|
+
accept: 'application/vnd.github+json',
|
|
30
|
+
'user-agent': 'update-native-deps',
|
|
31
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// derive "OWNER/REPO" from a github.com baseUrl (targets shape) or url (single)
|
|
35
|
+
function repoFor(dep) {
|
|
36
|
+
const source = dep.baseUrl ?? dep.url;
|
|
37
|
+
const match = /^https:\/\/github\.com\/([^/]+\/[^/]+)/.exec(source ?? '');
|
|
38
|
+
if (!match) throw new Error(`cannot derive a github.com OWNER/REPO from: ${source}`);
|
|
39
|
+
return match[1];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// returns the latest release tag, or null when the repo publishes no release
|
|
43
|
+
async function latestReleaseTag(repo) {
|
|
44
|
+
const res = await fetch(`https://api.github.com/repos/${repo}/releases/latest`, {
|
|
45
|
+
headers: apiHeaders,
|
|
46
|
+
signal: AbortSignal.timeout(30000),
|
|
47
|
+
});
|
|
48
|
+
if (res.status === 404) return null;
|
|
49
|
+
if (!res.ok) throw new Error(`GitHub API returned HTTP ${res.status} for ${repo} latest release`);
|
|
50
|
+
const { tag_name: tag } = await res.json();
|
|
51
|
+
if (!tag) throw new Error(`latest release for ${repo} has no tag_name`);
|
|
52
|
+
return tag;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function sha256Url(url, allowedOrigin) {
|
|
56
|
+
const parsed = new URL(url);
|
|
57
|
+
if (allowedOrigin && parsed.origin !== allowedOrigin) {
|
|
58
|
+
throw new Error(`refusing to fetch from unexpected origin: ${parsed.origin}`);
|
|
59
|
+
}
|
|
60
|
+
const res = await fetch(parsed, { redirect: 'follow', signal: AbortSignal.timeout(120000) });
|
|
61
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} for ${parsed.href}`);
|
|
62
|
+
if (!res.body) throw new Error(`empty response body for ${parsed.href}`);
|
|
63
|
+
const hash = createHash('sha256');
|
|
64
|
+
await pipeline(Readable.fromWeb(res.body), hash);
|
|
65
|
+
return hash.digest('hex');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const changes = [];
|
|
69
|
+
for (const [name, dep] of Object.entries(manifest)) {
|
|
70
|
+
const repo = repoFor(dep);
|
|
71
|
+
const tag = await latestReleaseTag(repo);
|
|
72
|
+
if (tag === null) {
|
|
73
|
+
console.warn(`${name}: ${repo} publishes no GitHub release; skipping (update manually)`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (dep.targets) {
|
|
78
|
+
// targets shape: version is the full tag (e.g. "chromium/7920")
|
|
79
|
+
if (tag === dep.version) {
|
|
80
|
+
console.log(`${name}: up to date (${dep.version})`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
console.log(
|
|
84
|
+
`${name}: ${dep.version} -> ${tag}; re-hashing ${Object.keys(dep.targets).length} targets`,
|
|
85
|
+
);
|
|
86
|
+
for (const [key, target] of Object.entries(dep.targets)) {
|
|
87
|
+
const url = `${dep.baseUrl}/${encodeURIComponent(tag)}/${target.asset}`;
|
|
88
|
+
target.sha256 = await sha256Url(url, dep.origin);
|
|
89
|
+
console.log(` ${key}: ${target.sha256}`);
|
|
90
|
+
}
|
|
91
|
+
changes.push({ name, from: dep.version, to: tag });
|
|
92
|
+
dep.version = tag;
|
|
93
|
+
} else {
|
|
94
|
+
// single-url shape: manifest version is numeric; the tag may carry a v/n
|
|
95
|
+
// prefix. The url embeds the version string, so a plain substitution rebuilds
|
|
96
|
+
// both the tag segment and the filename.
|
|
97
|
+
const version = tag.replace(/^[^0-9]*/, '');
|
|
98
|
+
if (version === dep.version) {
|
|
99
|
+
console.log(`${name}: up to date (${dep.version})`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const url = dep.url.replaceAll(dep.version, version);
|
|
103
|
+
console.log(`${name}: ${dep.version} -> ${version}; re-hashing`);
|
|
104
|
+
dep.sha256 = await sha256Url(url, dep.origin);
|
|
105
|
+
dep.url = url;
|
|
106
|
+
changes.push({ name, from: dep.version, to: version });
|
|
107
|
+
dep.version = version;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (changes.length === 0) {
|
|
112
|
+
console.log('\nAll native dependencies are up to date.');
|
|
113
|
+
} else {
|
|
114
|
+
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
115
|
+
const summary = changes.map((c) => `- **${c.name}**: \`${c.from}\` → \`${c.to}\``).join('\n');
|
|
116
|
+
console.log(`\n${summary}`);
|
|
117
|
+
|
|
118
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
119
|
+
const body = [
|
|
120
|
+
'Automated native dependency update.',
|
|
121
|
+
'',
|
|
122
|
+
summary,
|
|
123
|
+
'',
|
|
124
|
+
'Checksums were recomputed from the upstream release assets. `verify-checksums` re-downloads each asset and confirms it matches the recorded hash — a consistency check against the same source, not independent provenance.',
|
|
125
|
+
].join('\n');
|
|
126
|
+
appendFileSync(process.env.GITHUB_OUTPUT, 'changed=true\n');
|
|
127
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `body<<PR_BODY_EOF\n${body}\nPR_BODY_EOF\n`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "napi_helpers.h"
|
|
4
|
+
|
|
5
|
+
#include <atomic>
|
|
6
|
+
#include <cstdio>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
#ifdef _WIN32
|
|
12
|
+
#include <io.h>
|
|
13
|
+
#define F_OK 0
|
|
14
|
+
#define access _access
|
|
15
|
+
#else
|
|
16
|
+
#include <unistd.h>
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#include "fpdf_attachment.h"
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Embedded-file (attachment) helpers
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// PDF/A-3 documents (ZUGFeRD / Factur-X / XRechnung e-invoices) carry the
|
|
25
|
+
// structured invoice as an embedded XML file in the /EmbeddedFiles name tree.
|
|
26
|
+
// FPDFDoc_GetAttachmentCount already surfaces detection via metadata; these
|
|
27
|
+
// workers add the ability to enumerate attachment metadata and read the raw
|
|
28
|
+
// bytes so callers can pull out factur-x.xml / zugferd-invoice.xml / etc.
|
|
29
|
+
|
|
30
|
+
// read a UTF-16LE string value from an attachment's params dictionary
|
|
31
|
+
inline std::u16string ReadAttachmentStringValue(FPDF_ATTACHMENT attachment,
|
|
32
|
+
const char *key) {
|
|
33
|
+
return ReadU16(
|
|
34
|
+
[&](auto *, unsigned long) {
|
|
35
|
+
return FPDFAttachment_GetStringValue(attachment, key, nullptr, 0);
|
|
36
|
+
},
|
|
37
|
+
[&](FPDF_WCHAR *buf, unsigned long len) {
|
|
38
|
+
return FPDFAttachment_GetStringValue(attachment, key, buf, len);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// GetAttachmentsWorker — async attachment metadata listing
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Deliberately cheap: reads only dictionary entries (name, subtype, dates)
|
|
46
|
+
// and never decodes the file streams. Use GetAttachmentDataWorker to fetch the
|
|
47
|
+
// bytes of a specific attachment.
|
|
48
|
+
|
|
49
|
+
struct AttachmentInfo {
|
|
50
|
+
int index = 0;
|
|
51
|
+
std::u16string name;
|
|
52
|
+
std::u16string mimeType;
|
|
53
|
+
std::u16string creationDate;
|
|
54
|
+
std::u16string modDate;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
class GetAttachmentsWorker : public SafeAsyncWorker {
|
|
58
|
+
public:
|
|
59
|
+
GetAttachmentsWorker(Napi::Env env, FPDF_DOCUMENT doc,
|
|
60
|
+
std::shared_ptr<std::atomic<bool>> docAlive)
|
|
61
|
+
: SafeAsyncWorker(env), deferred_(Napi::Promise::Deferred::New(env)),
|
|
62
|
+
doc_(doc), docAlive_(std::move(docAlive)) {}
|
|
63
|
+
|
|
64
|
+
Napi::Promise Promise() { return deferred_.Promise(); }
|
|
65
|
+
|
|
66
|
+
protected:
|
|
67
|
+
void Execute() override {
|
|
68
|
+
std::lock_guard<std::mutex> lock(g_pdfium_mutex);
|
|
69
|
+
if (!docAlive_ || !docAlive_->load()) {
|
|
70
|
+
SetError("Document was destroyed");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
int count = FPDFDoc_GetAttachmentCount(doc_);
|
|
75
|
+
if (count <= 0)
|
|
76
|
+
return;
|
|
77
|
+
|
|
78
|
+
attachments_.reserve(count);
|
|
79
|
+
for (int i = 0; i < count; i++) {
|
|
80
|
+
FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(doc_, i);
|
|
81
|
+
if (!attachment)
|
|
82
|
+
continue;
|
|
83
|
+
|
|
84
|
+
AttachmentInfo info;
|
|
85
|
+
info.index = i;
|
|
86
|
+
|
|
87
|
+
info.name = ReadU16(
|
|
88
|
+
[&](auto *, unsigned long) {
|
|
89
|
+
return FPDFAttachment_GetName(attachment, nullptr, 0);
|
|
90
|
+
},
|
|
91
|
+
[&](FPDF_WCHAR *buf, unsigned long len) {
|
|
92
|
+
return FPDFAttachment_GetName(attachment, buf, len);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
info.mimeType = ReadU16(
|
|
96
|
+
[&](auto *, unsigned long) {
|
|
97
|
+
return FPDFAttachment_GetSubtype(attachment, nullptr, 0);
|
|
98
|
+
},
|
|
99
|
+
[&](FPDF_WCHAR *buf, unsigned long len) {
|
|
100
|
+
return FPDFAttachment_GetSubtype(attachment, buf, len);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
info.creationDate = ReadAttachmentStringValue(attachment, "CreationDate");
|
|
104
|
+
info.modDate = ReadAttachmentStringValue(attachment, "ModDate");
|
|
105
|
+
|
|
106
|
+
attachments_.push_back(std::move(info));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void OnOK() override {
|
|
111
|
+
Napi::Env env = Env();
|
|
112
|
+
Napi::Array arr = Napi::Array::New(env, attachments_.size());
|
|
113
|
+
for (uint32_t i = 0; i < attachments_.size(); i++) {
|
|
114
|
+
const auto &info = attachments_[i];
|
|
115
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
116
|
+
obj.Set("index", Napi::Number::New(env, info.index));
|
|
117
|
+
SetU16(obj, "name", env, info.name);
|
|
118
|
+
SetU16(obj, "mimeType", env, info.mimeType);
|
|
119
|
+
SetU16IfPresent(obj, "creationDate", env, info.creationDate);
|
|
120
|
+
SetU16IfPresent(obj, "modDate", env, info.modDate);
|
|
121
|
+
arr.Set(i, obj);
|
|
122
|
+
}
|
|
123
|
+
deferred_.Resolve(arr);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
void OnError(const Napi::Error &err) override {
|
|
127
|
+
deferred_.Reject(err.Value());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private:
|
|
131
|
+
Napi::Promise::Deferred deferred_;
|
|
132
|
+
FPDF_DOCUMENT doc_;
|
|
133
|
+
std::shared_ptr<std::atomic<bool>> docAlive_;
|
|
134
|
+
std::vector<AttachmentInfo> attachments_;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
// GetAttachmentDataWorker — async read of a single attachment's bytes
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
class GetAttachmentDataWorker : public SafeAsyncWorker {
|
|
142
|
+
public:
|
|
143
|
+
GetAttachmentDataWorker(Napi::Env env, FPDF_DOCUMENT doc, int index,
|
|
144
|
+
std::string outputPath,
|
|
145
|
+
std::shared_ptr<std::atomic<bool>> docAlive)
|
|
146
|
+
: SafeAsyncWorker(env), deferred_(Napi::Promise::Deferred::New(env)),
|
|
147
|
+
doc_(doc), index_(index), outputPath_(std::move(outputPath)),
|
|
148
|
+
docAlive_(std::move(docAlive)) {}
|
|
149
|
+
|
|
150
|
+
Napi::Promise Promise() { return deferred_.Promise(); }
|
|
151
|
+
|
|
152
|
+
protected:
|
|
153
|
+
void Execute() override {
|
|
154
|
+
std::lock_guard<std::mutex> lock(g_pdfium_mutex);
|
|
155
|
+
if (!docAlive_ || !docAlive_->load()) {
|
|
156
|
+
SetError("Document was destroyed");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
int count = FPDFDoc_GetAttachmentCount(doc_);
|
|
161
|
+
if (index_ < 0 || index_ >= count) {
|
|
162
|
+
SetError("Attachment index out of range");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(doc_, index_);
|
|
167
|
+
if (!attachment) {
|
|
168
|
+
SetError("Failed to get attachment");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// first pass: query the decoded byte length (buffer null → size only)
|
|
173
|
+
unsigned long outLen = 0;
|
|
174
|
+
if (!FPDFAttachment_GetFile(attachment, nullptr, 0, &outLen)) {
|
|
175
|
+
SetError("Failed to read attachment file data");
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// second pass: copy the bytes (skip for a zero-length embedded file, where
|
|
180
|
+
// data_.data() would be null and the copy is a no-op anyway)
|
|
181
|
+
if (outLen > 0) {
|
|
182
|
+
data_.resize(outLen);
|
|
183
|
+
unsigned long written = 0;
|
|
184
|
+
if (!FPDFAttachment_GetFile(attachment, data_.data(), outLen, &written) ||
|
|
185
|
+
written != outLen) {
|
|
186
|
+
SetError("Failed to read attachment file data");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!outputPath_.empty()) {
|
|
192
|
+
// verify parent directory exists (mirrors RenderWorker)
|
|
193
|
+
auto slash = outputPath_.rfind('/');
|
|
194
|
+
if (slash != std::string::npos && slash > 0) {
|
|
195
|
+
std::string parentDir = outputPath_.substr(0, slash);
|
|
196
|
+
if (access(parentDir.c_str(), F_OK) != 0) {
|
|
197
|
+
SetError("Parent directory does not exist: " + parentDir);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
FILE *f = fopen(outputPath_.c_str(), "wb");
|
|
203
|
+
if (!f) {
|
|
204
|
+
SetError("Failed to open output file: " + outputPath_);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
size_t total = data_.size();
|
|
208
|
+
size_t wrote = total == 0 ? 0 : fwrite(data_.data(), 1, total, f);
|
|
209
|
+
fclose(f);
|
|
210
|
+
if (wrote != total) {
|
|
211
|
+
SetError("Failed to write output file: " + outputPath_);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
data_.clear();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void OnOK() override {
|
|
219
|
+
Napi::Env env = Env();
|
|
220
|
+
if (!outputPath_.empty()) {
|
|
221
|
+
deferred_.Resolve(env.Undefined());
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
auto *vec = new std::vector<uint8_t>(std::move(data_));
|
|
225
|
+
auto buffer = Napi::Buffer<uint8_t>::New(
|
|
226
|
+
env, vec->data(), vec->size(),
|
|
227
|
+
[](Napi::Env, uint8_t *, std::vector<uint8_t> *v) { delete v; }, vec);
|
|
228
|
+
deferred_.Resolve(buffer);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
void OnError(const Napi::Error &err) override {
|
|
232
|
+
deferred_.Reject(err.Value());
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private:
|
|
236
|
+
Napi::Promise::Deferred deferred_;
|
|
237
|
+
FPDF_DOCUMENT doc_;
|
|
238
|
+
int index_;
|
|
239
|
+
std::string outputPath_;
|
|
240
|
+
std::shared_ptr<std::atomic<bool>> docAlive_;
|
|
241
|
+
std::vector<uint8_t> data_;
|
|
242
|
+
};
|
package/src/document.h
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include "attachments_worker.h"
|
|
3
4
|
#include "bookmarks_worker.h"
|
|
4
5
|
#include "page.h"
|
|
5
6
|
|
|
@@ -21,6 +22,8 @@ public:
|
|
|
21
22
|
{
|
|
22
23
|
InstanceMethod<&PDFiumDocument::GetPage>("getPage"),
|
|
23
24
|
InstanceMethod<&PDFiumDocument::GetBookmarks>("getBookmarks"),
|
|
25
|
+
InstanceMethod<&PDFiumDocument::GetAttachments>("getAttachments"),
|
|
26
|
+
InstanceMethod<&PDFiumDocument::GetAttachment>("getAttachment"),
|
|
24
27
|
InstanceMethod<&PDFiumDocument::Destroy>("destroy"),
|
|
25
28
|
});
|
|
26
29
|
}
|
|
@@ -82,6 +85,51 @@ private:
|
|
|
82
85
|
return promise;
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Returns metadata for every embedded file / attachment (async).
|
|
90
|
+
*/
|
|
91
|
+
Napi::Value GetAttachments(const Napi::CallbackInfo &info) {
|
|
92
|
+
Napi::Env env = info.Env();
|
|
93
|
+
EnsureOpen(env);
|
|
94
|
+
if (env.IsExceptionPending())
|
|
95
|
+
return env.Null();
|
|
96
|
+
|
|
97
|
+
auto *worker = new GetAttachmentsWorker(env, doc_, docAlive_);
|
|
98
|
+
auto promise = worker->Promise();
|
|
99
|
+
worker->Queue();
|
|
100
|
+
return promise;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Reads the raw bytes of the attachment at `index` (async). Resolves to a
|
|
105
|
+
* Buffer, or writes to an optional output path and resolves to undefined.
|
|
106
|
+
*/
|
|
107
|
+
Napi::Value GetAttachment(const Napi::CallbackInfo &info) {
|
|
108
|
+
Napi::Env env = info.Env();
|
|
109
|
+
EnsureOpen(env);
|
|
110
|
+
if (env.IsExceptionPending())
|
|
111
|
+
return env.Null();
|
|
112
|
+
|
|
113
|
+
if (info.Length() < 1 || !info[0].IsNumber()) {
|
|
114
|
+
Napi::TypeError::New(env, "Expected attachment index")
|
|
115
|
+
.ThrowAsJavaScriptException();
|
|
116
|
+
return env.Null();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
int index = info[0].As<Napi::Number>().Int32Value();
|
|
120
|
+
|
|
121
|
+
std::string outputPath;
|
|
122
|
+
if (info.Length() > 1 && info[1].IsString()) {
|
|
123
|
+
outputPath = info[1].As<Napi::String>().Utf8Value();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
auto *worker = new GetAttachmentDataWorker(env, doc_, index,
|
|
127
|
+
std::move(outputPath), docAlive_);
|
|
128
|
+
auto promise = worker->Promise();
|
|
129
|
+
worker->Queue();
|
|
130
|
+
return promise;
|
|
131
|
+
}
|
|
132
|
+
|
|
85
133
|
/**
|
|
86
134
|
* Closes the document and releases all resources.
|
|
87
135
|
*/
|