glebdmitriew / node-unzip-2

node.js cross-platform unzip using streams
MIT License
44 stars 39 forks source link

Pipe from request #19

Open RWOverdijk opened 7 years ago

RWOverdijk commented 7 years ago

Cool library. It works fine with files, but I can't get it to work with requests:

const request = require('request');
const unzip   = require('unzip2');

const run = () => {
  let stream = request.get(SDK_URL).pipe(unzip.Parse()).on('entry', entry => {
    entry.autodrain();
  });

  return new Promise((resolve, reject) => {
    stream.on('finish', resolve);
    stream.on('error', reject);
  });
};

This gives me:

{ Error: invalid distance too far back at Zlib._handle.onerror (zlib.js:355:17) errno: -3, code: 'Z_DATA_ERROR' }

Any ideas?

mtharrison commented 7 years ago

I'm getting similar errors @RWOverdijk. I'd like to debug. Are you able to provide a file (or URL) to test this with that shows the error?

RWOverdijk commented 7 years ago

@mtharrison I was using this to download the google chromecast sdk. I worked around it by simply downloading the file first, and then creating a read stream from disk.

mtharrison commented 7 years ago

Do you know the URL for that? I tried https://developers.google.com/cast/downloads/GoogleCastSDK-Public-3.4.0-Release-ios.zip and it works with the above code. May I ask what OS you're on?

RWOverdijk commented 7 years ago

https://developers.google.com/cast/downloads/GoogleCastSDK-Public-3.1.1-Release-ios.zip for instance. (old, I know)

Mac os

mtharrison commented 7 years ago

Thanks, I'm also on Mac OSX. I tried to run your code above and it's executing just fine with that URL:

const SDK_URL = 'https://developers.google.com/cast/downloads/GoogleCastSDK-Public-3.1.1-Release-ios.zip';

const request = require('request');
const unzip   = require('unzip2');

const stream = request.get(SDK_URL).pipe(unzip.Parse()).on('entry', entry => {

  console.log(entry.path);
  entry.autodrain();
});

stream.on('finish', () => console.log('finished'));
stream.on('error', (err) => console.error(err));

Are you able to confirm that running the above gives you an error? Can I ask what versions of Node/Unzip2/Request that you're using?