1.37.0 • Published 1 year ago

@zenenwjaimes/array-stream-traversal v1.37.0

Weekly downloads
1
License
GPL-3.0-or-later
Repository
github
Last release
1 year ago

array-stream-traversal

Adds the ability to traverse an array with file stream like abilities such as seek, read, tell.

Example Usage

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
} 

ArrayStreamT

External ArrayStreamT object

ArrayStreamT~SeekPos ⇒ object

Seek whence constant SET: Starts seek from beginning of array CURR: Seek from current position

Kind: inner enum of ArrayStreamT
Properties

NameTypeDefault
SETinteger0
CURRinteger1

ArrayStreamT~InvalidLengthException(message) ⇒ Error

Returns custom invalid length exception

Kind: inner method of ArrayStreamT

ParamTypeDescription
messagestringexception message

ArrayStreamT~InvalidPositionException(message) ⇒ Error

Returns custom invalid position exception

Kind: inner method of ArrayStreamT

ParamTypeDescription
messagestringexception message

ArrayStreamT~load(data, makeCopy:, position:, whence:) ⇒ object

ArrayStreamT Object

Kind: inner method of ArrayStreamT
Returns: object - returns array, read/seek/tell methods

ParamTypeDescription
dataArray
makeCopy:booleanCopies the array (recommended), default true
position:integerStarting position, default 0
whence:integerWhere to start seeking from, default SeekPos.SET

ArrayStreamT~read(len:) ⇒ array

Read x amount of bytes/items

Kind: inner method of ArrayStreamT

ParamTypeDescription
len:integer-1 reads til eof, has to be 0+

ArrayStreamT~seek(offset:, whence:) ⇒ this

Sets the current position

Kind: inner method of ArrayStreamT

ParamTypeDescription
offset:integerposition
whence:integerwhere to start seeking (start, current)

ArrayStreamT~tell() ⇒ integer

Returns current position of the pointer

Kind: inner method of ArrayStreamT

1.37.0

1 year ago

1.36.0

3 years ago

1.35.0

4 years ago

1.34.0

4 years ago

1.32.0

4 years ago

1.33.0

4 years ago

1.31.0

4 years ago

1.30.0

4 years ago

1.29.0

4 years ago

1.28.0

4 years ago

1.25.0

4 years ago

1.22.0

4 years ago

1.20.0

4 years ago

1.5.1

4 years ago

1.2.4

4 years ago