Pausable linereader for node.js 12+ using streams3 API.

Emits line events (with string parameter containing line character data) on each line, then a single no-parameter end event.

Uses a supplied readable stream in (streams3-improved) flowing mode.

Takes advantage of streams3 guarantees wrt. readable.pause() (whereas in streams2/node < 12, readable.pause() is only advisory).

Starts in unpaused mode.

Note an alternative, or even preferred, approach for doing this on Node.js is to use a transform stream, with potential support for backpressure propagation. However, an experimental implementation turned out not portable across node versions, and requiring version-specific tweaks.

If a non-flowing linereader.js file (as opposed to this file, flowinglinereader.js) is part of the sgmljs.net package sources your received, it can be experimentally used in place of flowinglinereader.js by changing require('linereader') into require(flowinglinereader`) directives throughout all source files.

Constructor

new Linereader(instream)

Parameters

Name Type Description
instream stream.Readable

Streams3-conformant Readable, opened in character mode (with eg. UTF-8 encoding parameter)

Name Description
is_paused Returns whether pause() without subsequent resume() has been called.
pause Pauses emitting events.
push_text Prepends literal text before other text in buffer.
resume Resumes emitting events after pausing.

Member Details

is_paused()

Returns whether pause() without subsequent resume() has been called.

Note: untested for flowing linereader

pause()

Pauses emitting events.

push_text()

Prepends literal text before other text in buffer.

resume()

Resumes emitting events after pausing.