I tried out your streamToString method documented here: https://docs.digitalocean.com/products/spaces/reference/s3-sdk-examples/#download-a-file-from-a-space but it seems not to work anymore.
I get a typeError: stream.on is not a function.
With this code it seems to work (typescript but should also work in js):
const streamToString = async (stream: ReadableStream) => {
const reader = stream.getReader();
const chunks = [];
let stop = false;
while (!stop) {
const { done, value } = await reader.read();
if (value) {
chunks.push(value);
}
if (done) {
stop = true;
}
}
return Buffer.concat(chunks).toString("utf-8");
};