feat(utils/streamToBuffer): rebase on get-stream and use everywhere (#295)
This commit is contained in:
parent
bb75d42ede
commit
5b8608c186
@ -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) {
|
||||
|
@ -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) {
|
||||
|
13
src/utils.js
13
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
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user