Repository navigation
feat(convert): @p10node/convert, server-side conversion (CLI + HTTP service with Gotenberg's routes) (#43) - #56
Merged
Conversation
…CLI, HTTP service with Gotenberg's routes) First part of p10node#43. The engine runs in Node or Bun on worker threads and converts files without LibreOffice: - convert(bytes, { to }): opens any format the viewer opens, waits until it is read whole (docx.start / sheet loading hidden), writes DOCX / XLSX / PPTX, or the document as text, Markdown, HTML, CSV / TSV - Converter: a pool of worker threads; a file past its time limit or whose caller gave up ends with its thread, a full queue is refused - office-convert: files on the command line, several at once, size and time limits; `office-convert serve` for the HTTP service - createHandler: POST /convert (multipart or the file as the body), Gotenberg's /forms/libreoffice/convert (501 until PDF, p10node#44), /health, /version, Gotenberg-Output-Filename and Gotenberg-Trace, a ZIP for several files - Dockerfile: built with Bun, runs on node:26-slim with the bundle only Core: XlsxWorkbook.text() waits for the values computed after reading, so a CSV written right after opening has the formulas the file gave no value for (it had them empty before, also in the browser's Download as CSV). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nputs never overwritten - pool: the bytes are copied before they move to a thread (a Node Buffer can share its memory: posting it failed and left the thread busy); a failed dispatch rejects its conversion and frees the thread; input bytes running and waiting have a budget (`bytes`, 1 GB); a queued conversion's abort listener is removed once it leaves the queue - convert: `maxOutput` (1 GB; a sparse sheet is refused before its CSV is written) and `maxUnpacked` (gzip inputs, 1 GB, through a new `maxUnpacked` open parameter of the engine); a sheet index must be a whole number - HTTP: Gotenberg's route answers 501 before the body is read or the pool asked; a file of a request failing gives up the others; ZIP names unique without their case; `too-large` is 413 - CLI: stdout is written whole before the process ends (exitCode, not exit); an output that is one of the inputs under any name (a link) is refused, and without --force a file is only created (wx); stdin is refused once past --max-size; files are read and converted as threads become free; `in out` with an existing output is refused instead of read as two inputs - types: relative imports of the .d.ts files with .js, for NodeNext Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds, held bodies - CSV / TSV: the size limit is applied by the exporter (xlsx.text takes a limit): the cells in use are counted, not the sheet's extent, so a blank formatted cell far away no longer refuses a small export, and the text is counted while it is written - pool: a thread that cannot start fails its conversion and gives its bytes back - HTTP: request bodies held at once have a budget (`maxPending`, 1 GB): past it 503 with Retry-After, before the pool is asked - CLI: named files are read up to --max-size too (a pipe or a device has no size); an output is checked on the file opened, before it is truncated, against the inputs and stdin when it is a file; no byte budget (files go one per thread); `a.doc b.md` with both existing converts both again (only --force with an existing second name is refused) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #43 (except PDF, which is #44).
What it does
A new package,
@p10node/convert, runs office-engine on a server with no browser and no LibreOffice. It works on Node ≥ 22 and Bun ≥ 1.3.convert(input, { to })converts in-process. It hidesdocx.start/docx:done/xlsx:progressand returns{ data, name, type, ext, kind, from?, warnings }.sheet: an index or a name).Converteris a pool onnode:worker_threads, which works on both Node and Bun.Buffer's shared pool is never transferred.office-convertCLI:office-convert a.doc b.xlsx,office-convert in.doc out.md,-o dir, and-for stdin and stdout;--max-sizeand--timeout;office-convert serveis a Web-standard fetch handler that runs onBun.serve, or onnode:httpthrough an adapter.POST /converttakes multipart or a raw body. Several files come back as a ZIP./healthand/versionin Gotenberg's shapes, and honours theGotenberg-Output-FilenameandGotenberg-Traceheaders./forms/libreoffice/convertanswers 501 until PDF output exists (PDF output without a browser #44). It refuses before reading the body.maxBytesper request,maxFiles, and a sharedmaxPendingbudget for bodies being read. A request over the budget gets 503 andRetry-After.oven/bunbuild stage and anode:26-slimruntime. It runs as a non-root user and has a HEALTHCHECK. The image is about 383 MB, and it builds, starts and reports healthy.Core changes
Workbook.text()awaitssettled(), so CSV exported right after load no longer has empty formula values. It also takes alimitand throws aRangeErrorwhile writing once the limit is passed.xlsx.textin the protocol takes an optionallimit.OpenParams.maxUnpackedlimits gzip-compressed inputs (.csv.gz, .svgz);ungzipped()counts the bytes as they are unpacked.Review
Codex reviewed the branch in two rounds before anything was pushed.
ef9b056):BufferDataCloneErrorthat wedged the pool;--forceoverwriting an input through a symlink;sheet 0.5;.d.tsfiles under NodeNext;in outform;748ced4):maxPendingbudget);--force -o;--max-size;spawnleaving its bytes charged to the budget;Known limitation: a multipart request is parsed (buffered, up to
maxBytes) beforemaxFilesis checked.Tests
test/convert-service.test.tsadds 20 tests covering conversions, limits, the pool, HTTP and the CLI.main(encodings on Bun 1.3.6).bun run typecheckis clean andbun run build:packagesbuilds.distand on Bun from source;npm pack, then install andnpx office-convert.Before release
@p10node/convertis a new npm package.release.ymlpublishespackages/*, but the package needs its npm trusted publisher set up once before the first publish..eml/.msginput will follow once feat: e-mail messages (.eml, .msg) open read-only, attachments saved from the File menu #55 lands.🤖 Generated with Claude Code