Skip to content

Commit

Permalink
Fix failing gzip detection after GitHub changed what their download U…
Browse files Browse the repository at this point in the history
…RLs redirect to.
  • Loading branch information
sorccu committed Jun 18, 2017
1 parent c76c230 commit 6b08248
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ const download = module.exports.download = (src, writer) => {
}

const unpack = (stream) => {
const contentDisposition = res.headers['content-disposition']

if (contentDisposition) {
// This obviously isn't perfect, but considering how complex the
// whole issue is (see [1]) it should work well enough.
//
// [1] http://greenbytes.de/tech/tc2231/#attwithfn2231utf8
if (/attachment;.*filename.*\.gz(\s*$|")/.test(contentDisposition)) {
return stream.pipe(zlib.createGunzip()).on('error', reject)
}
}

if (options.pathname.endsWith('.gz')) {
return stream.pipe(zlib.createGunzip()).on('error', reject)
}
Expand Down

0 comments on commit 6b08248

Please sign in to comment.