Fast, asynchronous, functional reactive stream programming framework with multi‑threading capability based on ES6+.

Master Build StatusMaster Build StatusDependenciesDev DependenciesKnown VulnerabilitiesDeepScan grade
Classes
  • DataStream : stream.PassThrough

  • BufferStream : DataStream

    A facilitation stream created for easy splitting or parsing buffers.

    Useful for working on built-in Node.js streams from files, parsing binary formats etc.

    A simple use case would be:

     fs.createReadStream('pixels.rgba')
         .pipe(new BufferStream)         // pipe a buffer stream into scramjet
         .breakup(4)                     // split into 4 byte fragments
         .parse(buffer => [
             buffer.readInt8(0),            // the output is a stream of R,G,B and Alpha
             buffer.readInt8(1),            // values from 0-255 in an array.
             buffer.readInt8(2),
             buffer.readInt8(3)
         ]);

    Kind: global class
    Extends: DataStream

    new BufferStream(opts)

    Creates the BufferStream

    Param Type Description
    opts DataStreamOptions Stream options passed to superclass

    bufferStream.shift(chars, func) : BufferStream ↺

    Shift given number of bytes from the original stream

    Works the same way as {@see DataStream.shift}, but in this case extracts the given number of bytes.

    Kind: instance method of BufferStream
    Chainable
    Overrides: shift
    Returns: BufferStream - sub-stream
    Test: test/methods/string-stream-shift.js

    Param Type Description
    chars Number The number of bytes to shift
    func ShiftCallback Function that receives a string of shifted bytes

    bufferStream.split(splitter) : BufferStream ↺

    Splits the buffer stream into buffer objects

    Kind: instance method of BufferStream
    Chainable
    Returns: BufferStream - the re-split buffer stream.
    Test: test/methods/buffer-stream-split.js

    Param Type Description
    splitter String | Buffer the buffer or string that the stream should be split by.

    bufferStream.breakup(number) : BufferStream ↺

    Breaks up a stream apart into chunks of the specified length

    Kind: instance method of BufferStream
    Chainable
    Returns: BufferStream - the resulting buffer stream.
    Test: test/methods/buffer-stream-breakup.js

    Param Type Description
    number Number the desired chunk length

    bufferStream.stringify(encoding) : StringStream

    Creates a string stream from the given buffer 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 BufferStream
    Overrides: stringify
    Returns: StringStream - The converted stream.
    Test: test/methods/buffer-stream-tostringstream.js

    Param Type Description
    encoding String The encoding to be used to convert the buffers to streams.

    bufferStream.parse(parser) : DataStream

    Parses every buffer to object

    The method MUST parse EVERY buffer into a single object, so the buffer stream here should already be split or broken up.

    Kind: instance method of BufferStream
    Returns: DataStream - The parsed objects stream.
    Test: test/methods/buffer-stream-parse.js

    Param Type Description
    parser ParseCallback The transform function

    bufferStream.toStringStream(encoding) : StringStream

    Creates a string stream from the given buffer 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 BufferStream
    Overrides: stringify
    Returns: StringStream - The converted stream.
    Test: test/methods/buffer-stream-tostringstream.js

    Param Type Description
    encoding String The encoding to be used to convert the buffers to streams.

    bufferStream.pop(chars, func) : BufferStream ↺

    Shift given number of bytes from the original stream

    Works the same way as {@see DataStream.shift}, but in this case extracts the given number of bytes.

    Kind: instance method of BufferStream
    Chainable
    Overrides: shift
    Returns: BufferStream - sub-stream
    Test: test/methods/string-stream-shift.js

    Param Type Description
    chars Number The number of bytes to shift
    func ShiftCallback Function that receives a string of shifted bytes

    bufferStream.toDataStream(parser) : DataStream

    Parses every buffer to object

    The method MUST parse EVERY buffer into a single object, so the buffer stream here should already be split or broken up.

    Kind: instance method of BufferStream
    Returns: DataStream - The parsed objects stream.
    Test: test/methods/buffer-stream-parse.js

    Param Type Description
    parser ParseCallback The transform function

    BufferStream:pipeline(readable, transforms) : BufferStream

    Creates a pipeline of streams and returns a scramjet stream.

    Kind: static method of BufferStream
    Returns: BufferStream - a new StringStream instance of the resulting pipeline
    See: DataStream.pipeline

    Param Type Description
    readable Array | Iterable | 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)

    BufferStream:from(stream, options) : BufferStream

    Create BufferStream from anything.

    Kind: static method of BufferStream
    Returns: BufferStream - new StringStream.
    See: module:scramjet.from

    Param Type Description
    stream Array | Iterable | AsyncGeneratorFunction | GeneratorFunction | AsyncFunction | function | Readable argument to be turned into new stream
    options DataStreamOptions | Writable

    BufferStream:ShiftCallback : function

    Shift Function

    Kind: static typedef of BufferStream

    Param Type Description
    shifted Buffer shifted bytes

    BufferStream:ParseCallback : Promise

    Kind: static typedef of BufferStream
    Returns: Promise - the promise should be resolved with the parsed object

    Param Type Description
    chunk Buffer the transformed chunk