diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/get-stream | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) | |
download | wallet-core-363723fc84f7b8477592e0105aeb331ec9a017af.tar.xz |
node_modules
Diffstat (limited to 'node_modules/get-stream')
-rw-r--r-- | node_modules/get-stream/buffer-stream.js | 33 | ||||
-rw-r--r-- | node_modules/get-stream/index.js | 50 | ||||
-rw-r--r-- | node_modules/get-stream/package.json | 15 | ||||
-rw-r--r-- | node_modules/get-stream/readme.md | 8 |
4 files changed, 48 insertions, 58 deletions
diff --git a/node_modules/get-stream/buffer-stream.js b/node_modules/get-stream/buffer-stream.js index cc834c4dc..ae45d3d9e 100644 --- a/node_modules/get-stream/buffer-stream.js +++ b/node_modules/get-stream/buffer-stream.js @@ -1,14 +1,13 @@ -var PassThrough = require('stream').PassThrough; -var objectAssign = require('object-assign'); +'use strict'; +const PassThrough = require('stream').PassThrough; -module.exports = function (opts) { - opts = objectAssign({}, opts); +module.exports = opts => { + opts = Object.assign({}, opts); - var array = opts.array; - var encoding = opts.encoding; - - var buffer = encoding === 'buffer'; - var objectMode = false; + const array = opts.array; + let encoding = opts.encoding; + const buffer = encoding === 'buffer'; + let objectMode = false; if (array) { objectMode = !(encoding || buffer); @@ -20,16 +19,15 @@ module.exports = function (opts) { encoding = null; } - var len = 0; - var ret = []; - - var stream = new PassThrough({objectMode: objectMode}); + let len = 0; + const ret = []; + const stream = new PassThrough({objectMode}); if (encoding) { stream.setEncoding(encoding); } - stream.on('data', function (chunk) { + stream.on('data', chunk => { ret.push(chunk); if (objectMode) { @@ -39,16 +37,15 @@ module.exports = function (opts) { } }); - stream.getBufferedValue = function () { + stream.getBufferedValue = () => { if (array) { return ret; } + return buffer ? Buffer.concat(ret, len) : ret.join(''); }; - stream.getBufferedLength = function () { - return len; - }; + stream.getBufferedLength = () => len; return stream; }; diff --git a/node_modules/get-stream/index.js b/node_modules/get-stream/index.js index aa60cf038..2dc5ee96a 100644 --- a/node_modules/get-stream/index.js +++ b/node_modules/get-stream/index.js @@ -1,24 +1,31 @@ 'use strict'; -var Promise = require('pinkie-promise'); -var objectAssign = require('object-assign'); -var bufferStream = require('./buffer-stream'); +const bufferStream = require('./buffer-stream'); function getStream(inputStream, opts) { if (!inputStream) { return Promise.reject(new Error('Expected a stream')); } - opts = objectAssign({maxBuffer: Infinity}, opts); - var maxBuffer = opts.maxBuffer; - var stream; - var clean; + opts = Object.assign({maxBuffer: Infinity}, opts); + + const maxBuffer = opts.maxBuffer; + let stream; + let clean; + + const p = new Promise((resolve, reject) => { + const error = err => { + if (err) { // null check + err.bufferedData = stream.getBufferedValue(); + } + + reject(err); + }; - var p = new Promise(function (resolve, reject) { stream = bufferStream(opts); inputStream.once('error', error); inputStream.pipe(stream); - stream.on('data', function () { + stream.on('data', () => { if (stream.getBufferedLength() > maxBuffer) { reject(new Error('maxBuffer exceeded')); } @@ -26,34 +33,19 @@ function getStream(inputStream, opts) { stream.once('error', error); stream.on('end', resolve); - clean = function () { - // some streams doesn't implement the stream.Readable interface correctly + clean = () => { + // some streams doesn't implement the `stream.Readable` interface correctly if (inputStream.unpipe) { inputStream.unpipe(stream); } }; - - function error(err) { - if (err) { // null check - err.bufferedData = stream.getBufferedValue(); - } - reject(err); - } }); p.then(clean, clean); - return p.then(function () { - return stream.getBufferedValue(); - }); + return p.then(() => stream.getBufferedValue()); } module.exports = getStream; - -module.exports.buffer = function (stream, opts) { - return getStream(stream, objectAssign({}, opts, {encoding: 'buffer'})); -}; - -module.exports.array = function (stream, opts) { - return getStream(stream, objectAssign({}, opts, {array: true})); -}; +module.exports.buffer = (stream, opts) => getStream(stream, Object.assign({}, opts, {encoding: 'buffer'})); +module.exports.array = (stream, opts) => getStream(stream, Object.assign({}, opts, {array: true})); diff --git a/node_modules/get-stream/package.json b/node_modules/get-stream/package.json index e23737dd5..2f2adf0d5 100644 --- a/node_modules/get-stream/package.json +++ b/node_modules/get-stream/package.json @@ -1,6 +1,6 @@ { "name": "get-stream", - "version": "2.3.1", + "version": "3.0.0", "description": "Get a stream as a string, buffer, or array", "license": "MIT", "repository": "sindresorhus/get-stream", @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { "test": "xo && ava" @@ -30,20 +30,19 @@ "buffer", "read", "data", + "consume", "readable", "readablestream", "array", "object", "obj" ], - "dependencies": { - "object-assign": "^4.0.1", - "pinkie-promise": "^2.0.0" - }, "devDependencies": { "ava": "*", - "buffer-equals": "^1.0.3", - "into-stream": "^2.0.1", + "into-stream": "^3.0.0", "xo": "*" + }, + "xo": { + "esnext": true } } diff --git a/node_modules/get-stream/readme.md b/node_modules/get-stream/readme.md index a74866bb2..73b188fb4 100644 --- a/node_modules/get-stream/readme.md +++ b/node_modules/get-stream/readme.md @@ -46,7 +46,7 @@ getStream(stream).then(str => { ## API -The methods returns a promise that is resolved when the `end` event fires on the stream, indicating that there is no more data to be read. The stream is switched to flowing mode. +The methods returns a promise that resolves when the `end` event fires on the stream, indicating that there is no more data to be read. The stream is switched to flowing mode. ### getStream(stream, [options]) @@ -93,8 +93,10 @@ If the input stream emits an `error` event, the promise will be rejected with th ```js getStream(streamThatErrorsAtTheEnd('unicorn')) - .catch(err => console.log(err.bufferedData)); -// unicorn + .catch(err => { + console.log(err.bufferedData); + //=> 'unicorn' + }); ``` |