jspm / npm

NPM Location Service
19 stars 34 forks source link

Only unzip if the npm package is gzipped #147

Closed MortenHoustonLudvigsen closed 8 years ago

MortenHoustonLudvigsen commented 8 years ago

It turns out that not all packages downloaded from npm are actually gzipped (even though they are named *.tgz). Specifically, I have seen this with the @types scope introduced recently for use with typescript. In theses cases jspm install fails when trying to unzip:

jspm install npm:@types/jquery
     Updating registry cache...
     Downloading npm:@types/jquery@1.10.28

err  Error: incorrect header check
    at Zlib._handle.onerror (zlib.js:370:17)

This pull request resolves this by checking whether the downloaded package is actually gzipped, and only extracts the tar contents if not.

MortenHoustonLudvigsen commented 8 years ago

I can also make a pull request against branch 0.17, if that would be better.

guybedford commented 8 years ago

Thanks so much for the PR, this looks really great!

When we've finished review on this, getting it into 0.17 as well would definitely be worth doing.

MortenHoustonLudvigsen commented 8 years ago

I'm glad you like it.

MortenHoustonLudvigsen commented 8 years ago

Right, this is now implemented by peeking at the first few bytes of the download stream to check if the contents are gzipped. I reverted the first commit and made a third. If you decide that this should be merged, I am happy to squash the commits first. :-)

guybedford commented 8 years ago

Looks great, thanks!

guybedford commented 8 years ago

If you're able to do a PR for 0.17 too please do.