Class: ReadableStreamWrapper

ReadableStreamWrapper()

ReadableStream wrapper for RandomAccessStream. Use this class to wrap any RandomAccessStream to a JavaScript ReadableStream to use with 3rd party libraries.

Constructor

new ReadableStreamWrapper()

Construct a wrapper do not use directly, use createReadableStream() instead.
Source:

Classes

ReadableStreamWrapper

Members

lruBuffersIndex

We reuse the least recently used buffer. Since the buffer count is relative small there is no need for a fast-access lru queue so a simple linked list of keeping the indexes is adequately fast.
Source:

(static) DEFAULT_BACK_OFFSET

The default backwards buffer offset
Source:

(static) DEFAULT_BUFFERS

The default buffer count
Source:

(static) DEFAULT_BUFFER_SIZE

Default cache buffer should be high enough for some mpeg videos to work the cache buffers should be aligned to the SalmonFile chunk size for efficiency
Source:

(static) MAX_BUFFERS

The maximum allowed buffer count
Source:

Methods

(async) cancel(reasonopt)

Cancel the stream
Parameters:
Name Type Attributes Description
reason any <optional>
The reason
Source:

(async) fillBuffer(cacheBuffer, startPosition, length) → {Promise.<number>}

Fills a cache buffer with the decrypted data from the encrypted source file.
Parameters:
Name Type Description
cacheBuffer Buffer The cache buffer that will store the decrypted contents
startPosition number The start position
length number The length of the data requested
Source:
Returns:
The bytes read
Type
Promise.<number>

getBackOffset() → {number}

Get the back offset
Source:
Returns:
The back offset
Type
number

getBufferCount() → {number}

Get the buffer count
Source:
Returns:
The buffer count
Type
number

getBufferSize() → {number}

Get the buffer size
Source:
Returns:
The buffer size
Type
number

getPositionStart() → {number}

Get the start position of the stream
Source:
Returns:
The start position of the stream
Type
number

getStream() → {RandomAccessStream}

Get the source stream
Source:
Returns:
The source stream
Type
RandomAccessStream

getTotalSize()

Get the total size of the stream
Source:
Returns:
The total size

(async) read(buffer, offset, count) → {Promise.<number>}

Reads and decrypts the contents of an encrypted file
Parameters:
Name Type Description
buffer Uint8Array The buffer
offset number The offset
count number The count
Source:
Returns:
The bytes read
Type
Promise.<number>

reset()

Reset the stream
Source:

setAlignSize(alignSize)

Set the align size
Parameters:
Name Type Description
alignSize number The align size
Source:

setBackOffset(backOffset)

Set the back offset
Parameters:
Name Type Description
backOffset The back offset
Source:

setBufferCount(buffersCount)

Set the buffer count
Parameters:
Name Type Description
buffersCount number The buffer count
Source:

setBufferSize(bufferSize)

Set the buffer size
Parameters:
Name Type Description
bufferSize number The buffer size
Source:

(async) setPositionEnd(pos)

Set the end position of the stream
Parameters:
Name Type Description
pos number The end position of the stream
Source:

(async) setPositionStart(pos)

Set the start position of the stream.
Parameters:
Name Type Description
pos number The start position
Source:

setStream(stream)

Set the source stream
Parameters:
Name Type Description
stream RandomAccessStream The stream
Source:

setTotalSize(totalSize)

Set the total size of the stream
Parameters:
Name Type Description
totalSize number The total size of the stream
Source:

(async) skip(bytes) → {Promise.<number>}

Skip a number of bytes.
Parameters:
Name Type Description
bytes number the number of bytes to be skipped.
Source:
Returns:
The new position
Type
Promise.<number>

(static) createReadableStream(stream, buffersCount, bufferSize, backOffset, alignSize)

Creates a native ReadableStream from a RandomAccessStream
Parameters:
Name Type Default Description
stream RandomAccessStream The source stream.
buffersCount number 1 Number of buffers to use.
bufferSize Uint8Array 524288 The length of each buffer.
backOffset number 32768 The backwards offset. Some media libraries might request data rewinding the stream just a few bytes backwards. This ensures those bytes are included so we don't reset the stream.
alignSize number 0 The align size. Set to a positive number to override the stream aligned size.
Source: