Skip to content

Instantly share code, notes, and snippets.

@catdevnull
Created October 18, 2025 22:37
Show Gist options
  • Select an option

  • Save catdevnull/1bea1654bd5a419b7c2dc2710df1d847 to your computer and use it in GitHub Desktop.

Select an option

Save catdevnull/1bea1654bd5a419b7c2dc2710df1d847 to your computer and use it in GitHub Desktop.
repro-bug-bun-s3-amp

output:

Res from aws-sdk: Hello, world!
Error reading with no escaping with bun: S3Error: Key not found
Error reading with escaping with bun: S3Error: Key not found
List from bun: 
- testing-bun-bug/hello?world&...
- testing-bun-bug/test.txt
Error reading testing-bun-bug/hello?world&... with bun: S3Error: Key not found
Content for testing-bun-bug/test.txt from bun: Hello, world!

notice how it fails to read the file, even when directly taking the key off of the directory listing.

import {
_Object,
GetObjectCommand,
ListObjectsV2Command,
PutObjectCommand,
S3Client,
} from "@aws-sdk/client-s3";
// only tested in Backblaze B2, but I would assume happens in other places.
const B2_REGION = "us-west-004";
const B2_BUCKET = process.env.B2_BUCKET || "flybondi-fail";
const b2 = new S3Client({
endpoint: `https://s3.${B2_REGION}.backblazeb2.com`,
region: B2_REGION,
credentials: {
accessKeyId: process.env.B2_KEY_ID!,
secretAccessKey: process.env.B2_APP_KEY!,
},
});
const B2_PATH = "testing-bun-bug";
await b2.send(
new PutObjectCommand({
Bucket: B2_BUCKET,
Key: `${B2_PATH}/hello?world&...`,
Body: "Hello, world!",
})
);
{
const response = await b2.send(
new GetObjectCommand({
Bucket: B2_BUCKET,
Key: `${B2_PATH}/hello?world&...`,
})
);
const text = await response.Body?.transformToString();
console.log(`Res from aws-sdk: ${text}`);
}
{
const bunb2 = new Bun.S3Client({
endpoint: `https://s3.${B2_REGION}.backblazeb2.com`,
region: B2_REGION,
bucket: B2_BUCKET,
accessKeyId: process.env.B2_KEY_ID,
secretAccessKey: process.env.B2_APP_KEY,
});
try {
const response = bunb2.file(`${B2_PATH}/hello?world&...`);
const text = await response.text();
console.log(`Res from bun: ${text}`);
} catch (error) {
console.error(`Error reading with no escaping with bun: ${error}`);
}
try {
const response = await bunb2.file(`${B2_PATH}/hello?world&...`).text();
console.log(`Res from bun: ${response}`);
} catch (error) {
console.error(`Error reading with escaping with bun: ${error}`);
}
try {
const response = await bunb2.list({
prefix: B2_PATH,
});
console.log(
`List from bun: \n- ${response.contents?.map((c) => c.key).join("\n- ")}`
);
for (const content of response.contents || []) {
if (!content.key) continue;
const file = bunb2.file(content.key);
try {
const text = await file.text();
console.log(`Content for ${content.key} from bun: ${text}`);
} catch (error) {
console.error(`Error reading ${content.key} with bun: ${error}`);
}
}
} catch (error) {
console.error(`Error listing with bun: ${error}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment