> ## Documentation Index
> Fetch the complete documentation index at: https://microsanbox-staging-toks-cloud-snapshot-contracts.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Volumes

> TypeScript SDK - Volume API reference

Create, manage, and mount named volumes. See [Volumes](/sandboxes/volumes) for usage examples.

## MountBuilder

Sandbox mount callbacks receive a fluent `MountBuilder`. For bind and directory-backed named-volume mounts, use `owner(uid, gid)` to choose the guest owner shown for host files that do not carry a per-file stat override.

```typescript theme={null}
const sb = await Sandbox.builder("worker")
  .image("python")
  .volume("/workspace", (mount) => mount.bind("./workspace").owner(1000, 1000))
  .create();
```

```typescript theme={null}
owner(uid: number, gid: number): this
```

Both values must be finite integers from `0` through `4294967295`. Existing per-file overrides still take precedence, and no host inode ownership is changed. The policy is rejected for tmpfs, host disk images, disk-backed named volumes, and mounts using `statVirtualization("off")`.

## Volume

<p className="msb-member-group">Instance properties</p>

#### <span className="msb-recv">volume.</span><span className="msb-hn">name</span>

```typescript theme={null}
get name(): string
```

The volume's name.

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Volume name.</div>
  </div>
</div>

#### <span className="msb-recv">volume.</span><span className="msb-hn">path</span>

<Tooltip tip="Only local volumes expose a path on the computer running the SDK."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

```typescript theme={null}
get path(): string
```

Absolute host path to the volume's directory. By default volumes live under `~/.microsandbox/volumes/<name>/`.

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Absolute host directory path.</div>
  </div>
</div>

<p className="msb-member-group">Static methods</p>

#### <span className="msb-recv">Volume.</span><span className="msb-hn">getDefault()</span>

<Tooltip tip="Available only on microsandbox cloud; the local backend has no default volume."><span className="msb-badge-cloud">Cloud-only <Icon icon="circle-info" size={11} /></span></Tooltip>

```typescript theme={null}
static getDefault(): Promise<VolumeHandle>
```

Get the Cloud account's always-present default volume. It has no user-assigned name, cannot be removed, and supports direct filesystem operations through `.fs()`. The local backend returns a typed `Unsupported` error; it never substitutes a directory from the caller's machine.

```typescript theme={null}
const volume = await Volume.getDefault();
await volume.fs().write("customers/acme.json", JSON.stringify({ active: true }));
console.log(await volume.fs().readToString("customers/acme.json"));
```

#### <span className="msb-recv">Volume.</span><span className="msb-hn">builder()</span>

```typescript theme={null}
static builder(name: string): VolumeBuilder
```

<Accordion title="Example">
  ```typescript theme={null}
  const data = await Volume.builder("my-data")
    .label("env", "prod")
    .create();
  ```
</Accordion>

Begin building a named volume. Directory-backed volumes are the default. Call `.disk().size(...)` for a disk-backed volume. See [`VolumeBuilder`](#volumebuilder) for all options.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>name</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Volume name.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="#volume-builder">VolumeBuilder</a></div>
    <div className="msb-param-desc">Fluent builder for configuring the volume.</div>
  </div>
</div>

#### <span className="msb-recv">Volume.</span><span className="msb-hn">get()</span>

```typescript theme={null}
static get(name: string): Promise<VolumeHandle>
```

<Accordion title="Example">
  ```typescript theme={null}
  const handle = await Volume.get("my-data");
  console.log(handle.usedBytes);
  ```
</Accordion>

Get a live handle to an existing named volume. A live handle supports `.fs()` and `.remove()`, unlike the read-only handles returned by [`list()`](#volume-list).

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>name</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Volume name.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="#volumehandle">Promise\<VolumeHandle></a></div>
    <div className="msb-param-desc">Live handle with metadata, filesystem access, and removal.</div>
  </div>
</div>

#### <span className="msb-recv">Volume.</span><span className="msb-hn">list()</span>

```typescript theme={null}
static list(): Promise<VolumeHandle[]>
```

<Accordion title="Example">
  ```typescript theme={null}
  for (const v of await Volume.list()) {
    console.log(`${v.name} - ${v.kind} - ${v.usedBytes} bytes`);
  }
  ```
</Accordion>

List all named volumes. Handles returned here are **read-only**: calling `.fs()` or `.remove()` on them throws. Call [`Volume.get(name)`](#volume-get) to upgrade to a live handle.

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="#volumehandle">Promise\<VolumeHandle\[]></a></div>
    <div className="msb-param-desc">All volumes, as read-only handles.</div>
  </div>
</div>

#### <span className="msb-recv">Volume.</span><span className="msb-hn">remove()</span>

```typescript theme={null}
static remove(name: string): Promise<void>
```

<Accordion title="Example">
  ```typescript theme={null}
  await Volume.remove("my-data");
  ```
</Accordion>

Delete a named volume and its contents. Fails if the volume is currently mounted by a sandbox.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>name</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Volume name.</div>
  </div>
</div>

<p className="msb-member-group">Instance methods</p>

#### <span className="msb-recv">volume.</span><span className="msb-hn">fs()</span>

```typescript theme={null}
fs(): VolumeFs
```

<Accordion title="Example">
  ```typescript theme={null}
  const vfs = data.fs();
  await vfs.write("seed.txt", "hello");
  console.log(await vfs.readToString("seed.txt"));
  ```
</Accordion>

Get a filesystem handle for this volume. Local reads and writes use the managed host directory; Cloud reads and writes use the authenticated volume API. No sandbox needs to be running. See [`VolumeFs`](#volumefs-methods) for the full API.

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="#volumefs">VolumeFs</a></div>
    <div className="msb-param-desc">Host-side filesystem handle.</div>
  </div>
</div>

## VolumeBuilder

Fluent builder for a named volume. Obtained via [`Volume.builder(name)`](#volume-builder). Directory-backed volumes are the default; call [`disk()`](#disk) plus [`size()`](#size) for a disk-backed volume. Every setter returns the builder, so calls chain.

#### <span className="msb-recv">volumeBuilder.</span><span className="msb-hn">directory()</span>

```typescript theme={null}
directory(): this
```

Create a directory-backed volume. This is the default, so calling it is only needed for clarity.

#### <span className="msb-recv">volumeBuilder.</span><span className="msb-hn">disk()</span>

<Tooltip tip="Disk-kind volumes are not available on microsandbox cloud; use a directory-backed named volume."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

```typescript theme={null}
disk(): this
```

<Accordion title="Example">
  ```typescript theme={null}
  const dockerData = await Volume.builder("docker-data")
    .disk()
    .size(20 * 1024)
    .create();
  ```
</Accordion>

Create a raw ext4 disk-backed volume. Pair with [`size()`](#size) to set the capacity.

#### <span className="msb-recv">volumeBuilder.</span><span className="msb-hn">size()</span>

<Tooltip tip="Disk-kind volumes are not available on microsandbox cloud; use a directory-backed named volume."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

```typescript theme={null}
size(mib: number): this
```

Set the disk capacity in MiB. Required after [`disk()`](#disk).

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>mib</code><span className="msb-type">number</span></div>
    <div className="msb-param-desc">Disk capacity in MiB.</div>
  </div>
</div>

#### <span className="msb-recv">volumeBuilder.</span><span className="msb-hn">quota()</span>

<Tooltip tip="On microsandbox cloud, quota must be a nonzero whole number of GiB."><span className="msb-badge-limited">Limited on cloud <Icon icon="circle-info" size={11} /></span></Tooltip>

```typescript theme={null}
quota(mib: number): this
```

Record a quota in MiB as metadata for directory-backed volumes.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>mib</code><span className="msb-type">number</span></div>
    <div className="msb-param-desc">Quota in MiB.</div>
  </div>
</div>

#### <span className="msb-recv">volumeBuilder.</span><span className="msb-hn">label()</span>

```typescript theme={null}
label(key: string, value: string): this
```

Add a metadata label. Can be called multiple times.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>key</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Label key.</div>
  </div>

  <div className="msb-param">
    <div className="msb-param-key"><code>value</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Label value.</div>
  </div>
</div>

#### <span className="msb-recv">volumeBuilder.</span><span className="msb-hn">build()</span>

```typescript theme={null}
build(): { name: string; kind: string; quotaMib?: number | null; capacityMib?: number | null; labels: Record<string, string> }
```

Materialize the volume configuration without creating the volume on disk. To create it, use [`create()`](#create) instead. The returned config object is the internal `NapiVolumeConfig` shape (not a public export).

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key">
      <span className="msb-type">
        {`{ name, kind, quotaMib?, capacityMib?, labels }`}
      </span>
    </div>

    <div className="msb-param-desc">Frozen volume configuration object.</div>
  </div>
</div>

#### <span className="msb-recv">volumeBuilder.</span><span className="msb-hn">create()</span>

<Tooltip tip="Microsandbox cloud creates directory volumes only; size is unavailable and quota must be a nonzero whole number of GiB."><span className="msb-badge-limited">Limited on cloud <Icon icon="circle-info" size={11} /></span></Tooltip>

```typescript theme={null}
create(): Promise<Volume>
```

<Accordion title="Example">
  ```typescript theme={null}
  const data = await Volume.builder("my-data").create();
  ```
</Accordion>

Build and create the volume on disk, returning a [`Volume`](#instance-methods).

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="#instance-methods">Promise\<Volume></a></div>
    <div className="msb-param-desc">The created volume.</div>
  </div>
</div>

## VolumeFs

<p className="msb-backref">Returned by <a href="#volume-fs">volume.fs()</a> · <a href="#volumehandle">VolumeHandle.fs()</a></p>

Host-side filesystem operations for a named volume.

#### <span className="msb-recv">vfs.</span><span className="msb-hn">read()</span>

```typescript theme={null}
read(path: string): Promise<Uint8Array>
```

<Accordion title="Example">
  ```typescript theme={null}
  const bytes = await vfs.read("data.bin");
  ```
</Accordion>

Read a file's full contents as bytes.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Path relative to the volume root.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><span className="msb-type">Promise\<Uint8Array></span></div>
    <div className="msb-param-desc">File contents.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">readToString()</span>

```typescript theme={null}
readToString(path: string): Promise<string>
```

<Accordion title="Example">
  ```typescript theme={null}
  const text = await vfs.readToString("config.json");
  ```
</Accordion>

Read a file's full contents as a UTF-8 string.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Path relative to the volume root.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><span className="msb-type">Promise\<string></span></div>
    <div className="msb-param-desc">Decoded file contents.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">readStream()</span>

```typescript theme={null}
readStream(path: string): Promise<VolumeFsReadStream>
```

<Accordion title="Example">
  ```typescript theme={null}
  const stream = await vfs.readStream("large.bin");
  for await (const chunk of stream) {
    console.log(chunk.byteLength);
  }
  ```
</Accordion>

Open a streaming reader for a file, for chunked reads of large files without loading them fully into memory.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Path relative to the volume root.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="#volumefsreadstream">Promise\<VolumeFsReadStream></a></div>
    <div className="msb-param-desc">Async-iterable read stream.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">write()</span>

```typescript theme={null}
write(path: string, data: Uint8Array | string): Promise<void>
```

<Accordion title="Example">
  ```typescript theme={null}
  await vfs.write("seed.txt", "hello");
  ```
</Accordion>

Write a file, replacing any existing contents. Strings are encoded as UTF-8.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Path relative to the volume root.</div>
  </div>

  <div className="msb-param">
    <div className="msb-param-key"><code>data</code><span className="msb-type">Uint8Array | string</span></div>
    <div className="msb-param-desc">Bytes, or a UTF-8 string.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">writeStream()</span>

```typescript theme={null}
writeStream(path: string): Promise<VolumeFsWriteSink>
```

<Accordion title="Example">
  ```typescript theme={null}
  const sink = await vfs.writeStream("out.bin");
  await sink.write(chunk);
  await sink.close();
  ```
</Accordion>

Open a streaming writer for a file, for chunked writes of large files.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Path relative to the volume root.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="#volumefswritesink">Promise\<VolumeFsWriteSink></a></div>
    <div className="msb-param-desc">Write sink; call <code>close()</code> when done.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">list()</span>

```typescript theme={null}
list(path: string): Promise<FsEntry[]>
```

<Accordion title="Example">
  ```typescript theme={null}
  for (const e of await vfs.list("")) {
    console.log(e.path, e.kind, e.size);
  }
  ```
</Accordion>

List the entries in a directory. Pass `""` for the volume root.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Directory path relative to the volume root.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="/sdk/typescript/filesystem#fsentry">Promise\<FsEntry\[]></a></div>
    <div className="msb-param-desc">Directory entries.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">mkdir()</span>

```typescript theme={null}
mkdir(path: string): Promise<void>
```

<Accordion title="Example">
  ```typescript theme={null}
  await vfs.mkdir("cache/images");
  ```
</Accordion>

Create a directory, including any missing parents.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Directory path relative to the volume root.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">removeDir()</span>

```typescript theme={null}
removeDir(path: string): Promise<void>
```

<Accordion title="Example">
  ```typescript theme={null}
  await vfs.removeDir("cache");
  ```
</Accordion>

Recursively remove a directory and its contents.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Directory path relative to the volume root.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">remove()</span>

```typescript theme={null}
remove(path: string): Promise<void>
```

<Accordion title="Example">
  ```typescript theme={null}
  await vfs.remove("seed.txt");
  ```
</Accordion>

Remove a single file.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">File path relative to the volume root.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">copy()</span>

```typescript theme={null}
copy(from: string, to: string): Promise<void>
```

<Accordion title="Example">
  ```typescript theme={null}
  await vfs.copy("seed.txt", "backup/seed.txt");
  ```
</Accordion>

Copy a file or directory from one path to another.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>from</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Source path relative to the volume root.</div>
  </div>

  <div className="msb-param">
    <div className="msb-param-key"><code>to</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Destination path relative to the volume root.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">rename()</span>

```typescript theme={null}
rename(from: string, to: string): Promise<void>
```

<Accordion title="Example">
  ```typescript theme={null}
  await vfs.rename("draft.txt", "final.txt");
  ```
</Accordion>

Move or rename a file or directory.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>from</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Source path relative to the volume root.</div>
  </div>

  <div className="msb-param">
    <div className="msb-param-key"><code>to</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Destination path relative to the volume root.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">stat()</span>

```typescript theme={null}
stat(path: string): Promise<FsMetadata>
```

<Accordion title="Example">
  ```typescript theme={null}
  const meta = await vfs.stat("seed.txt");
  console.log(meta.size, meta.kind);
  ```
</Accordion>

Get metadata for a file or directory.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Path relative to the volume root.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><a className="msb-type" href="/sdk/typescript/filesystem#fsmetadata">Promise\<FsMetadata></a></div>
    <div className="msb-param-desc">Kind, size, mode, and timestamps.</div>
  </div>
</div>

#### <span className="msb-recv">vfs.</span><span className="msb-hn">exists()</span>

```typescript theme={null}
exists(path: string): Promise<boolean>
```

<Accordion title="Example">
  ```typescript theme={null}
  if (await vfs.exists("seed.txt")) {
    await vfs.remove("seed.txt");
  }
  ```
</Accordion>

Check whether a path exists.

<p className="msb-label">Parameters</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><code>path</code><span className="msb-type">string</span></div>
    <div className="msb-param-desc">Path relative to the volume root.</div>
  </div>
</div>

<p className="msb-label">Returns</p>

<div className="msb-params">
  <div className="msb-param">
    <div className="msb-param-key"><span className="msb-type">Promise\<boolean></span></div>
    <div className="msb-param-desc"><code>true</code> if the path exists.</div>
  </div>
</div>

## VolumeHandle

<p className="msb-backref">Returned by <a href="#volume-get">Volume.get()</a> · <a href="#volume-list">Volume.list()</a></p>

A metadata and lifecycle handle for an existing volume.

#### <span className="msb-recv">handle.</span><span className="msb-hn">name</span>

`string`

Volume name

#### <span className="msb-recv">handle.</span><span className="msb-hn">kind</span>

`string`

Volume kind (`"dir"` or `"disk"`)

#### <span className="msb-recv">handle.</span><span className="msb-hn">quotaMib</span>

`number \| null`

Recorded storage quota in MiB

#### <span className="msb-recv">handle.</span><span className="msb-hn">usedBytes</span>

`number`

Current disk usage in bytes

#### <span className="msb-recv">handle.</span><span className="msb-hn">capacityBytes</span>

`number \| null`

Disk capacity in bytes (disk volumes)

#### <span className="msb-recv">handle.</span><span className="msb-hn">diskFormat</span>

`string \| null`

Disk image format (disk volumes)

#### <span className="msb-recv">handle.</span><span className="msb-hn">diskFstype</span>

`string \| null`

Inner disk filesystem (disk volumes)

#### <span className="msb-recv">handle.</span><span className="msb-hn">labels</span>

`ReadonlyArray<readonly [string, string]>`

Metadata labels

#### <span className="msb-recv">handle.</span><span className="msb-hn">createdAt</span>

`Date \| null`

Creation timestamp

#### <span className="msb-recv">handle.</span><span className="msb-hn">fs()</span>

```typescript theme={null}
fs()
```

Host-side filesystem (live handles only; throws on read-only handles)

<p className="msb-label">Returns</p>

[`VolumeFs`](#volumefs)

#### <span className="msb-recv">handle.</span><span className="msb-hn">remove()</span>

```typescript theme={null}
remove()
```

Delete this volume (live handles only; throws on read-only handles)

<p className="msb-label">Returns</p>

`Promise<void>`

## VolumeFsReadStream

<p className="msb-backref">Returned by <a href="#volumefs-methods">VolumeFs.readStream()</a></p>

A streaming reader over a volume file. Implements `AsyncIterable<Uint8Array>` and `AsyncDisposable`, so it works with `for await` and `using`.

#### <span className="msb-recv">stream.</span><span className="msb-hn">recv()</span>

```typescript theme={null}
recv()
```

Read the next chunk; `null` when the stream is exhausted

<p className="msb-label">Returns</p>

`Promise<Uint8Array \| null>`

#### <span className="msb-recv">stream.</span><span className="msb-hn">collect()</span>

```typescript theme={null}
collect()
```

Drain the stream into a single byte array

<p className="msb-label">Returns</p>

`Promise<Uint8Array>`

#### <span className="msb-recv">stream.</span><span className="msb-hn">[Symbol.asyncIterator]()</span>

```typescript theme={null}
[Symbol.asyncIterator]()
```

Iterate chunks with `for await`

<p className="msb-label">Returns</p>

`AsyncIterator<Uint8Array>`

#### <span className="msb-recv">stream.</span><span className="msb-hn">[Symbol.asyncDispose]()</span>

```typescript theme={null}
[Symbol.asyncDispose]()
```

Mark the stream done (for `using`)

<p className="msb-label">Returns</p>

`Promise<void>`

## VolumeFsWriteSink

<p className="msb-backref">Returned by <a href="#volumefs-methods">VolumeFs.writeStream()</a></p>

A streaming writer for a volume file. Implements `AsyncDisposable`, so `await using` closes it automatically.

#### <span className="msb-recv">sink.</span><span className="msb-hn">write()</span>

```typescript theme={null}
write(data)
```

Write a chunk (`Uint8Array` or UTF-8 string)

<p className="msb-label">Returns</p>

`Promise<void>`

#### <span className="msb-recv">sink.</span><span className="msb-hn">close()</span>

```typescript theme={null}
close()
```

Flush and close the sink; idempotent

<p className="msb-label">Returns</p>

`Promise<void>`

#### <span className="msb-recv">sink.</span><span className="msb-hn">[Symbol.asyncDispose]()</span>

```typescript theme={null}
[Symbol.asyncDispose]()
```

Close the sink (for `await using`)

<p className="msb-label">Returns</p>

`Promise<void>`
