StringStream
:StringStream : DataStream
A stream of string objects for further transformation on top of DataStream.
Example:
StringStream.from(async () =>
(await fetch("https://example.com/data/article.txt")).text()
)
.lines()
.append("\r\n")
.pipe(fs.createWriteStream("./path/to/file.txt"));
Kind: static class
Extends: DataStream
Scope: public
- :StringStream
DataStream
- new StringStream([encoding], [options])
- stringStream.shift(bytes, func) ↺
- stringStream.split(splitter) ↺
- stringStream.match(matcher) ↺
- stringStream.toBufferStream() ↺
BufferStream
- stringStream.parse(parser, [StreamClass]) ↺
DataStream
- stringStream.toDataStream()
- stringStream.lines([eol]) ↺
- stringStream.JSONParse([perLine]) ↺
DataStream
- stringStream.CSVParse([options]) ↺
DataStream
- stringStream.append(param) ↺
- stringStream.prepend(param) ↺
- stringStream.exec(command, [options])
- StringStream:SPLIT_LINE
- StringStream:fromString(stream, encoding)
StringStream
- StringStream:pipeline(readable, transforms)
StringStream
- StringStream:from(source, [options])
StringStream
new StringStream([encoding], [options])
Constructs the stream with the given encoding
Returns: StringStream
- the created data stream
Param | Type | Default | Description |
---|---|---|---|
[encoding] | string | ""utf-8"" | the encoding to use |
[options] | DataStreamOptions |
| the encoding to use |
stringStream.shift(bytes, func) ↺
Shifts given length of chars from the original stream
Works the same way as @see DataStream.shift, but in this case extracts the given number of characters.
Kind: instance method of StringStream
Chainable
Test: test/methods/string-stream-shift.js
Param | Type | Description |
---|---|---|
bytes | number | The number of characters to shift. |
func | ShiftStringCallback | Function that receives a string of shifted chars. |
stringStream.split(splitter) ↺
Splits the string stream by the specified RegExp or string
Kind: instance method of StringStream
Chainable
Test: test/methods/string-stream-split.js
Param | Type | Description |
---|---|---|
splitter | RegExp | string | What to split by |
stringStream.match(matcher) ↺
Finds matches in the string stream and streams the match results
Kind: instance method of StringStream
Chainable
Test: test/methods/string-stream-match.js
Param | Type | Description |
---|---|---|
matcher | RegExp | A function that will be called for every stream chunk. |
stringStream.toBufferStream() : BufferStream ↺
Transforms the StringStream to BufferStream
Creates a buffer stream from the given string stream. Still it returns a DataStream derivative and isn't the typical node.js stream so you can do all your transforms when you like.
Kind: instance method of StringStream
Chainable
Returns: BufferStream
- The converted stream.
Meta.noreadme:
Test: test/methods/string-stream-tobufferstream.js
stringStream.parse(parser, [StreamClass]) : DataStream ↺
Parses every string to object
The method MUST parse EVERY string into a single object, so the string stream here should already be split.
Kind: instance method of StringStream
Chainable
Returns: DataStream
- The parsed objects stream.
Test: test/methods/string-stream-parse.js
Param | Type | Description |
---|---|---|
parser | ParseCallback | The transform function |
[StreamClass] | function | the output stream class to return |
stringStream.toDataStream()
Alias for StringStream.parse
Kind: instance method of StringStream
stringStream.lines([eol]) ↺
Splits the string stream by the specified regexp or string
Kind: instance method of StringStream
Chainable
Test: test/methods/string-stream-split.js
Param | Type | Default | Description |
---|---|---|---|
[eol] | string | RegExp | "/\r?\n/" | End of line string or regex |
stringStream.JSONParse([perLine]) : DataStream ↺
Parses each entry as JSON. Ignores empty lines
Kind: instance method of StringStream
Chainable
Returns: DataStream
- stream of parsed items
Param | Type | Default | Description |
---|---|---|---|
[perLine] | Boolean | true | instructs to split per line |
stringStream.CSVParse([options]) : DataStream ↺
Parses CSV to DataString using 'papaparse' module.
Kind: instance method of StringStream
Chainable
Returns: DataStream
- stream of parsed items
Test: test/methods/data-stream-separate.js
Param | Type | Default | Description |
---|---|---|---|
[options] | object |
| options for the papaparse.parse method. |
stringStream.append(param) ↺
Appends given argument to all the items.
Kind: instance method of StringStream
Chainable
Test: test/methods/string-stream-append.js
Param | Type | Description |
---|---|---|
param | ThenFunction | string | the argument to append. If function passed then it will be called and resolved and the resolution will be appended. |
stringStream.prepend(param) ↺
Prepends given argument to all the items.
Kind: instance method of StringStream
Chainable
Test: test/methods/string-stream-prepend.js
Param | Type | Description |
---|---|---|
param | ThenFunction | string | the argument to prepend. If function passed then it will be called and resolved and the resolution will be prepended. |
stringStream.exec(command, [options])
Executes a given sub-process with arguments and pipes the current stream into it while returning the output as another DataStream.
Pipes the current stream into the sub-processes stdin. The data is serialized and deserialized as JSON lines by default. You can provide your own alternative methods in the ExecOptions object.
Note: if you're piping both stderr and stdout (options.stream=3) keep in mind that chunks may get mixed up!
Kind: instance method of StringStream
Test: test/methods/string-stream-exec.js
Param | Type | Default | Description |
---|---|---|---|
command | string | command to execute | |
[options] | ExecOptions | any |
| options to be passed to spawn and defining serialization. |
...args | Array.<string> | additional arguments (will overwrite to SpawnOptions args even if not given) |
StringStream:SPLIT_LINE
A handy split by line regex to quickly get a line-by-line stream
Kind: static property of StringStream
StringStream:fromString(stream, encoding) : StringStream
Creates a StringStream and writes a specific string.
Kind: static method of StringStream
Returns: StringStream
- new StringStream.
Param | Type | Description |
---|---|---|
stream | string | the string to push the your stream |
encoding | string | optional encoding |
StringStream:pipeline(readable, transforms) : StringStream
Creates a pipeline of streams and returns a scramjet stream.
Kind: static method of StringStream
Returns: StringStream
- a new StringStream instance of the resulting pipeline
See: DataStream.pipeline
Param | Type | Description |
---|---|---|
readable | Array | Iterable.<any> | AsyncGeneratorFunction | GeneratorFunction | AsyncFunction | function | string | Readable | the initial readable argument that is streamable by scramjet.from |
transforms | AsyncFunction | function | Transform | Transform functions (as in DataStream..use) or Transform streams (any number of these as consecutive arguments) |
StringStream:from(source, [options]) : StringStream
Create StringStream from anything.
Kind: static method of StringStream
Returns: StringStream
- new StringStream.
See
- DataStream.from
- module:scramjet.from
Param | Type | Default | Description |
---|---|---|---|
source | string | Array | Iterable.<any> | AsyncGeneratorFunction | GeneratorFunction | AsyncFunction | function | Readable | argument to be turned into new stream | |
[options] | DataStreamOptions | Writable |
|