node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



ByteVector for node.js. Perfect for binary data.


var ByteVector = requite('bytevector'),
    vector = new ByteVector([1, 2, 3, 4, 5]); // Our vector

vector.push_back(6); // Insert binary value '6' in the end
vector.pop_front(); // Remove first value (1).

var copy = new ByteVector(vector); // [2, 3, 4, 5, 6]


  • Space effcient. Each element will only use 8 bits memory.
  • Performance wise. It is so fast it can principle be.

Good to know

All values are saved in a Uint8Array instance which only accepts integer values between 0-255. I



Construct an empty vector with reserved size [int].


Construct a vector with values from [array].

Constructor(array, offset):

Construct a vector from [array] range: [offset, to_array_end).

Constructor(Uint8Array): (Not implemented yet)

Construct the vector from the Uint8Array. It will assume the array has previusly been constrcted with .serialize().

.serialize() Not implemented yet.

Returns the underlying Uint8Array buffer.


Returns the first element in the vector.


Returns the last element in the vector.


Insert [Uint8] in the back of of the vector.


Remove last item and returns it. Alias for .pop_back()


Reserve [Uint32] amount of memory.


Return reserved memory.


Resize vector size to [Uint32] elements.

.assign(obj, offset?, length?)

Assign this vector using the elements in [obj]. Obj can either be a instance of ByteVector or an object that implements obj.length and obj[N].


Insert [Uint8] in the back of the vector.


Insert [Uint8] in the beginning of the vector.


Remove last item in the vector and returns it.


Remove first element in the beginning of the vector and returns it.


Return element at position [pos].

.set(pos, value)

Set element at position [pos] to value [value].


Removes all elements from the vector.


Returns current vector size.


Returns current vector size.

.length = N

Resize vector to [N] elements.


Returns a reference to the underlying buffer.