mirror-drive

Mirror a hyperdrive or localdrive into another one

Apache-2.0 28 个版本
安装
npm install mirror-drive
yarn add mirror-drive
pnpm add mirror-drive
bun add mirror-drive
README

mirror-drive

Mirror a Hyperdrive or Localdrive into another one

npm i mirror-drive

Usage

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:

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:

{
  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

版本列表
1.14.2 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
1.3.1 2024-03-01
1.3.0 2023-07-21
1.2.4 2023-05-25
1.2.3 2023-05-19
1.2.2 2023-01-30
1.2.1 2022-12-22
1.2.0 2022-10-07
1.1.0 2022-10-05
1.0.4 2022-10-05
1.0.3 2022-09-22
1.0.2 2022-09-19
1.0.1 2022-09-16
1.0.0 2022-09-16