refactor(pdfkit): parse images from plain Uint8Array - #3472
Closed
diegomura wants to merge 1 commit into
Closed
Conversation
Drops the remaining Node `Buffer` requirements from image parsing: - `image.js` accepts any `Uint8Array` (a `Buffer` still is one) and no longer copies `ArrayBuffer` input through `Buffer.from` - `image/jpeg.js` uses the `binary.js` `readUInt16BE` helper instead of the `Buffer.prototype` method, matching the EXIF parser already in that file - `binary.js` grows `fromBinaryString`, which `fromBase64` now reuses `image/png.js` is left alone: it feeds `zlib.deflateSync`, and the browser build aliases `zlib` to `browserify-zlib`, which rejects non-`Buffer` input (see #3431). That one goes with the pako swap. Extracted from #3397.
🦋 Changeset detectedLatest commit: 447eeb8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Extracted from #3397 (PR 1 & 3 of the plan, image half). Drops the remaining Node
Bufferrequirements from image parsing.Changes
image.js— accepts anyUint8Array(aBufferstill is one), and stops copyingArrayBufferinput throughBuffer.from. PlainUint8Arraysources now work instead of falling through tofs.readFileSync.image/jpeg.js— uses thebinary.jsreadUInt16BEhelper rather than theBuffer.prototypemethod, matching the EXIF parser already in that file.binary.js— addsfromBinaryString;fromBase64becomes a one-liner on top of it.Not included
image/png.jsstays onBuffer. It feedszlib.deflateSync, and the browser build aliaseszlibtobrowserify-zlib, which throws on non-Bufferinput — that was #3431. Those lines belong with the pako swap (PR 7 in the #3397 plan), not here.Tests
New
tests/image.test.tscoversPDFImage.openforUint8Array,Buffer,ArrayBuffer, base64 data URI, and unknown-format input; newtests/binary.test.tscovers the byte helpers againstBufferas the reference. Fullrenderer/render/imagesuites pass unchanged.