Hi,
I tried streamsaver js in my app. It can write the stream data into a file. But the download is in progress even after the stream is closed. I used the below code.
function unencrypt(value){
// should return Uint8Array
return new Uint8Array(value)
}
// We use fetch instead of xhr that has streaming support
fetch(url).then(res => {
// create a writable stream + intercept a network response
const fileStream = streamSaver.createWriteStream('filename.txt')
const writer = fileStream.getWriter()
// stream the response
const reader = res.body.getReader()
const pump = () => reader.read()
.then(({ value, done }) => {
let chunk = unencrypt(value)
// Write one chunk, then get the next one
writer.write(chunk) // returns a promise
// While the write stream can handle the watermark,
// read more data
return writer.ready.then(pump)
)
// Start the reader
pump().then(() =>
console.log('Closed the stream, Done writing')
)
})
Hi, I tried streamsaver js in my app. It can write the stream data into a file. But the download is in progress even after the stream is closed. I used the below code.