# BufferedReadStream

Class · extends [`ReadStream`](https://api.playcanvas.com/splat-transform/classes/ReadStream.md)

Source: https://github.com/playcanvas/splat-transform/blob/b6424a5b3b929695fbaafe738a995adb1240d675/src/lib/io/read/buffered-read-stream.ts#L13

ReadStream wrapper that adds read-ahead buffering to reduce async overhead.
Reads larger chunks from the inner stream and buffers excess data for
subsequent small reads. Useful for sources with high per-call overhead.

**Example**

```ts
// Wrap a stream with 4MB read-ahead buffering
const buffered = new BufferedReadStream(rawStream, 4 * 1024 * 1024);
const data = await buffered.readAll();
```

## Constructors

### constructor

```ts
new BufferedReadStream(inner: ReadStream, chunkSize?: number)
```

Create a caching wrapper around a stream.

**Parameters**

- `inner` ([`ReadStream`](https://api.playcanvas.com/splat-transform/classes/ReadStream.md)): The underlying stream to read from
- `chunkSize` (`number`, optional, default `65536`): Minimum bytes to read at once from inner stream (default 64KB)

## Methods

### close

```ts
close(): void
```

Release resources and abort any pending operations.

### pull

```ts
pull(target: Uint8Array): Promise<number>
```

Pull data into the provided buffer.

**Parameters**

- `target` (`Uint8Array`): Buffer to fill with data

**Returns** `Promise<number>`: Number of bytes read, or 0 for EOF

## Inherited from [ReadStream](https://api.playcanvas.com/splat-transform/classes/ReadStream.md)

- `bytesRead: number = 0`
- `readonly expectedSize: number`
- `readAll(): Promise<Uint8Array<ArrayBufferLike>>`
