Closed mykhailoklym94 closed 2 months ago
The best way to do this is first to use the Open
method to open the zip file to get the central directory, and then you can open individual entries at your leisure. If you want to do this with the .pipe
method, then you can simply stop consuming for a bit (and the stream pauses on its own).
Here is a rudimentary example of how you can pause inside on('entry
if you are still processing previous file:
let isProcessing;
on('entry', async entry => {
await isProcessing;
const data = await entry.buffer();
isProcessing = process(data);
const results = await isProcessing;
isProcessing = undefined;
}
This would strangely work because .on('entry
happens sequentially as the zip file is read sequentially. So we should never have multiple isProcessing
set at any given time
Hi @ZJONSSON, thanks for the great library!
I was wondering if there is a way to somehow
pause
the processing of the zip for a period of time. I will provide an example to make it clear.Let's say I have a zip file with the following structure:
My goal is to process these files sequentially, here is the general algorithm that I want to achieve:
file-1.json
file-1.json
- let's say it takes around 20-30 secondsfile-2.json
andfile-3.json
.Here is a contrived example in code:
Explanation for the code: What I am trying to achieve is to buffer the file into memory, pause unziper for some time until I process the file. I tried to pause the incoming stream, but apparently, it doesn't work and unzipper keeps loading data into memory.