-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetch() stream capable? #1
Comments
Now there are only some simple utility functions, such as adding text files, streaming serializing javascript objects into JSON strings, and adding them as files. function createFetchDataGenerator(factory: () => Promise<Response<unknown>>) Users probably use it this way. zip.addFile('a.bin', createFetchDataGenerator(() => fetch('xxx'))) |
Looks reasonable. :-)
alternatively, for more control, maybe something like (it's usually a good idea to give people the option - some browsers limit the total number of connections, so if you app needs 1 or 2 connections, you might want 4 or 5 concurrent promises, or you might want no more than 2 or 3 to ease the server load, requirements are often different here.) |
As far as I know, the files in the zip are added one after another. For example, there is no way to add 50% of the content of a.bin first, then add 60% of the content of b.bin, and then add the remaining 50% of the content of a.bin. All the contents of a.bin must be added first, and then all the contents of b.bin. So actually concurrency doesn't make sense, requests should be made one after the other when considering "streaming". If "streaming" and memory usage are not considered (for example, the requested files are small), A third-party const asyncTaskPool = new AsyncTaskPool({concurrent: 4})
const zip = new StreamZip();
// fetch files and add them to zip
toRequests.forEach(([addr, filename]) => {
asyncTaskPool.add(() => fetch(addr).then(resp => {
// read total buffer
const buf = resp.arrayBuffer()
zip.add(filename, createBytesDataGenerator(new Uint8Array(buf)))
}))
}) |
Yes, that's not what I'm asking for. 🙂 But you can start opening the |
Hi,
do you know if there's any way to add body streams from
fetch
calls with this library?(e.g. downloading a list of files and compressing them on the fly.)
The text was updated successfully, but these errors were encountered: