Skip to content

S3Client writes empty file for HTMLRewriter transformed fetch Response #19305

Closed

Description

@nickjackson

What version of Bun is running?

1.2.10+db2e7d7f7

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

const r2 = new S3Client(); // setup r2 params

describe("S3Client", () => {
  test("save webpage to R2 via HTMLRewriter", async () => {
    const response = await fetch("https://bun.sh");

    const rewriter = new HTMLRewriter();
    const rewrittenResponse = rewriter.transform(response);

    await r2.write("index.html", rewrittenResponse);

    const text = await r2.file("index.html").text();
    expect(text).not.toBeEmpty();
  });

  test("save webpage to R2", async () => {
    const response = await fetch("https://bun.sh");

    await r2.write("index2.html", response);

    const text = await r2.file("index2.html").text();
    expect(text).not.toBeEmpty();
  });
});

The first test fails and it should not.

What is the expected behavior?

I'd expect to be able to fetch some HTML, run it through a HTMLRewriter and save that back to R2 via the S3Client.

If this shouldn't work, then it ought to error rather then create an empty file on R2.

What do you see instead?

The client will occasionally (but not always) write empty files.

Additional information

  • I'm unsure if this is only an issue with Cloudflare R2, I've not tried the others.
  • Converting the transformed response to text first will workaround the issue. r2.write(path, await response.text()
  • Writing to a local file with Bun.file (instead of S3Client) works as expected.

Activity

  1. added 7 commits that reference this issue on Jun 28, 2026
    d9d9955
    3ad4ee6
    7805d6e
    a47d290
    30345c2
    38cbdaa
    54c7be8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HTMLRewritercloudflare workers APIbugSomething isn't workings3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions