into-stream
Advanced tools
Comparing version 3.1.0 to 4.0.0
49
index.js
@@ -5,5 +5,5 @@ 'use strict'; | ||
module.exports = x => { | ||
if (Array.isArray(x)) { | ||
x = x.slice(); | ||
module.exports = input => { | ||
if (Array.isArray(input)) { | ||
input = input.slice(); | ||
} | ||
@@ -14,10 +14,19 @@ | ||
prepare(x); | ||
prepare(input); | ||
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; | ||
input = value; | ||
if ( | ||
input instanceof ArrayBuffer || | ||
(ArrayBuffer.isView(input) && !Buffer.isBuffer(input)) | ||
) { | ||
input = Buffer.from(input); | ||
} | ||
promise = pIsPromise(input) ? input : null; | ||
// We don't iterate on strings and buffers since slicing them is ~7x faster | ||
const shouldIterate = !promise && input[Symbol.iterator] && typeof input !== 'string' && !Buffer.isBuffer(input); | ||
iterator = shouldIterate ? input[Symbol.iterator]() : null; | ||
} | ||
@@ -37,3 +46,3 @@ | ||
if (x.length === 0) { | ||
if (input.length === 0) { | ||
setImmediate(cb, null, null); | ||
@@ -43,4 +52,4 @@ return; | ||
const chunk = x.slice(0, size); | ||
x = x.slice(size); | ||
const chunk = input.slice(0, size); | ||
input = input.slice(size); | ||
@@ -51,5 +60,5 @@ setImmediate(cb, null, chunk); | ||
module.exports.obj = x => { | ||
if (Array.isArray(x)) { | ||
x = x.slice(); | ||
module.exports.obj = input => { | ||
if (Array.isArray(input)) { | ||
input = input.slice(); | ||
} | ||
@@ -60,8 +69,8 @@ | ||
prepare(x); | ||
prepare(input); | ||
function prepare(value) { | ||
x = value; | ||
promise = pIsPromise(x) ? x : null; | ||
iterator = !promise && x[Symbol.iterator] ? x[Symbol.iterator]() : null; | ||
input = value; | ||
promise = pIsPromise(input) ? input : null; | ||
iterator = !promise && input[Symbol.iterator] ? input[Symbol.iterator]() : null; | ||
} | ||
@@ -81,3 +90,3 @@ | ||
this.push(x); | ||
this.push(input); | ||
@@ -84,0 +93,0 @@ setImmediate(cb, null, null); |
{ | ||
"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": "*" | ||
} | ||
"name": "into-stream", | ||
"version": "4.0.0", | ||
"description": "Convert a string/promise/array/iterable/buffer/typedarray/arraybuffer/object into a stream", | ||
"license": "MIT", | ||
"repository": "sindresorhus/into-stream", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"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": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"get-stream": "^4.1.0", | ||
"p-event": "^2.1.0", | ||
"xo": "^0.23.0" | ||
} | ||
} |
# 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 | ||
> Convert a string/promise/array/iterable/buffer/typedarray/arraybuffer/object into a stream | ||
@@ -11,3 +11,3 @@ Correctly chunks up the input and handles backpressure. | ||
``` | ||
$ npm install --save into-stream | ||
$ npm install into-stream | ||
``` | ||
@@ -30,3 +30,3 @@ | ||
Type: `Buffer` `string` `Iterable<Buffer|string>` `Promise`<br> | ||
Type: `Buffer` `TypedArray` `ArrayBuffer` `string` `Iterable<Buffer|string>` `Promise`<br> | ||
Returns: [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) | ||
@@ -42,4 +42,9 @@ | ||
## Related | ||
- [to-readable-stream](https://github.com/sindresorhus/to-readable-stream) - Simpler version of this module | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4908
68
48
4
+ Addedp-is-promise@2.1.0(transitive)
- Removedp-is-promise@1.1.0(transitive)
Updatedp-is-promise@^2.0.0