diff options
Diffstat (limited to 'node_modules/into-stream')
-rw-r--r-- | node_modules/into-stream/index.js | 79 | ||||
-rw-r--r-- | node_modules/into-stream/license | 21 | ||||
-rw-r--r-- | node_modules/into-stream/package.json | 50 | ||||
-rw-r--r-- | node_modules/into-stream/readme.md | 42 |
4 files changed, 192 insertions, 0 deletions
diff --git a/node_modules/into-stream/index.js b/node_modules/into-stream/index.js new file mode 100644 index 0000000..c35f695 --- /dev/null +++ b/node_modules/into-stream/index.js @@ -0,0 +1,79 @@ +'use strict'; +const from = require('from2'); +const pIsPromise = require('p-is-promise'); + +module.exports = x => { + if (Array.isArray(x)) { + x = x.slice(); + } + + let promise; + let iterator; + + prepare(x); + + function prepare(value) { + x = value; + promise = pIsPromise(x) ? x : null; + // we don't iterate on strings and buffers since slicing them is ~7x faster + const shouldIterate = !promise && x[Symbol.iterator] && typeof x !== 'string' && !Buffer.isBuffer(x); + iterator = shouldIterate ? x[Symbol.iterator]() : null; + } + + return from(function reader(size, cb) { + if (promise) { + promise.then(prepare).then(() => reader.call(this, size, cb), cb); + return; + } + + if (iterator) { + const obj = iterator.next(); + setImmediate(cb, null, obj.done ? null : obj.value); + return; + } + + if (x.length === 0) { + setImmediate(cb, null, null); + return; + } + + const chunk = x.slice(0, size); + x = x.slice(size); + + setImmediate(cb, null, chunk); + }); +}; + +module.exports.obj = x => { + if (Array.isArray(x)) { + x = x.slice(); + } + + let promise; + let iterator; + + prepare(x); + + function prepare(value) { + x = value; + promise = pIsPromise(x) ? x : null; + iterator = !promise && x[Symbol.iterator] ? x[Symbol.iterator]() : null; + } + + return from.obj(function reader(size, cb) { + if (promise) { + promise.then(prepare).then(() => reader.call(this, size, cb), cb); + return; + } + + if (iterator) { + const obj = iterator.next(); + setImmediate(cb, null, obj.done ? null : obj.value); + return; + } + + this.push(x); + + setImmediate(cb, null, null); + }); +}; diff --git a/node_modules/into-stream/license b/node_modules/into-stream/license new file mode 100644 index 0000000..654d0bf --- /dev/null +++ b/node_modules/into-stream/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/into-stream/package.json b/node_modules/into-stream/package.json new file mode 100644 index 0000000..e0241c9 --- /dev/null +++ b/node_modules/into-stream/package.json @@ -0,0 +1,50 @@ +{ + "name": "into-stream", + "version": "3.1.0", + "description": "Convert a buffer/string/array/object/iterable/promise into a stream", + "license": "MIT", + "repository": "sindresorhus/into-stream", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "index.js" + ], + "keywords": [ + "stream", + "buffer", + "string", + "object", + "array", + "iterable", + "promise", + "promises", + "from", + "into", + "to", + "transform", + "convert", + "readable", + "pull", + "gulpfriendly", + "value", + "str" + ], + "dependencies": { + "from2": "^2.1.1", + "p-is-promise": "^1.1.0" + }, + "devDependencies": { + "ava": "*", + "get-stream": "^3.0.0", + "xo": "*" + } +} diff --git a/node_modules/into-stream/readme.md b/node_modules/into-stream/readme.md new file mode 100644 index 0000000..6c4ed0b --- /dev/null +++ b/node_modules/into-stream/readme.md @@ -0,0 +1,42 @@ +# into-stream [![Build Status](https://travis-ci.org/sindresorhus/into-stream.svg?branch=master)](https://travis-ci.org/sindresorhus/into-stream) + +> Convert a buffer/string/array/object/iterable/promise into a stream + +Correctly chunks up the input and handles backpressure. + + +## Install + +``` +$ npm install --save into-stream +``` + + +## Usage + +```js +const intoStream = require('into-stream'); + +intoStream('unicorn').pipe(process.stdout); +//=> 'unicorn' +``` + + +## API + +### intoStream(input) + +Type: `Buffer` `string` `Iterable<Buffer|string>` `Promise`<br> +Returns: [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) + +Adheres to the requested chunk size, except for `array` where each element will be a chunk. + +### intoStream.obj(input) + +Type: `Object`, `Iterable<Object>` `Promise`<br> +Returns: [Readable object stream](https://nodejs.org/api/stream.html#stream_object_mode) + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) |