stream-to-it
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "stream-to-it", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Convert Node.js streams to streaming iterables", | ||
"main": "src/index.js", | ||
"main": "index.js", | ||
"scripts": { | ||
@@ -26,7 +26,7 @@ "test": "ava test/*.test.js --verbose", | ||
"ava": "^2.2.0", | ||
"bl": "^3.0.0", | ||
"bl": "^4.0.0", | ||
"it-pipe": "^1.0.1", | ||
"nyc": "^14.1.1", | ||
"p-fifo": "^1.0.0", | ||
"standard": "^13.1.0", | ||
"standard": "^14.3.1", | ||
"streaming-iterables": "^4.1.0" | ||
@@ -33,0 +33,0 @@ }, |
@@ -33,2 +33,12 @@ # stream-to-it | ||
Also works with browser [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream): | ||
```js | ||
const res = fetch('http://example.org/file.jpg') | ||
for await (const chunk of toIterable.source(res.body)) { | ||
console.log(chunk.toString()) | ||
} | ||
``` | ||
### Convert writable stream to sink iterable | ||
@@ -35,0 +45,0 @@ |
@@ -22,1 +22,23 @@ const test = require('ava') | ||
}) | ||
test('should convert browser ReadableStream to source iterable', async t => { | ||
const input = Array.from(Array(randomInt(5, 10)), () => randomBytes(1, 512)) | ||
let i = 0 | ||
// Like a Response object you get from a call to fetch() in the browser | ||
const response = { | ||
body: { | ||
getReader () { | ||
return { | ||
read () { | ||
const value = input[i++] | ||
return value == null ? { done: true } : { value } | ||
}, | ||
releaseLock () {} | ||
} | ||
} | ||
} | ||
} | ||
const output = await collect(toIterable.source(response.body)) | ||
t.deepEqual(input, output) | ||
}) |
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
17808
14
425
111