title: NodeJs unzip stream
body: <p>I need unzip some two level zip:  </p>
  
  <pre><code>file1.zip
    - file1.1.zip
      - data.txt
    - file1.2.zip
    - file1.3.zip
  </code></pre>
  
  <p>I need just data.txt in file1.1.zip inside file1.zip and I need ignore (<code>entry.autodrain();</code>) other entries.  </p>
  
  <p>This is info about zip:  </p>
  
  <pre><code>apshenichnikov@IAS-WS-UX02:/tmp$ file /var/logs-storage/wcm/119/2017-11-01-119-TcVXBh5RPEHTm86y7sOvJc7TjyQcAc6bqZVawcniIPwyJpWlYqCBJ2XNqBj1ikVF.zip
  /var/logs-storage/wcm/119/2017-11-01-119-TcVXBh5RPEHTm86y7sOvJc7TjyQcAc6bqZVawcniIPwyJpWlYqCBJ2XNqBj1ikVF.zip: Zip archive data, at least v4.5 to extract
  
  
  apshenichnikov@IAS-WS-UX02:/tmp$ unzip -t /var/logs-storage/wcm/119/2017-11-01-119-TcVXBh5RPEHTm86y7sOvJc7TjyQcAc6bqZVawcniIPwyJpWlYqCBJ2XNqBj1ikVF.zip
  Archive:  /var/logs-storage/wcm/119/2017-11-01-119-TcVXBh5RPEHTm86y7sOvJc7TjyQcAc6bqZVawcniIPwyJpWlYqCBJ2XNqBj1ikVF.zip
      testing: datamining_119_20171101_clickevent.zip   OK
      testing: datamining_119_20171101_impressionvisibility.zip   OK
      testing: datamining_119_20171101_conversion.zip   OK
  No errors detected in compressed data of /var/logs-storage/wcm/119/2017-11-01-119-TcVXBh5RPEHTm86y7sOvJc7TjyQcAc6bqZVawcniIPwyJpWlYqCBJ2XNqBj1ikVF.zip.
  </code></pre>
  
  <p>This is the code:</p>
  
  <pre><code>fs.createReadStream(source)
      .pipe(unzipper.Parse())
      .on('entry', (entry) =&gt;
      {
          if (found || stop)
          {
              entry.autodrain();  
              return;
          }
  
          var filePath = entry.path;
          var type = entry.type; // 'Directory' or 'File'
          //var size = entry.size; // might be undefined in some archives
  
          log.info(getMessage(ID, util.format("Entry: %s", filePath)));
  
          var outPath = path.join(target, filePath);
  
          if (
              filePath.match(
                  new RegExp(
                      util.format(
                          "datamining_\d+_\d+_%s.*\.zip", 
                          type
                      )
                  )
              )
          ) {
              var outStream = fs.createWriteStream(outPath);
              entry.pipe(outStream);
              found = true;
  
              procLogStream.write(util.format(
                  "%s Found: %s\r\n", 
                  utils.getCurrentDate(),
                  filePath
              ));
  
              outStream.on('finish', () =&gt;
              {
                  if (!stop)
                  {
                      cb();
                      //tmpdir.removeCallback();
                      console.log('out stream finish');
                  }
  
                  stop = true;
              }).on('error', (err) =&gt;
              {
                  if (!stop)
                  {
                      cb(err);
                      //tmpdir.removeCallback();
                      console.log('out stream error');
                  }
  
                  stop = true;
              });
          } else {
              entry.autodrain();
          }
      })
      .on('error', (err) =&gt;
      {
          console.log('zip stream error');
          console.log(err);
          if (!found &amp;&amp; !stop) {
              cb(err);
              //tmpdir.removeCallback();
          }
  
          stop = true;
      })
      .on('finish', () =&gt;
      {
          console.log('zip stream finish');
          if (!found &amp;&amp; !stop) {
              cb();
              //tmpdir.removeCallback();
          }
  
          stop = true;
      });
  </code></pre>
  
  <p>And these are the errors:  </p>
  
  <pre><code>info: [utils/worker.js] 5a27a822cb569b2db8bc493d: Entry: datamining_119_20171101_clickevent.zip
  zip stream error
  Error: invalid signature: 0x83268e0
      at /home/apshenichnikov/NetBeansProjects/lps/node_modules/unzip/lib/parse.js:59:13
      at runCallback (timers.js:666:20)
      at tryOnImmediate (timers.js:639:5)
      at processImmediate [as _immediateCallback] (timers.js:611:5)
  error: [utils/worker.js] 5a27a822cb569b2db8bc493d Error: invalid signature: 0x83268e0
  error: [utils/worker.js] 5a27a822cb569b2db8bc493d: errored
  zip stream error
  { Error: unexpected end of file
      at Zlib._handle.onerror (zlib.js:370:17) errno: -5, code: 'Z_BUF_ERROR' }
  </code></pre>
  
  <p>I search much for library which will actually work, I tried tree...<br>
  I feel that there is no option in NodeJs to handle zip files...<br>
  Can you disprove my belief?</p>