Skip to content

Commit

Permalink
Merge pull request #2092 from Utsav2/gzip
Browse files Browse the repository at this point in the history
Decompress gzip files
  • Loading branch information
sheerun committed Dec 13, 2015
2 parents 8b2fad3 + 4255d7d commit 1e5122c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/util/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function download(url, file, options) {
minTimeout: 1000,
maxTimeout: 35000,
randomize: true,
progressDelay: progressDelay
progressDelay: progressDelay,
gzip: true
}, options || {});

// Retry on network errors
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"p-throttler": "0.1.1",
"promptly": "0.2.0",
"q": "^1.1.2",
"request": "2.53.0",
"request": "2.67.0",
"request-progress": "0.3.1",
"retry": "0.6.1",
"rimraf": "^2.2.8",
Expand Down
Binary file added test/assets/test-gz.txt
Binary file not shown.
Binary file added test/assets/test-gz.txt.gz
Binary file not shown.
34 changes: 33 additions & 1 deletion test/util/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('download', function () {
nock('http://bower.io', opts.nockOpts)
);

download('http://bower.io/package.tar.gz', destination, opts.downloadOpts)
download(opts.sourceUrl || 'http://bower.io/package.tar.gz', opts.destinationPath || destination, opts.downloadOpts)
.then(function (result) {
if (opts.expect) {
opts.expect(result);
Expand Down Expand Up @@ -174,4 +174,36 @@ describe('download', function () {
}
});
});

describe('gzipped files', function () {

function testGzip(sourceFilename) {
var sourceFile = path.resolve(__dirname, '../assets/' + sourceFilename);
var destinationPath = tempDir.getPath(sourceFilename);

return downloadTest({
response: function(nock) {
nock
.get('/' + sourceFilename)
.replyWithFile(200, sourceFile, {
'Content-Encoding' : 'gzip'
});
},
expect: function() {
expect(fs.readFileSync(destinationPath, 'ascii'))
.to.be('Hello World!\n');
},
sourceUrl: 'http://bower.io/' + sourceFilename,
destinationPath: destinationPath
});
}

it('correctly decodes gzipped files without gz extension', function () {
return testGzip('test-gz.txt');
});

it('correctly decodes gzipped files with gz extension', function () {
return testGzip('test-gz.txt.gz');
});
});
});

0 comments on commit 1e5122c

Please sign in to comment.