Global

Methods

read(stream, sizeopt, optionsopt) → {Promise.<(Buffer|string|*)>|CancellableReadPromise.<(Buffer|string|*)>}

Reads from a stream.Readable.
Parameters:
Name Type Attributes Description
stream stream.Readable Stream from which to read.
size number <optional>
Number of bytes to read. If stream.read is a function, size is passed to it, guaranteeing maximum result size. Otherwise, 'data' events will be consumed until size bytes are read, making it a minimum rather than an exact value.
options ReadOptions <optional>
Options.
Source:
Returns:
Promise with result of read or Error. Result may be shorter than size if 'end' occurs and will be null if no data can be read. If an error occurs after reading some data, the .read property of the error object will contain the partial read result. The promise is resolved synchronously for streams in flowing mode (see README.md for details).
Type
Promise.<(Buffer|string|*)> | CancellableReadPromise.<(Buffer|string|*)>

readTo(stream, needle, optionsopt) → {Promise.<(Buffer|string|Array)>|CancellableReadPromise.<(Buffer|string|Array)>}

Reads from a stream.Readable until a given value is found.

This function calls readUntil with an until function which uses .indexOf to search for needle. When reading Buffers and performance is paramount, consider using readUntil directly with an optional function for the problem (e.g. buffer-indexof-fast for single-character search).

Doc note: options should be a ReadToOptions type which extends ReadOptions, but record types can't currently be extended. See https://github.com/google/closure-compiler/issues/604.

Parameters:
Name Type Attributes Description
stream stream.Readable Stream from which to read.
needle Buffer | string | * Value to search for in the read result. The stream will be read until this value is found or 'end' or 'error' is emitted.
options ReadOptions <optional>
Options. This function additionally supports an endOK option which prevents EOFError on 'end'.
Source:
Returns:
Promise with the data read, up to and including needle, or an Error if one occurs. If stream does not support unshift, the result may include additional data. If 'end' is emitted before needle is found, an EOFError is returned, unless options.endOK is truthy in which case any remaining data is returned or null if none was read. If an error occurs after reading some data, the .read property of the error object will contain the partial read result. The promise is resolved synchronously for streams in flowing mode (see README.md for details).
Type
Promise.<(Buffer|string|Array)> | CancellableReadPromise.<(Buffer|string|Array)>

readToEnd(stream, optionsopt) → {Promise.<(!Buffer|string|!Array)>|CancellableReadPromise.<(!Buffer|string|!Array)>}

Reads from a stream.Readable until 'end' is emitted.
Parameters:
Name Type Attributes Description
stream stream.Readable Stream from which to read.
options ReadOptions <optional>
Options.
Source:
Returns:
Promise with the data read, null if no data was read, or an Error if one occurred. If an error occurs after reading some data, the .read property of the error object will contain the partial read result. The promise is resolved synchronously for streams in flowing mode (see README.md for details).
Type
Promise.<(!Buffer|string|!Array)> | CancellableReadPromise.<(!Buffer|string|!Array)>

readToMatch(stream, regexp, optionsopt) → {Promise.<string>|CancellableReadPromise.<string>}

Reads from a stream.Readable until a given expression is matched.

This function calls readUntil with an until function which applies regexp to the data read.

Doc note: options should be a ReadToMatchOptions type which extends ReadToOptions, but record types can't currently be extended. See https://github.com/google/closure-compiler/issues/604.

Parameters:
Name Type Attributes Description
stream stream.Readable.<string> Stream from which to read. This stream must produce strings (so call .setEncoding if necessary).
regexp RegExp | string Expression to find in the read result. The stream will be read until this value is matched or 'end' or 'error' is emitted.
options ReadOptions <optional>
Options. This function additionally supports an endOK option which prevents EOFError on 'end' and a maxMatchLen option which specifies the maximum length of a match, which allow additional search optimizations.
Source:
Returns:
Promise with the data read, up to and including the data matched by regexp, or an Error if one occurs. If stream does not support unshift, the result may include additional data. If 'end' is emitted before regexp is matched, an EOFError is returned, unless options.endOK is truthy in which case any remaining data is returned or null if none was read. If an error occurs after reading some data, the .read property of the error object will contain the partial read result. The promise is resolved synchronously for streams in flowing mode (see README.md for details).
Type
Promise.<string> | CancellableReadPromise.<string>

readUntil(stream, test, optionsopt) → {Promise.<(!Buffer|string|!Array)>|CancellableReadPromise.<(!Buffer|string|!Array)>}

Reads from a stream.Readable until a given test is satisfied.
Parameters:
Name Type Attributes Description
stream stream.Readable Stream from which to read.
test function Test function called with the data read so far and the most recent chunk read. If it returns a negative or falsey value, more data will be read. If it returns a non-negative number and the stream can be unshifted, that many bytes will be returned and the others will be unshifted into the stream. Otherwise, all data read will be returned. If it returns a number larger than the length of the data read so far, enough data to reach the requested length will be read before returning. Non-numeric, non-boolean values will result in an error.
options ReadOptions <optional>
Options.
Source:
Returns:
Promise with the data read and not unshifted, or an Error if one occurred. If 'end' is emitted before until returns a non-negative/true value, an EOFError is returned. If an error occurs after reading some data, the .read property of the error object will contain the partial read result. The promise is resolved synchronously for streams in flowing mode (see README.md for details).
Type
Promise.<(!Buffer|string|!Array)> | CancellableReadPromise.<(!Buffer|string|!Array)>