0

I have a zip folder that contain a html file. I want to extract the zip in a directory then read the content of the html. In this code i can extract the zip folder but when i want read the content of the extracted file i found this error 'No such file or directory...' eve the file exist in the write path but i think that my code read the content of the html before the extraction.How can i fix this please.

var unzip = require('unzip');
 var stream =  fs.createReadStream(zipFilePath).pipe(unzip.Extract({ path: outputPath }));
stream.on('finish',function({console.log('done')});
 console.log(fs.readFileSync('outputPath'+'/'+htmlFile).toString());
Mat
  • 631
  • 3
  • 10
  • 21
  • 1
    Put the `fs.readFileSync` in the `finish` callback, not outside of it. – zero298 May 07 '19 at 14:17
  • The console.log() will run first, before the file exists, since it's not part of the onfinished callback. So replace `console.log( 'done' );` with the readFile() call. – Shilly May 07 '19 at 14:19
  • Not only that, but I think you have a typo in your code, you need an extra `)` before the `console.log(fs...`. – zero298 May 07 '19 at 14:20
  • when i put read file inside on.finished return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ Error: ENOENT: no such file or directory, open 'outPutPath\file.html' – Mat May 07 '19 at 14:21
  • Also, don't use the [`node-unzip` library](https://github.com/EvanOxfeld/node-unzip/issues/120) – zero298 May 07 '19 at 14:30
  • what should i use, if you have a proposition write an answer :D – Mat May 07 '19 at 14:33
  • That GitHub issue links to this answer: [Simplest way to download and unzip files in Node.js cross-platform?](https://stackoverflow.com/a/46967462/691711). I would check against that. I couldn't even get the `node-unzip` library to function. – zero298 May 07 '19 at 14:36

0 Answers0