Browse Source

Use pipe instead of manually piping inside data

cache-clone-stream
Luke Childs 8 years ago
parent
commit
159c3994a8
  1. 6
      index.js

6
index.js

@ -212,21 +212,19 @@ function asStream(opts) {
if (opts.cache && policy.storable()) {
const bodyChunks = [];
res.on('data', chunk => {
output.push(chunk);
bodyChunks.push(chunk);
});
res.on('end', () => {
output.push(null);
res.body = Buffer.concat(bodyChunks);
if (opts.encoding !== null) {
res.body = res.body.toString(opts.encoding);
}
cacheResponse(res, policy, opts);
});
} else {
res.pipe(output);
}
res.pipe(output);
if (statusCode !== 304 && (statusCode < 200 || statusCode > 299)) {
proxy.emit('error', new got.HTTPError(statusCode, opts), null, res);
return;

Loading…
Cancel
Save