Skip to content

Latest commit

 

History

History
174 lines (127 loc) · 6.68 KB

buffer-stream.md

File metadata and controls

174 lines (127 loc) · 6.68 KB

ScramjetCore

ScramjetCore~BufferStream ⇐ DataStream

A factilitation stream created for easy splitting or parsing buffers

Kind: inner class of ScramjetCore
Extends: DataStream

new BufferStream(opts)

Creates the BufferStream

Param Type Description
opts object Stream options passed to superclass

Example

[../samples/buffer-stream-constructor.js](../samples/buffer-stream-constructor.js)

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
Returns: BufferStream - substream

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

Example

[../samples/string-stream-shift.js](../samples/string-stream-shift.js)

bufferStream.split(splitter) ⇒ BufferStream

Splits the buffer stream into buffer objects

Kind: instance method of BufferStream
Returns: BufferStream - the re-splitted buffer stream.
Todo

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

Example

[../samples/buffer-stream-split.js](../samples/buffer-stream-split.js)

bufferStream.breakup(number) ⇒ BufferStream

Breaks up a stream apart into chunks of the specified length

Kind: instance method of BufferStream
Returns: BufferStream - the resulting buffer stream.

Param Type Description
number Number the desired chunk length

Example

[../samples/buffer-stream-breakup.js](../samples/buffer-stream-breakup.js)

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
Returns: StringStream - The converted stream.

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

Example

[../samples/buffer-stream-tostringstream.js](../samples/buffer-stream-tostringstream.js)

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 splitted or broken up.

Kind: instance method of BufferStream
Returns: DataStream - The parsed objects stream.

Param Type Description
parser ParseCallback The transform function

Example

[../samples/buffer-stream-parse.js](../samples/buffer-stream-parse.js)

ScramjetCore~toStringStream()

Alias for BufferStream#stringify

Kind: inner method of ScramjetCore

ScramjetCore~toDataStream()

Alias for BufferStream#parse

Kind: inner method of ScramjetCore

ScramjetCore~PopCallback : function

Pop callback

Kind: inner typedef of ScramjetCore

Param Type Description
popped Buffer popped bytes

ScramjetCore~ParseCallback ⇒ Promise

Kind: inner typedef of ScramjetCore
Returns: Promise - the promise should be resolved with the parsed object

Param Type Description
chunk Buffer the transformed chunk