refactor: use Uint8Array instead of Buffer - #1764
Open
diegomura wants to merge 1 commit into
Open
Conversation
diegomura
added a commit
to diegomura/react-pdf
that referenced
this pull request
Aug 12, 2026
…t#1764 Adopts upstream's naming and shapes so the files stay mergeable: concat instead of concatBytes, toUTF16BE writing its own BOM, fromBinaryString masking with 0xff, and the restructured encrypt branch in object.js. Restores src/virtual-fs.js with upstream's Uint8Array version. It is unreachable in this fork (not imported, not exported, absent from both bundles), but keeping it avoids a needless divergence. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Buffer is a Uint8Array subclass, and Readable.push() converts Uint8Array to Buffer zero-copy, so Buffer inputs and Buffer output chunks keep working on Node.
diegomura
force-pushed
the
diegomura/replace-buffer-with-uint8array
branch
from
August 12, 2026 23:20
f2fb807 to
15fb90d
Compare
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.
What kind of change does this PR introduce?
Nothing under
lib/uses Node'sBufferanymore.Latin1 and UTF-16BE encoding, hex and base64 conversion, concatenation and fixed-size allocation all go through
Uint8Arrayand a few helpers inlib/binary.jsnow.This is part of modernizing the library, and follows the fflate and base64 changes.
Bufferis a Node builtin that bundlers no longer polyfill by default, and it was the last one left in code that has to run in a browser.It is not a breaking change.
Bufferis aUint8Arraysubclass, so passing one toimage(),file()orregisterFont()works as before, andReadable.push()convertsUint8ArraytoBufferzero-copy, so Node consumers still readBufferchunks off the document stream.pdfkit/virtual-fsnow returns aUint8ArrayfromreadFileSync(). Encoded reads still return strings.A dict value that is a plain
Uint8Arraynow serializes to a hex string. The check wasBuffer.isBuffer(), so it used to fall through toString(obj)and write1,2,3.TextDecoder('latin1')is not a valid replacement for theString.fromCharCodeloops. Node mapslatin1,iso-8859-1andwindows-1252all to ISO-8859-1, but the WHATWG Encoding Standard makes all three windows-1252, where0x80decodes to U+20AC. Browsers follow the spec, so it would corrupt0x80-0x9Fin the browser build.