promise-readable
Advanced tools
Comparing version 0.4.1 to 0.4.2
# Changelog | ||
## v0.4.2 2017-03-16 | ||
* Minor tweaks for documentation. | ||
## v0.4.1 2017-03-14 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "promise-readable", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Return promise for readable stream", | ||
@@ -5,0 +5,0 @@ "main": "lib/promise-readable.js", |
@@ -28,33 +28,45 @@ ## promise-readable | ||
#### constructor(stream) | ||
#### constructor | ||
`PromiseReadable` object requires `Readable` object to work: | ||
```js | ||
const promiseReadable = new PromiseReadable(stream) | ||
``` | ||
`PromiseReadable` object requires `Readable` object to work. | ||
_Example:_ | ||
```js | ||
const PromiseReadable = require('promise-readable') | ||
const rstream = require('fs').createReadStream('/etc/hosts') | ||
const stream = require('fs').createReadStream('/etc/hosts') | ||
const promiseRstream = new PromiseReadable(rstream) | ||
const promiseReadable = new PromiseReadable(stream) | ||
``` | ||
Original stream is available with `stream` property: | ||
#### stream | ||
Original stream is available with `stream` property. | ||
_Example:_ | ||
```js | ||
console.log(promiseRstream.stream.flags) | ||
console.log(promiseReadable.stream.flags) | ||
``` | ||
#### read([chunkSize]) | ||
#### read | ||
```js | ||
const chunk = await promiseReadable.read([chunkSize]) | ||
``` | ||
This method returns `Promise` which is fulfilled when stream can return one | ||
chunk (by `read` method or `data` event) or stream is ended (`end` event). | ||
```js | ||
const chunk = await promiseRstream.read() | ||
``` | ||
If stream2 API is available then additional argument `size` is accepted. | ||
_Example:_ | ||
```js | ||
const chunk = await promiseRstream.read(1024) | ||
const chunk = await promiseReadable.read(1024) | ||
``` | ||
@@ -65,4 +77,6 @@ | ||
_Example:_ | ||
```js | ||
for (let chunk; (chunk = await promiseRstream.read()) !== null;) { | ||
for (let chunk; (chunk = await promiseReadable.read()) !== null;) { | ||
console.log(chunk.length) | ||
@@ -73,4 +87,8 @@ } | ||
#### readAll() | ||
#### readAll | ||
```js | ||
const content = await promiseReadable.readAll() | ||
``` | ||
This method returns `Promise` which is fulfilled when stream is ended. The | ||
@@ -80,19 +98,21 @@ content from the stream is buffered and then Promise returns this concatenated | ||
#### once | ||
```js | ||
const content = await promiseRstream.readAll() | ||
const result = await promiseReadable.once(event) | ||
``` | ||
#### once(event) | ||
This method returns `Promise` which is fulfilled when stream emits `event`. The | ||
result of this event is returned or `null` value if stream is already ended. | ||
_Example:_ | ||
```js | ||
const fd = await promiseRstream.once('open') | ||
promiseRstream.stream.pipe(process.stdout) | ||
const fd = await promiseReadable.once('open') | ||
promiseReadable.stream.pipe(process.stdout) | ||
await promiseRstream.once('close') | ||
await promiseReadable.once('close') | ||
promiseRstream.stream.on('data', chunk => console.log(chunk.length)) | ||
await promiseRstream.once('end') | ||
promiseReadable.stream.on('data', chunk => console.log(chunk.length)) | ||
await promiseReadable.once('end') | ||
``` | ||
@@ -99,0 +119,0 @@ |
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
28927
134