Skip to content

Add streaming base64 encode/decode via TransformStream - #187

Draft
Hexagon with Copilot wants to merge 2 commits into
mainfrom
copilot/add-cross-runtime-support
Draft

Hexagon with Copilot wants to merge 2 commits into
mainfrom
copilot/add-cross-runtime-support

Conversation

Copilot AI commented Nov 19, 2025 •

Copy link
Copy Markdown
Contributor

Adds memory-efficient streaming support for base64 encoding and decoding using Web Streams API.

Changes

  • New Classes

    • Base64EncoderStream - TransformStream<Uint8Array, string> for streaming encode
    • Base64DecoderStream - TransformStream<string, Uint8Array> for streaming decode
    • Both support standard base64 and base64url via constructor urlMode parameter
  • Implementation

    • Automatic chunk boundary handling via internal buffering (3-byte for encode, 4-char for decode)
    • Reuses existing encoding/decoding functions
    • Zero dependencies - uses native TransformStream
  • Documentation

    • README, examples.md, and index.md updated with streaming API and usage
    • Version bumped to 3.0.0 (breaking: new major API surface)

Usage

// Encode a large file stream
const encoder = new base64.Base64EncoderStream();
await fileStream.readable
  .pipeThrough(encoder)
  .pipeTo(destination);

// Decode base64 stream
const decoder = new base64.Base64DecoderStream(true); // URL mode
await base64Stream.readable
  .pipeThrough(new TextDecoderStream())
  .pipeThrough(decoder)
  .pipeTo(destination);

Compatibility

Node.js 16.5+, Deno 1.16+, Bun, modern browsers (all with native TransformStream support).

Original prompt

Add cross runtime support for streaming encoding and decoding. Keep it lean.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…m, update docs, bump to v3.0.0

Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copilot AI changed the title [WIP] Add cross runtime support for streaming encoding and decoding Add streaming base64 encode/decode via TransformStream Nov 19, 2025
Copilot AI requested a review from Hexagon November 19, 2025 00:50
@Hexagon
Hexagon requested a balanced review from Copilot September 12, 2026 19:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Formatting fails CI, decoder boundary coverage is incomplete, and examples use an API unavailable in the documented runtime range.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds Web Streams-based Base64 encoding and decoding while preserving standard and URL-safe modes.

Changes:

  • Adds encoder and decoder TransformStream classes.
  • Adds streaming tests and usage documentation.
  • Bumps the package to version 3.0.0.
File summaries
File Description
src/base64.ts Implements and exports streaming APIs.
tests/base64.test.ts Adds streaming behavior tests.
README.md Lists streaming APIs and compatibility.
docs/index.md Documents stream classes and usage.
docs/examples.md Adds streaming examples.
deno.json Bumps the package version.
Review details

Suppressed comments (3)

tests/base64.test.ts:222

  • This “multiple chunks” case splits only on four-character boundaries, so it never exercises the decoder's new buffering across a quartet boundary. Use deliberately unaligned chunks so a regression in buffer carry-over is detected.
  const chunks = ["SGVs", "bG8g", "d29y", "bGQ="];

docs/examples.md:66

  • ReadableStream.from() is unavailable before Node.js v20.6.0, despite the documented v16.5.0 minimum. Use the baseline stream constructor so this decoding example works on supported Node.js versions.
const decodedStream = ReadableStream.from([base64Data])
  .pipeThrough(decoder);

docs/examples.md:84

  • This URL-mode example also relies on ReadableStream.from(), which requires Node.js v20.6.0 rather than the advertised v16.5.0. Build the source with the standard constructor to preserve the stated compatibility.
const urlEncodedStream = ReadableStream.from([textData])
  .pipeThrough(urlEncoder);
  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/base64.test.ts
const reader = ReadableStream.from([new TextEncoder().encode("Hello world")])
.pipeThrough(encoder)
.getReader();

Comment thread docs/examples.md
Comment on lines +54 to +55
const encodedStream = ReadableStream.from([textData])
.pipeThrough(encoder);

This branch has not been deployed

No deployments
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.

3 participants