diff --git a/src/http-request.js b/src/http-request.js index eb833ca71..52dbe8b0d 100644 --- a/src/http-request.js +++ b/src/http-request.js @@ -1,5 +1,4 @@ import assign from 'lodash.assign' -import getStream from 'get-stream' import startsWith from 'lodash.startswith' import { parse as parseUrl } from 'url' import { request as httpRequest } from 'http' @@ -7,7 +6,8 @@ import { request as httpsRequest } from 'https' import { stringify as formatQueryString } from 'querystring' import { - isString + isString, + streamToBuffer } from './utils' // ------------------------------------------------------------------- @@ -90,7 +90,7 @@ export default (...args) => { response.cancel = () => { req.abort() } - response.readAll = () => getStream(response) + response.readAll = () => streamToBuffer(response) const length = response.headers['content-length'] if (length) { diff --git a/src/remote-handlers/abstract.js b/src/remote-handlers/abstract.js index 5e35ff000..944e2683d 100644 --- a/src/remote-handlers/abstract.js +++ b/src/remote-handlers/abstract.js @@ -1,5 +1,4 @@ import eventToPromise from 'event-to-promise' -import getStream from 'get-stream' import through2 from 'through2' import { @@ -10,6 +9,7 @@ import { addChecksumToReadStream, noop, pCatch, + streamToBuffer, validChecksumOfReadStream } from '../utils' @@ -62,8 +62,8 @@ export default class RemoteHandlerAbstract { return this._readFile(file, options) } - async _readFile (file, options) { - return getStream(await this.createReadStream(file, options)) + _readFile (file, options) { + return this.createReadStream(file, options).then(streamToBuffer) } async rename (oldPath, newPath) { diff --git a/src/utils.js b/src/utils.js index 96cd54cdf..8dc4c532b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,7 @@ import base64url from 'base64url' import eventToPromise from 'event-to-promise' import forEach from 'lodash.foreach' +import getStream from 'get-stream' import has from 'lodash.has' import highland from 'highland' import humanFormat from 'human-format' @@ -45,17 +46,7 @@ export function bufferToStream (buf) { return stream } -export async function streamToBuffer (stream) { - return new Promise((resolve, reject) => { - const bufs = [] - - stream.on('error', reject) - stream.on('data', data => { - bufs.push(data) - }) - stream.on('end', () => resolve(Buffer.concat(bufs))) - }) -} +export const streamToBuffer = getStream.buffer // -------------------------------------------------------------------