Adds the ability to traverse an array with file stream like abilities such as seek, read, tell.
import {ArrayStreamT} from 'array-stream-traversal';
const exampleArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
try {
const ast = ArrayStreamT.load(exampleArray);
const res = ast.read(4); // res = [0, 1, 2, 3]
ast.seek(1); // pointer should be at idx 1
const res2 = ast.read(1); // [1] and move pointer to idx 2
ast.seek(2, ArrayStreamT.SeekPos.CURR); // Seeks from current position, so it adds on instead of resettting to beginning
console.log(ast.tell()); // 4
console.log(ast.read()); // 5
}
catch(err) {
// do error things here
}
External ArrayStreamT object
- ArrayStreamT
- ~SeekPos ⇒
object - ~InvalidLengthException(message) ⇒
Error - ~InvalidPositionException(message) ⇒
Error - ~load(data, makeCopy:, position:, whence:) ⇒
object- ~read(len:) ⇒
array - ~seek(offset:, whence:) ⇒
this - ~tell() ⇒
integer
- ~read(len:) ⇒
- ~SeekPos ⇒
Seek whence constant SET: Starts seek from beginning of array CURR: Seek from current position
Kind: inner enum of ArrayStreamT
Properties
| Name | Type | Default |
|---|---|---|
| SET | integer |
0 |
| CURR | integer |
1 |
Returns custom invalid length exception
Kind: inner method of ArrayStreamT
| Param | Type | Description |
|---|---|---|
| message | string |
exception message |
Returns custom invalid position exception
Kind: inner method of ArrayStreamT
| Param | Type | Description |
|---|---|---|
| message | string |
exception message |
ArrayStreamT Object
Kind: inner method of ArrayStreamT
Returns: object - returns array, read/seek/tell methods
| Param | Type | Description |
|---|---|---|
| data | Array |
|
| makeCopy: | boolean |
Copies the array (recommended), default true |
| position: | integer |
Starting position, default 0 |
| whence: | integer |
Where to start seeking from, default SeekPos.SET |
Read x amount of bytes/items
Kind: inner method of ArrayStreamT
| Param | Type | Description |
|---|---|---|
| len: | integer |
-1 reads til eof, has to be 0+ |
Sets the current position
Kind: inner method of ArrayStreamT
| Param | Type | Description |
|---|---|---|
| offset: | integer |
position |
| whence: | integer |
where to start seeking (start, current) |
Returns current position of the pointer
Kind: inner method of ArrayStreamT