Constructor
new ReadableStreamWrapper()
Construct a wrapper do not use directly, use createReadableStream() instead.
Classes
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.
(static) DEFAULT_BACK_OFFSET
The default backwards buffer offset
(static) DEFAULT_BUFFERS
The default buffer count
(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
(static) MAX_BUFFERS
The maximum allowed buffer count
Methods
(async) cancel(reasonopt)
Cancel the stream
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
reason |
any |
<optional> |
The reason |
(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 |
Returns:
The bytes read
- Type
- Promise.<number>
getBackOffset() → {number}
Get the back offset
Returns:
The back offset
- Type
- number
getBufferCount() → {number}
Get the buffer count
Returns:
The buffer count
- Type
- number
getBufferSize() → {number}
Get the buffer size
Returns:
The buffer size
- Type
- number
getPositionStart() → {number}
Get the start position of the stream
Returns:
The start position of the stream
- Type
- number
getStream() → {RandomAccessStream}
Get the source stream
Returns:
The source stream
- Type
- RandomAccessStream
getTotalSize()
Get the total size of the stream
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 |
Returns:
The bytes read
- Type
- Promise.<number>
reset()
Reset the stream
setAlignSize(alignSize)
Set the align size
Parameters:
Name | Type | Description |
---|---|---|
alignSize |
number | The align size |
setBackOffset(backOffset)
Set the back offset
Parameters:
Name | Type | Description |
---|---|---|
backOffset |
The back offset |
setBufferCount(buffersCount)
Set the buffer count
Parameters:
Name | Type | Description |
---|---|---|
buffersCount |
number | The buffer count |
setBufferSize(bufferSize)
Set the buffer size
Parameters:
Name | Type | Description |
---|---|---|
bufferSize |
number | The buffer size |
(async) setPositionEnd(pos)
Set the end position of the stream
Parameters:
Name | Type | Description |
---|---|---|
pos |
number | The end position of the stream |
(async) setPositionStart(pos)
Set the start position of the stream.
Parameters:
Name | Type | Description |
---|---|---|
pos |
number | The start position |
setStream(stream)
Set the source stream
Parameters:
Name | Type | Description |
---|---|---|
stream |
RandomAccessStream | The stream |
setTotalSize(totalSize)
Set the total size of the stream
Parameters:
Name | Type | Description |
---|---|---|
totalSize |
number | The total size of the stream |
(async) skip(bytes) → {Promise.<number>}
Skip a number of bytes.
Parameters:
Name | Type | Description |
---|---|---|
bytes |
number | the number of bytes to be skipped. |
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. |