Can I give file chunk by chunk for downloading in JavaScript?

Viewed 29

This question is touching the browser part of JavaScript.

I have a web code that can receive parts of the file chunk by chunk. Every chunk is about 750 kB. And the size of the whole file can be 20-30 MB and more.

Currently, the user needs to wait for when all chunks are received and joined together and then download the whole file.

Can I force downloading when the first chunk is received and serve the file to the user chunk by chunk?

Or it doesn't matter because the total downloading time will be the same?

1 Answers

This issue can be solved using FileSave.js

a simple example of saving a txt file

import { saveAs } from 'file-saver';

var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, "hello world.txt");

Related