Skip to content

refactor: decode base64 image data URIs without Buffer - #1759

Merged
blikblum merged 1 commit into
masterfrom
diegomura/pdfkit-image-binary-changes
Aug 8, 2026
Merged

refactor: decode base64 image data URIs without Buffer#1759
blikblum merged 1 commit into
masterfrom
diegomura/pdfkit-image-binary-changes

Conversation

@diegomura

Copy link
Copy Markdown
Collaborator

Ports the image.js / binary.js changes from diegomura/react-pdf#3400.

  • Adds fromBase64 to lib/binary.js (atob + Uint8Array), replacing Buffer.from(match[1], 'base64') in PDFImage.open.
  • Switches the JPEG parser's header reads from this.data.readUInt16BE(...) to the shared readUInt16BE helper it already imports. Without this, the data-URI path throws this.data.readUInt16BE is not a function, since the decoded data is now a plain Uint8Array.
  • Adds a unit test covering both PNG and JPEG data URIs — previously only the JPEG data URI was exercised, and only indirectly through the visual tests.

The PNG magic-byte check from that PR is already on master.

Buffer is still used elsewhere in image.js (Buffer.isBuffer, the ArrayBuffer branch) and across security.js / object.js / virtual-fs.js, so this removes one usage rather than the dependency.

Adds a fromBase64 helper to binary.js and makes the JPEG parser read
headers via the shared readUInt16BE helper, so image data flows as
Uint8Array end to end.
@diegomura diegomura changed the title Decode base64 image data URIs without Buffer refactor: decode base64 image data URIs without Buffer Aug 8, 2026
@blikblum
blikblum merged commit f308aae into master Aug 8, 2026
3 checks passed
@blikblum
blikblum deleted the diegomura/pdfkit-image-binary-changes branch August 8, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants