@reportwright/pdf 0.1.0-beta.2 → 0.1.0-beta.3

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/README.md CHANGED
@@ -249,6 +249,26 @@ const { bytes } = await doc.saveIncremental(); // the origin
249
249
  [`examples/merge-split.mjs`](./examples/merge-split.mjs). `save()` rewrites the file (and strips active content);
250
250
  `saveIncremental()` appends (and refuses files with active content): see [Security model](#security-model).
251
251
 
252
+ ### Bulk: many files in worker threads
253
+
254
+ ```js
255
+ import { bulk } from '@reportwright/pdf';
256
+
257
+ const files = fs.readdirSync('in').map((f) => fs.readFileSync(`in/${f}`));
258
+ const texts = await bulk(files, 'extractText', { workers: 4 }); // [{ ok: true, value } | { ok: false, error }]
259
+ const locked = await bulk(files, 'encrypt', { encrypt: { userPassword: 'u', ownerPassword: 'o' } });
260
+ const pages = await bulk(files, 'split'); // value: one Uint8Array per page
261
+ const joined = await bulk([[a, b], [c, d]], 'merge'); // each input: the files to merge
262
+ ```
263
+
264
+ Tasks are names (`extractText`, `merge`, `split`, `encrypt`; `BULK_TASKS`), never functions, so only bytes and plain
265
+ options cross to a worker. Results come back in input order; a file that fails (malformed, wrong password, over the
266
+ budget) gives `{ ok: false, error: { name, code, message } }` and the batch goes on. Each worker's heap is capped
267
+ (`memoryMb`, default 512): a file that exhausts it kills only that worker, its item fails with `E_WORKER`, and a new
268
+ worker takes the next. `workers` defaults to `os.availableParallelism() - 1`. Node only: in browsers (no
269
+ `node:worker_threads`), and with `workers: 1`, the same tasks run one at a time in the calling thread, without the
270
+ heap cap. [`examples/bulk.mjs`](./examples/bulk.mjs).
271
+
252
272
  ## Examples
253
273
 
254
274
  | file | what it shows | run |
@@ -263,6 +283,7 @@ const { bytes } = await doc.saveIncremental(); // the origin
263
283
  | [`invoice-facturx.mjs`](./examples/invoice-facturx.mjs) | self-contained Factur-X PDF/A-3a invoice | `node examples/invoice-facturx.mjs font.ttf out.pdf` |
264
284
  | [`factur-x.mjs`](./examples/factur-x.mjs) | Factur-X from your own CII XML | `node examples/factur-x.mjs invoice.xml font.ttf out.pdf` |
265
285
  | [`merge-split.mjs`](./examples/merge-split.mjs) | merge, split, extractText, saveIncremental | `node examples/merge-split.mjs outDir` |
286
+ | [`bulk.mjs`](./examples/bulk.mjs) | extractText and encrypt over many files in worker threads | `node examples/bulk.mjs outDir` |
266
287
 
267
288
  Run from `node_modules/@reportwright/pdf` (or the package folder of the repository).
268
289