node-unzip icon indicating copy to clipboard operation
node-unzip copied to clipboard

readstream, close and entry sequence

Open gavinwilliams opened this issue 12 years ago • 3 comments

Hi there, I'm trying to extract files one by one through the entry callback and build up an array of files once each one has been extracted.

Once the last entry has been extracted, I then want to call my callback and pass through the entries to it. Close seems to be called before I finish extracting my files.

Is there a callback that is called once all of the entries have finished extracting? Or do i need to implement something myself?

The code looks like the below:

        fs.createReadStream(Card.getSrcOrigin())
            .pipe(unzip.Parse())
            .on('entry', function(entry) { _self._extractEntry(entry, Card) })
            .on('close', oncomplete)
            .on('error', function(){
                console.log(arguments);
            });

    /**
     * Extracts an entry from an unzip callback entry
     * @param {entry} entry - A file within the zip file
     * @param {Card} Card - The current Card that is being extracted
     */
    this._extractEntry = function(entry, Card){

        if(!this._validate.entry(entry)){
            return;
        }

        var targetFile = Card.getCode() + '-' + uuid.v4() + path.extname(entry.path);
        targetFile = path.join(destination, targetFile);

        entry.pipe(fs.createWriteStream(targetFile))
            .on('close', function(){
                Card.addFile(targetFile);
            });
    }

gavinwilliams avatar Jul 22 '13 18:07 gavinwilliams

Me too! Perhaps there is something that could be done with the issue?

juhamust avatar Aug 27 '13 11:08 juhamust

I annoyingly got around this by posting each entry as they came through to my external service, and modifying my other services to support it. Kind of sucked to be honest.

gavinwilliams avatar Aug 28 '13 13:08 gavinwilliams

As a workaround (worked for my case, at least) is to process files again after the unzip has completed. This makes the entry processing somewhat... less useful, though.

Actually, end up using https://github.com/cthackers/adm-zip, in the end (because of some odd problems while extracting the zip package with unzip). However, hopefully the issue gets resolved for this project, too.

juhamust avatar Aug 29 '13 08:08 juhamust