# mirror-drive

> Mirror a hyperdrive or localdrive into another one

Latest version **1.14.2** (published 2026-04-24) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install mirror-drive
pnpm add mirror-drive
yarn add mirror-drive
bun add mirror-drive
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.14.2 |
| Published | 2026-04-24 |
| First published | 2022-09-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 27.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Lucas Barrena |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/mirror-drive
- Repository: https://github.com/holepunchto/mirror-drive
- Issues: https://github.com/holepunchto/mirror-drive/issues
- npm.io page: https://npm.io/package/mirror-drive

## Dependencies (7)

- [streamx](https://npm.io/package/streamx.md) ^2.22.1
- [same-data](https://npm.io/package/same-data.md) ^1.0.0
- [bare-events](https://npm.io/package/bare-events.md) ^2.8.2
- [speedometer](https://npm.io/package/speedometer.md) ^1.1.0
- [rabin-stream](https://npm.io/package/rabin-stream.md) ^2.0.0
- [unix-path-resolve](https://npm.io/package/unix-path-resolve.md) ^1.0.2
- [binary-stream-equals](https://npm.io/package/binary-stream-equals.md) ^1.0.0

## Recent versions

- 1.14.2 (latest) — 2026-04-24
- 1.14.1 — 2026-03-29
- 1.14.0 — 2026-03-28
- 1.13.0 — 2026-02-23
- 1.12.0 — 2026-02-02
- 1.11.1 — 2026-01-26
- 1.11.0 — 2026-01-26
- 1.10.0 — 2025-11-24
- 1.9.0 — 2025-11-24
- 1.8.0 — 2025-11-24
- 1.7.0 — 2025-11-07
- 1.6.0 — 2025-09-11
- 1.5.1 — 2025-06-19
- 1.5.0 — 2025-04-16
- 1.4.0 — 2024-08-30
- … 13 more at https://npm.io/package/mirror-drive/versions

## README

# mirror-drive

Mirror a Hyperdrive or Localdrive into another one

```
npm i mirror-drive
```

## Usage

```js
import MirrorDrive from 'mirror-drive'

const src = new Localdrive('./src')
const dst = new Hyperdrive(store)

const mirror = new MirrorDrive(src, dst)
console.log(mirror.count) // => { files: 0, add: 0, remove: 0, change: 0 }

for await (const diff of mirror) {
  console.log(diff) /* {
    op: 'add',
    key: '/new-file.txt',
    bytesRemoved: 0,
    bytesAdded: 4
  }*/
}

console.log(mirror.count) // => { files: 1, add: 1, remove: 0, change: 0 }
```

Another example:

```js
const mirror = new MirrorDrive(src, dst)

console.log(mirror.count) // => { files: 0, add: 0, remove: 0, change: 0 }
await mirror.done()
console.log(mirror.count) // => { files: 1, add: 1, remove: 0, change: 0 }
```

## API

#### `const mirror = new MirrorDrive(src, dst, [options])`

Creates a mirror instance to efficiently move `src` drive into `dst` drive.

Available `options`:

```js
{
  prefix: '/',
  dryRun: false,
  prune: true,
  includeEquals: false,
  filter: (key) => true,
  metadataEquals: (srcMetadata, dstMetadata) => { ... }
  batch: false,
  entries: null // Array of key entries (if you use this then prefix is ignored)
  ignore: String || Array // Ignore source files and folders by name.
  transformers: [] // Array of factory functions (key) => stream
}
```

#### `mirror.count`

It counts the total files proccessed, added, removed, and changed.

Default value: `{ files: 0, add: 0, remove: 0, change: 0 }`

#### `await mirror.done()`

It starts processing all the diffing until is done.

## Transformers

Apply content transformers during mirroring. Each item in `transformers` is a factory function `(key) => stream | null` that returns a new stream (or `null`) for that file. MirrorDrive always pipes through all provided transformers. If a `transformer` returns `null` it is safely skipped.

## License

Apache-2.0

---
_Source: https://npm.io/package/mirror-drive · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
