-
Notifications
You must be signed in to change notification settings - Fork 106
Open
Description
Version: @smithy/util-stream@4.2.0
when buffering a stream, createBufferedReadable
treats Uint8Array and Buffer chunks differently. Switching from one to the other inside a stream makes it flush its buffer - which can lead to an InvalidChunkSizeError when this function is used by S3Client
. I'm not sure if mixing both Buffer and Uint8Array chunks in a same stream is "legal" or not, but it's an easy mistake to do if not, especially since on NodeJS Buffer is a base of Uint8Array (so Typescript won't complain if you mix them up).
Minimal reproducer:
import * as streams from "node:stream";
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
async function main() {
const client = new S3Client({ requestStreamBufferSize: 32 * 1024 });
async function* mixedData(): AsyncIterable<Uint8Array> {
yield new Uint8Array(2000); // too small chunk, should get buffered with the following one
yield Buffer.alloc(128_000);
}
// Triggers an InvalidChunkSizeError
await client.send(
new PutObjectCommand({
Bucket: "test-bucket",
Key: "test",
ContentLength: 130_000,
Body: streams.Readable.from(mixedData()),
})
);
}
main();
Metadata
Metadata
Assignees
Labels
No labels