---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/storage/in_memory/classes/InMemorySpoolStore.md
description: 'In-memory "give bytes, get a reader" persistence layer keyed by `callId`.'
---

# Class: InMemorySpoolStore

Defined in: [batteries/storage/in\_memory/index.ts:134](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L134)

In-memory "give bytes, get a reader" persistence layer keyed by `callId`.

## Remarks

Stores each value byte-faithfully as a `Uint8Array`. `string` inputs are encoded as UTF-8;
`Uint8Array` inputs are held verbatim (no lossy text round-trip, so binary payloads survive
intact); `ReadableStream<Uint8Array>` inputs are drained fully into a buffer — in-memory storage
cannot stream to disk, so the stream form resolves asynchronously and is the documented
trade-off for this battery.

Each `write()` and each `read()` returns a *fresh* [InMemorySpoolReader](InMemorySpoolReader.md) — the store
owns the bytes, the reader is a view. Mutating the store after handing out a reader does not
invalidate the reader.

Implements @nhtio/adk!SpoolStore (i.e. `ByteStore<SpoolReader>`).

## Example

```ts
const store = new InMemorySpoolStore();
const bytes = await tool.executor(ctx)(args);
const reader = await store.write(callId, bytes);
const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact;
const artifact = new Ctor(reader);
```

## Implements

* [`SpoolStore`](../../../../common/type-aliases/SpoolStore.md)

## Constructors

### Constructor

```ts
new InMemorySpoolStore(): InMemorySpoolStore;
```

#### Returns

`InMemorySpoolStore`

## Accessors

### size

#### Get Signature

```ts
get size(): number;
```

Defined in: [batteries/storage/in\_memory/index.ts:210](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L210)

Returns the number of entries currently in the store.

##### Returns

`number`

## Methods

### clear()

```ts
clear(): void;
```

Defined in: [batteries/storage/in\_memory/index.ts:203](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L203)

Removes every entry from the store.

#### Returns

`void`

#### Remarks

Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold
their own snapshot.

***

### delete()

```ts
delete(callId: string): boolean;
```

Defined in: [batteries/storage/in\_memory/index.ts:192](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L192)

Removes the entry under `callId`.

#### Parameters

| Parameter | Type     | Description                               |
| --------- | -------- | ----------------------------------------- |
| `callId`  | `string` | Identifier whose entry should be removed. |

#### Returns

`boolean`

`true` if an entry existed and was removed; `false` otherwise.

#### Implementation of

```ts
SpoolStore.delete;
```

***

### read()

```ts
read(callId: string): InMemorySpoolReader | undefined;
```

Defined in: [batteries/storage/in\_memory/index.ts:180](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L180)

Returns a reader over the bytes previously written under `callId`, or `undefined` if the
entry has not been written or has been deleted.

#### Parameters

| Parameter | Type     | Description                                                             |
| --------- | -------- | ----------------------------------------------------------------------- |
| `callId`  | `string` | Identifier supplied to a prior [InMemorySpoolStore.write](#write) call. |

#### Returns

[`InMemorySpoolReader`](InMemorySpoolReader.md) | `undefined`

A fresh [InMemorySpoolReader](InMemorySpoolReader.md) bound to the stored bytes, or `undefined`.

#### Implementation of

```ts
SpoolStore.read;
```

***

### write()

#### Call Signature

```ts
write(callId: string, bytes: string): InMemorySpoolReader;
```

Defined in: [batteries/storage/in\_memory/index.ts:151](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L151)

Persists `bytes` under `callId` and returns a reader over them.

##### Parameters

| Parameter | Type     | Description                                                                       |
| --------- | -------- | --------------------------------------------------------------------------------- |
| `callId`  | `string` | Identifier used to retrieve the bytes via [InMemorySpoolStore.read](#read).       |
| `bytes`   | `string` | The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`. |

##### Returns

[`InMemorySpoolReader`](InMemorySpoolReader.md)

A fresh [InMemorySpoolReader](InMemorySpoolReader.md) bound to the stored bytes — a `Promise` for stream
input, synchronous otherwise.

##### Remarks

`string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;
`ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the
same `callId` replaces the prior entry; readers handed out before the rewrite continue to view
the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).

##### Implementation of

```ts
SpoolStore.write;
```

#### Call Signature

```ts
write(callId: string, bytes: Uint8Array): InMemorySpoolReader;
```

Defined in: [batteries/storage/in\_memory/index.ts:152](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L152)

Persists `bytes` under `callId` and returns a reader over them.

##### Parameters

| Parameter | Type         | Description                                                                       |
| --------- | ------------ | --------------------------------------------------------------------------------- |
| `callId`  | `string`     | Identifier used to retrieve the bytes via [InMemorySpoolStore.read](#read).       |
| `bytes`   | `Uint8Array` | The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`. |

##### Returns

[`InMemorySpoolReader`](InMemorySpoolReader.md)

A fresh [InMemorySpoolReader](InMemorySpoolReader.md) bound to the stored bytes — a `Promise` for stream
input, synchronous otherwise.

##### Remarks

`string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;
`ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the
same `callId` replaces the prior entry; readers handed out before the rewrite continue to view
the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).

##### Implementation of

```ts
SpoolStore.write;
```

#### Call Signature

```ts
write(callId: string, bytes: ReadableStream<Uint8Array<ArrayBufferLike>>): Promise<InMemorySpoolReader>;
```

Defined in: [batteries/storage/in\_memory/index.ts:153](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L153)

Persists `bytes` under `callId` and returns a reader over them.

##### Parameters

| Parameter | Type                                                  | Description                                                                       |
| --------- | ----------------------------------------------------- | --------------------------------------------------------------------------------- |
| `callId`  | `string`                                              | Identifier used to retrieve the bytes via [InMemorySpoolStore.read](#read).       |
| `bytes`   | `ReadableStream`<`Uint8Array`<`ArrayBufferLike`>> | The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`. |

##### Returns

`Promise`<[`InMemorySpoolReader`](InMemorySpoolReader.md)>

A fresh [InMemorySpoolReader](InMemorySpoolReader.md) bound to the stored bytes — a `Promise` for stream
input, synchronous otherwise.

##### Remarks

`string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;
`ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the
same `callId` replaces the prior entry; readers handed out before the rewrite continue to view
the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).

##### Implementation of

```ts
SpoolStore.write;
```

#### Call Signature

```ts
write(callId: string, bytes:
  | string
  | Uint8Array<ArrayBufferLike>
  | ReadableStream<Uint8Array<ArrayBufferLike>>):
  | InMemorySpoolReader
| Promise<InMemorySpoolReader>;
```

Defined in: [batteries/storage/in\_memory/index.ts:154](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/storage/in_memory/index.ts#L154)

Persists `bytes` under `callId` and returns a reader over them.

##### Parameters

| Parameter | Type                                                                                                      | Description                                                                       |
| --------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `callId`  | `string`                                                                                                  | Identifier used to retrieve the bytes via [InMemorySpoolStore.read](#read).       |
| `bytes`   | | `string` | `Uint8Array`<`ArrayBufferLike`> | `ReadableStream`<`Uint8Array`<`ArrayBufferLike`>> | The bytes to store, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`. |

##### Returns

| [`InMemorySpoolReader`](InMemorySpoolReader.md)
| `Promise`<[`InMemorySpoolReader`](InMemorySpoolReader.md)>

A fresh [InMemorySpoolReader](InMemorySpoolReader.md) bound to the stored bytes — a `Promise` for stream
input, synchronous otherwise.

##### Remarks

`string` input is encoded as UTF-8; `Uint8Array` is stored byte-faithfully;
`ReadableStream<Uint8Array>` is drained fully (and `write` returns a `Promise`). Re-writing the
same `callId` replaces the prior entry; readers handed out before the rewrite continue to view
the old bytes (they hold their own snapshot via the `InMemorySpoolReader` constructor).

##### Implementation of

```ts
SpoolStore.write;
```
