Replies: 2 comments 4 replies
-
You can make your current code work by manually resolving a returned Promise; I can send code to do so if you'd like. However, since you're already loading all the data of the ZIP file into memory, I'd probably not bother with streaming the unzip process and instead use the buffer-based API. const { promisify } = require('util');
const { unzip } = require('fflate');
const unzipAsync = promisify(unzip);
async function unzipFile({ input, output }) {
const compressed = await fs.promises.readFile(input);
const unzipped = await unzip(compressed);
if (!unzipped[output]) {
// file not found in archive
throw new Error(`could not find ${output} in zip file ${input}`);
}
await fs.promises.writeFile(output, unzipped[output]);
// Number of files in archive is number of keys in returned object
return Object.keys(unzipped.length);
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi @101arrowz , I also have this question but with streaming in a browser. I can't work out how to know when all files in the zip file have been processed. Can you tell me how to do this please?
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to unzip a deflate file that is on disk and then do stuff with the unzipped file and need to have a way to block the calling code from running until the unzipping is done and the uncompressed file is written back to the disk. The zipped file is 20+MB and the unzipped file is 150+ MB so they can take a tad bit to finish. I have written the following and it creates the uncompressed data file on disk. What is the best way to block the response from the unzipFile function so when doing an
await unzipFile
it is resolved when the file unzipping is finished, and the file is written to the disk? Also, is there a better way to return how many files are in the zipped file?Thanks
Beta Was this translation helpful? Give feedback.
All reactions