Skip to main content

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

new StringStream([encoding], [options])

Constructs the stream with the given encoding

Returns: StringStream - the created data stream

ParamTypeDefaultDescription
[encoding]string""utf-8""the encoding to use
[options]DataStreamOptionsthe 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

ParamTypeDescription
bytesnumberThe number of characters to shift.
funcShiftStringCallbackFunction 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

ParamTypeDescription
splitterRegExp | stringWhat 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

ParamTypeDescription
matcherRegExpA 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

ParamTypeDescription
parserParseCallbackThe transform function
[StreamClass]functionthe 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

ParamTypeDefaultDescription
[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

ParamTypeDefaultDescription
[perLine]Booleantrueinstructs 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

ParamTypeDefaultDescription
[options]objectoptions 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

ParamTypeDescription
paramThenFunction | stringthe 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

ParamTypeDescription
paramThenFunction | stringthe 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

ParamTypeDefaultDescription
commandstringcommand to execute
[options]ExecOptions | anyoptions to be passed to spawn and defining serialization.
...argsArray.<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.

ParamTypeDescription
streamstringthe string to push the your stream
encodingstringoptional 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

ParamTypeDescription
readableArray | Iterable.<any> | AsyncGeneratorFunction | GeneratorFunction | AsyncFunction | function | string | Readablethe initial readable argument that is streamable by scramjet.from
transformsAsyncFunction | function | TransformTransform 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
ParamTypeDefaultDescription
sourcestring | Array | Iterable.<any> | AsyncGeneratorFunction | GeneratorFunction | AsyncFunction | function | Readableargument to be turned into new stream
[options]DataStreamOptions | Writable

Was it helpful?

Didn't find information needed?

Join our Scramjet Community on Discord, where you can get help from our engineers directly.