How to ensure zipWriter.close() waits for streamed data to finish downloading? #523
Replies: 3 comments 9 replies
-
I did not test the code (yet) but you are supposed to call |
Beta Was this translation helpful? Give feedback.
-
const response = await fetch(file.url);
// const fileContent = new BlobReader(await response.blob());
const fileContent = response.body || undefined; this is error! const response = await fetch(file.url).catch(e=>undefined);
if(response){
return addFileData(`${category}/${file.name}`, response.body);
} |
Beta Was this translation helpful? Give feedback.
-
your error is const response = await fetch(file.url).catch(e=>e.message);
if(response instanceof Response){
//if no-cros response 404 500
if(response.status!==200){
return ;
}
//or check mime
if(response.headers.get('content-type') != 'image/png'){
return;
}
return addFileData(`${category}/${file.name}`, response.body);
}
console.log(response ); |
Beta Was this translation helpful? Give feedback.
-
Excuse the question because I'm not sure exactly what my issue is. But what my problem seems to be is that
zipWriter.close()
is happening before a file that I'm fetching is completely fetched. I'm trying to download multiple files usingfetch
, and passing theresponse.body
(aReadableStream
) to zipWriter.add. Then I'mawait
ing the Promise.all for these before callingzipWriter.close()
.This is working for several small files, but when I have a large-ish file (20mb) selected, it seems like this file is still being downloaded after zipWriter.close() is called, and a Fetch failed error is thrown. If I
fetch
the same file without adding it to the zipWriter, there is no error; I can fetch it independently of the zip logic just fine.Update: fixed code below. This works as described above.
I did find this discussion (#442) which is the for same error I'm seeing, but I haven't confirmed if it was due to the disk being full. I'm also not really sure what to make of it, or if it means that my machine just can't handle the file size.
My internet speeds have varied during my testing, but even when download was relatively faster, the error still came up, just quicker, so I don't think it has to do with the speed of the download.
I guess I want to know (if anyone has some insight)
Screenshots
Logs in failed state
Note: I don't get
'Closing zipWriter...'
here, so it seems like we're not making it to the zipWriter.close() call. BUT we then see'Cannot close a ERRORED writable stream'
. Not sure what I can tell from this.Network tab
File is fetched completely (21.4mb), but this happens well after the above errors.
Logs in success state (multiple smaller files)
Network tab
Beta Was this translation helpful? Give feedback.
All reactions