|
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}`); |
|
} |
|
} |