Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompress gzip files #2092

Merged
merged 2 commits into from
Dec 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
});
});
});