Encodes bytes as standard, padded base64 (RFC 4648 §4).
Written out by hand rather than delegating, on purpose: Buffer does not
exist in a browser and would drag a Node dependency into a package that must
run in both, while btoa only accepts a string of code units ≤ 255 — feeding
it a large buffer means first materialising that string, which is exactly the
spread-the-arguments pattern that blows the call stack on real snapshots.
Sixteen lines of table lookup have neither problem and are identical on every
runtime, which is what §33 wants from anything on the replay path.
Output is built in chunks and joined once, so encoding an N-byte buffer costs
O(N) and holds at most one chunk of intermediate string at a time.
Encodes bytes as standard, padded base64 (RFC 4648 §4).
Written out by hand rather than delegating, on purpose:
Bufferdoes not exist in a browser and would drag a Node dependency into a package that must run in both, whilebtoaonly accepts a string of code units ≤ 255 — feeding it a large buffer means first materialising that string, which is exactly the spread-the-arguments pattern that blows the call stack on real snapshots. Sixteen lines of table lookup have neither problem and are identical on every runtime, which is what §33 wants from anything on the replay path.Output is built in chunks and joined once, so encoding an N-byte buffer costs O(N) and holds at most one chunk of intermediate string at a time.