-
Notifications
You must be signed in to change notification settings - Fork 344
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
Extract doesn't emit "close" event #80
Comments
Same here.. close is never fired event when finished the extract |
You can try unzipper, a drop in replacement for In the example above, here are three different ways to extract the file successfully (first two are compatible with const unzipper = require('./node-unzipper');
const fs = require('fs');
const path = require('path');
const filePath = '/tmp/test-subtitles/the-moth-diaries_english-627840.zip';
const outputDir = '/tmp/test-subtitles'; // this directory has to exist already
// Extract
fs.createReadStream(filePath)
.pipe(unzipper.Extract({path: outputDir}))
.on('close', () => console.log('Extract closed'));
// Parse each file with .on('entry',...)
fs.createReadStream(filePath)
.pipe(unzipper.Parse())
.on('entry', entry => {
entry.pipe(fs.createWriteStream(path.join(outputDir, 'parse.srt')))
.on('finish', () => console.log('parse done'));
});
// ParseOne (parses the first file)
fs.createReadStream(filePath)
.pipe(unzipper.ParseOne())
.pipe(fs.createWriteStream(path.join(outputDir,'parseOne.srt')))
.on('finish', () => console.log('parseOne done'));
// Open.file (opens the central directory and parses the first file)
unzipper.Open.file(filePath)
.then(directory => {
directory.files[0].stream()
.pipe(fs.createWriteStream(path.join(outputDir,'open.srt')))
.on('finish', () => console.log('open done'));
}); You can also unzip streaming from a url by using |
Hi.. tryed using unzipper, close its triggered but the folder its empty in that time:
console: Actually this is not making the unzip.. the destFolder still empty.. with node-unzip was unzipping |
Thanks for the report @mariohmol. Is the zip file you are looking at public or sharable - if so can you share a link? If you don't want it public you can also email me the file (ziggy.jonsson.nyc@gmail.com). Also can you tell me which version of unzipper you are using (if not the latest one). As @rhodgkins has pointed out in ZJONSSON#57 we emit |
No errors with error event, using version "unzipper": "^0.9.1" and its a normal zip using mac |
That worked:
|
Thanks @mariohmol, awesome that you got this working with I ran your exact example with
Would you be so kind to verify the node version you are running so I can make sure I am not missing anything? If you want to debug this further please note that errors do not propagate. So if you put an error handler on every step of the way you might be able to catch what went wrong, i.e.: fs.createReadStream(filepath)
.on('error', console.log)
.pipe(unzipper.Extract({ path: destFolder }))
.on('error', console.log)
.on('close', () => {
console.log(destFolder);
res.json({});
fs.readdir(destFolder, (err, files) => {
console.log(err, files, `<----`)
files.forEach(fileFound => {
console.log(fileFound);
});
});
}); |
Thanks for your attention! my node: v6.11.2 I found the issue, the filepath must be relative but the folderPath must be absolute. I could reproduce the error: This gives the error:
When i change the last line , it works
|
Excellent, thank you @mariohmol for investigating further. Great to get to the bottom of this! Ideally we should be able to catch all errors and the final response of a stream pipeline by something like
..,but we aren't there yet in native streams (here is my custom implementation with propagation tests) |
Thanks for the clarification. Isnt possible to test and check if works relative and absolute? so the dest folder will work anyway? |
I cannot unzip the file I download from this site. http://subscene.com/subtitles/the-moth-diaries/english/627840
The problem is: unzip.Extract never emit "close" event, and the entry (the .srt file) has 0 KB (as in the picture)
This is a really rare case. Hope you can fix it :)
The text was updated successfully, but these errors were encountered: