Skip to content
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

uncaught FILE_ENDED error #75

Closed
rhodgkins opened this issue Aug 24, 2018 · 7 comments
Closed

uncaught FILE_ENDED error #75

rhodgkins opened this issue Aug 24, 2018 · 7 comments

Comments

@rhodgkins
Copy link

rhodgkins commented Aug 24, 2018

I think this is the same as #48 - I've opened a new issue as that was closed and changes have been made since then...!

After finding this out when moving over to the Open APIs (#74) I've been looking into it and found that it's caused by the following line:

self.emit('error', new Error('FILE_ENDED'));

Is this supposed to be emitting on p - the returned PassThrough stream instead?

I've been playing around with a fix here which instead emits the error to the returned stream instead.
I've also had to include a similar fix as #57 (nulling out self.cb) and these changes fix the uncaught error and its propagated up to the Promise retuned from unzipper.Open.file but it breaks the parseOneEntry.js: error - file ended test case and I'm not sure why :-/

I hope this helps you debug it a bit! It might be the case that after the bug in the fix for #57 is implemented (#71) everything might work without this anyway...

@ZJONSSON
Copy link
Owner

I think this should be fixed now - please reopen if issue persists

@lucidkodo
Copy link

lucidkodo commented Jul 10, 2019

Hey guys! i'm not sure if this issue is back?

But i was using zipper.Extract() in a for loop

for (let i = 0; i < files.length; i++) {
  // console.log(files[i]) // /home/angie/exporter/auto/unsubscribe/zip/something.csv.zip

  fs.createReadStream(files[i])
    .pipe(zipper.Extract({
      path: 'path/to/dest/'
    }))
    .on('error', e => {
      console.log(e)
    })
    .on('finish', () => {
      console.log('finished')
    })
}

and gave gave me this error:

Error: FILE_ENDED
    at Parse.pull (/home/angie/exporter/node_modules/unzipper/lib/PullStream.js:80:28)
    at Parse.emit (events.js:189:13)
    at Parse.<anonymous> (/home/angie/exporter/node_modules/unzipper/lib/PullStream.js:20:10)
    at Parse.emit (events.js:194:15)
    at finishMaybe (_stream_writable.js:641:14)
    at endWritable (_stream_writable.js:649:3)
    at Parse.Writable.end (_stream_writable.js:589:5)
    at DuplexWrapper.<anonymous> (/home/angie/exporter/node_modules/duplexer2/index.js:29:14)
    at Object.onceWrapper (events.js:277:13)
    at DuplexWrapper.emit (events.js:194:15)
    at finishMaybe (/home/angie/exporter/node_modules/duplexer2/node_modules/readable-stream/lib/_stream_writable.js:630:14)
    at endWritable (/home/angie/exporter/node_modules/duplexer2/node_modules/readable-stream/lib/_stream_writable.js:638:3)
    at DuplexWrapper.Writable.end (/home/angie/exporter/node_modules/duplexer2/node_modules/readable-stream/lib/_stream_writable.js:594:41)
    at ReadStream.onend (_stream_readable.js:651:10)
    at Object.onceWrapper (events.js:277:13)
    at ReadStream.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
finished
finished
finished
Done in 5.99s.

(However the files extracted okay without problem!)
Maybe you might want to look into this? or let me know if i'm doing anything wrong!
Thanks for the package! :)

@ZJONSSON
Copy link
Owner

ZJONSSON commented Jul 10, 2019

@lucidkodo FILE_ENDED is an error that is thrown if the zip file is not valid, i.e. the reader reads past of the end of the zip file without concluding the parse. Is it possible that one of the files is broken?

You might want to try async await and do one file at a time and see if it makes a difference, or at the very least spot the offending file.

async function extract() {
  for (let i = 0; i < files.length; i++) {
    console.log(files[i]);
    await fs.createReadStream(files[i])
      .pipe(zipper.Extract({path: 'path/to/dest'}))
      .on('error',console.log)
      .on('finish', () => console.log('finised')
      .promise()
  }
}

Or you could use the Open method (which is technically better as it uses the Central Directory for offset information):

async function extract() {
  for (let i = 0; i < files.length; i++) {
    console.log(files[i]);
    const directory = await zipper.Open.file(files[i]);
    await directory.extract({'path/to/dest'})
  }
}

@lucidkodo
Copy link

@ZJONSSON thank you so much for your prompt reply!
There was an empty csv file in my array!

I'm using the first suggested approach as i need to do some extra processing once the file is done unzipping. thanks again!

@jlommori
Copy link

@ZJONSSON I'm experiencing the same file_ended issues when using the zipper.Open.file(file) method. I'm looping through paths for 10 zip files, all of which are valid (at least can be opened by the OS and have contents, both dirs and files). I receive the error inconsistently each time I run the code. Sometimes its all files, sometimes only some of them. It has me stumped. Any suggestions for troubleshooting?

@ZJONSSON
Copy link
Owner

ZJONSSON commented Jul 25, 2019

@jlommori Can you confirm you are using the latest version of unzipper and also share the code? If the zip files are not sensitive and you want me to replicate the issue you can send them to ziggy.jonsson.nyc@gmail.com

@jlommori
Copy link

@ZJONSSON Of course as I extract the code to post here and test it, everything works when the section isolated from everything else. So I guess I have some additional troubleshooting to do within the whole program. Thank you for the willingness to assist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants