# @jsonjoy.com/fs-snapshot

> File system snapshot - serialize and deserialize file system trees to binary or JSON

Latest version **4.79.0** (published 2026-09-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @jsonjoy.com/fs-snapshot
pnpm add @jsonjoy.com/fs-snapshot
yarn add @jsonjoy.com/fs-snapshot
bun add @jsonjoy.com/fs-snapshot
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.79.0 |
| Published | 2026-09-22 |
| First published | 2026-01-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0 |
| Dependencies | 4 |
| Unpacked size | 43.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2095 |
| Author | streamich |
| Maintainers | json-joy-team, streamich |
| Keywords | filesystem, fs, snapshot, serialize, deserialize, binary, cbor, json, backup, restore |

## Links

- npm: https://www.npmjs.com/package/@jsonjoy.com/fs-snapshot
- Repository: https://github.com/streamich/memfs
- Homepage: https://github.com/streamich/memfs/tree/master/packages/fs-snapshot
- Issues: https://github.com/streamich/memfs/issues
- Funding: https://github.com/sponsors/streamich
- npm.io page: https://npm.io/package/@jsonjoy.com/fs-snapshot

## Dependencies (4)

- [@jsonjoy.com/util](https://npm.io/package/@jsonjoy.com/util.md) ^17.65.0
- [@jsonjoy.com/buffers](https://npm.io/package/@jsonjoy.com/buffers.md) ^17.65.0
- [@jsonjoy.com/json-pack](https://npm.io/package/@jsonjoy.com/json-pack.md) ^17.65.0
- [@jsonjoy.com/fs-node-utils](https://npm.io/package/@jsonjoy.com/fs-node-utils.md) 4.79.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 4.79.0 (latest) — 2026-09-22
- 4.78.1 — 2026-09-17
- 4.78.0 — 2026-09-13
- 4.77.0 — 2026-09-13
- 4.76.0 — 2026-09-12
- 4.75.0 — 2026-09-11
- 4.74.0 — 2026-09-10
- 4.73.0 — 2026-09-10
- 4.72.2 — 2026-09-10
- 4.72.1 — 2026-09-09
- 4.72.0 — 2026-09-09
- 4.71.1 — 2026-09-09
- 4.71.0 — 2026-09-04
- 4.70.0 — 2026-09-04
- 4.69.1 — 2026-09-02
- … 32 more at https://npm.io/package/@jsonjoy.com/fs-snapshot/versions

## README

# @jsonjoy.com/fs-snapshot

File system snapshot - serialize and deserialize file system trees to binary (CBOR) or JSON format.

## Installation

```bash
npm install @jsonjoy.com/fs-snapshot
```

## Features

- Serialize entire file system trees into compact binary (CBOR) or JSON snapshots
- Restore file system trees from snapshots
- Supports files, directories, and symbolic links
- Both synchronous and asynchronous APIs
- Works with any Node.js-compatible `fs` module

## Usage

### Synchronous API

```ts
import * as fs from 'fs';
import { toSnapshotSync, fromSnapshotSync } from '@jsonjoy.com/fs-snapshot';

// Create a snapshot of a directory
const snapshot = toSnapshotSync({ fs, path: '/path/to/directory' });

// Restore the snapshot to a different location
fromSnapshotSync(snapshot, { fs, path: '/path/to/restore' });
```

### Asynchronous API

```ts
import * as fs from 'fs';
import { toSnapshot, fromSnapshot } from '@jsonjoy.com/fs-snapshot';

// Create a snapshot of a directory
const snapshot = await toSnapshot({ fs: fs.promises, path: '/path/to/directory' });

// Restore the snapshot to a different location
await fromSnapshot(snapshot, { fs: fs.promises, path: '/path/to/restore' });
```

### Binary (CBOR) Snapshots

Binary snapshots are more compact and faster to serialize/deserialize:

```ts
import * as fs from 'fs';
import { toBinarySnapshotSync, fromBinarySnapshotSync } from '@jsonjoy.com/fs-snapshot';

// Create a binary snapshot
const binary = toBinarySnapshotSync({ fs, path: '/path/to/directory' });

// Restore from binary snapshot
fromBinarySnapshotSync(binary, { fs, path: '/path/to/restore' });
```

### JSON Snapshots

JSON snapshots are human-readable and easier to debug:

```ts
import * as fs from 'fs';
import { toJsonSnapshotSync, fromJsonSnapshotSync } from '@jsonjoy.com/fs-snapshot';

// Create a JSON snapshot
const jsonSnapshot = toJsonSnapshotSync({ fs, path: '/path/to/directory' });

// Restore from JSON snapshot
fromJsonSnapshotSync(jsonSnapshot, { fs, path: '/path/to/restore' });
```

## Snapshot Format

Snapshots are represented as tuples with the following structure:

- **Folder**: `[0, metadata, { entries }]`
- **File**: `[1, metadata, Uint8Array]`
- **Symlink**: `[2, { target: string }]`

## License

Apache-2.0

---
_Source: https://npm.io/package/@jsonjoy.com/fs-snapshot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
