mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
Merge pull request #170 from Meeeeow/fix_yarn_upstream
Fix upstream search not work with gzip
This commit is contained in:
commit
f4058bb5c2
3 changed files with 19 additions and 9 deletions
|
@ -371,8 +371,8 @@ class Storage {
|
|||
}, function() {
|
||||
let lstream = self.local.search(startkey, options);
|
||||
stream.abort = function() {
|
||||
lstream.abort();
|
||||
};
|
||||
lstream.abort();
|
||||
};
|
||||
lstream.pipe(stream, {end: true});
|
||||
lstream.on('error', function(err) {
|
||||
self.logger.error({err: err}, 'search error: @{err.message}');
|
||||
|
|
|
@ -9,6 +9,7 @@ const parse_interval = require('./config').parse_interval;
|
|||
const Logger = require('./logger');
|
||||
const MyStreams = require('./streams');
|
||||
const Utils = require('./utils');
|
||||
const zlib = require('zlib');
|
||||
const encode = function(thing) {
|
||||
return encodeURIComponent(thing).replace(/^%40/, '@');
|
||||
};
|
||||
|
@ -410,18 +411,27 @@ class Storage {
|
|||
},
|
||||
});
|
||||
|
||||
let parsePackage = (pkg) => {
|
||||
if (Utils.is_object(pkg)) {
|
||||
stream.emit('data', pkg);
|
||||
}
|
||||
};
|
||||
|
||||
req.on('response', (res) => {
|
||||
if (!String(res.statusCode).match(/^2\d\d$/)) {
|
||||
return stream.emit('error', Error('bad status code ' + res.statusCode + ' from uplink'));
|
||||
}
|
||||
|
||||
res.pipe(JSONStream.parse('*')).on('data', (pkg) => {
|
||||
if (Utils.is_object(pkg)) {
|
||||
stream.emit('data', pkg);
|
||||
}
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
// See https://github.com/request/request#requestoptions-callback
|
||||
// Request library will not decode gzip stream.
|
||||
let jsonStream;
|
||||
if (res.headers['content-encoding'] === 'gzip') {
|
||||
jsonStream = res.pipe(zlib.createUnzip());
|
||||
} else {
|
||||
jsonStream = res;
|
||||
}
|
||||
jsonStream.pipe(JSONStream.parse('*')).on('data', parsePackage);
|
||||
jsonStream.on('end', () => {
|
||||
stream.emit('end');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue