# uint8arraylist
**Repository Path**: mirrors_tmm1/uint8arraylist
## Basic Information
- **Project Name**: uint8arraylist
- **Description**: Append and consume bytes using only no-copy operations
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-10-21
- **Last Updated**: 2026-03-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[](https://codecov.io/gh/achingbrain/uint8arraylist)
[](https://github.com/achingbrain/uint8arraylist/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
> Append and consume bytes using only no-copy operations
# About
A class that lets you do operations over a list of Uint8Arrays without
copying them.
```js
import { Uint8ArrayList } from 'uint8arraylist'
const list = new Uint8ArrayList()
list.append(Uint8Array.from([0, 1, 2]))
list.append(Uint8Array.from([3, 4, 5]))
list.subarray()
// -> Uint8Array([0, 1, 2, 3, 4, 5])
list.consume(3)
list.subarray()
// -> Uint8Array([3, 4, 5])
// you can also iterate over the list
for (const buf of list) {
// ..do something with `buf`
}
list.subarray(0, 1)
// -> Uint8Array([0])
```
## Converting Uint8ArrayLists to Uint8Arrays
There are two ways to turn a `Uint8ArrayList` into a `Uint8Array` - `.slice` and `.subarray` and one way to turn a `Uint8ArrayList` into a `Uint8ArrayList` with different contents - `.sublist`.
### slice
Slice follows the same semantics as [Uint8Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice) in that it creates a new `Uint8Array` and copies bytes into it using an optional offset & length.
```js
const list = new Uint8ArrayList()
list.append(Uint8Array.from([0, 1, 2]))
list.append(Uint8Array.from([3, 4, 5]))
list.slice(0, 1)
// -> Uint8Array([0]) - copy
list.slice(2, 5)
// -> Uint8Array([2, 3, 4]) - copy
```
### subarray
Subarray attempts to follow the same semantics as [Uint8Array.subarray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray) with one important different - this is a no-copy operation, unless the requested bytes span two internal buffers in which case it is a copy operation.
```js
const list = new Uint8ArrayList()
list.append(Uint8Array.from([0, 1, 2]))
list.append(Uint8Array.from([3, 4, 5]))
list.slice(0, 1)
// -> Uint8Array([0]) - no-copy
list.slice(2, 5)
// -> Uint8Array([2, 3, 4]) - copy
```
### sublist
Sublist creates and returns a new `Uint8ArrayList` that shares the underlying buffers with the original so is always a no-copy operation.
```js
const list = new Uint8ArrayList()
list.append(Uint8Array.from([0, 1, 2]))
list.append(Uint8Array.from([3, 4, 5]))
list.sublist(0, 1)
// -> Uint8ArrayList([0]) - no-copy
list.sublist(2, 5)
// -> Uint8ArrayList([2], [3, 4]) - no-copy
```
## Inspiration
Borrows liberally from [bl](https://www.npmjs.com/package/bl) but only uses native JS types.
# Install
```console
$ npm i uint8arraylist
```
## Browser `
```
# API Docs
-
# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / )
- MIT ([LICENSE-MIT](LICENSE-MIT) / )
# Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.