Write to R2 with ReadableStream

Im trying to write a ReadableStream to R2, however, I cannot pass a stream to the r2 .put without giving it a fixed size first, so I am piping an email objects stream to a FixedLengthStream as so:

let { readable, writeable } = new FixedLengthStream(message.rawSize);
message.raw.pipeTo(writeable);


and then saving it to R2 as follows:

await env.BUCKET_NAME.put(identifier, readable);


Im seeing the entry identifier in my R2 bucket, however the content is empty. message.rawSize is showing the number of bytes I would expect.

Am I using the stream pipes wrong?

Thank you
Was this page helpful?