Welcome
Awesome Dat
Dat Applications
datproject/dat
datproject/dat-desktop
Community Applications
codeforscience/sciencefair
mafintosh/hyperirc
jondashkyle/soundcloud-archiver
mafintosh/hypervision
joehand/hypertweet
beakerbrowser/dat-photos-app
High-Level APIs
datproject/dat-node
datproject/dat-js
beakerbrowser/pauls-dat-api
beakerbrowser/node-dat-archive
Hosting & Dat Management
mafintosh/hypercore-archiver
datprotocol/hypercloud
beakerbrowser/hashbase
joehand/dat-now
mafintosh/hypercore-archiver-bot
joehand/hypercore-archiver-ws
datproject/dat-registry-api
datproject/dat-registry-client
Managing & Aggregating Dats
datproject/multidat
datproject/multidrive
jayrbolton/dat-pki
beakerbrowser/injestdb
Http Hosting
joehand/hyperdrive-http
beakerbrowser/dathttpd
Dat Link Utilties
datprotocol/dat-dns
joehand/dat-link-resolve
pfrazee/parse-dat-url
juliangruber/dat-encoding
Dat Utilities
joehand/dat-log
mafintosh/dat-ls
karissa/hyperhealth
joehand/hyperdrive-network-speed
File Imports & Exports
juliangruber/hyperdrive-import-files
mafintosh/mirror-folder
pfrazee/hyperdrive-staging-area
pfrazee/hyperdrive-to-zip-stream
Hypercore Tools
mafintosh/hyperpipe
Dat Core Modules
mafintosh/hyperdrive
mafintosh/hypercore
CLI Utilities
joehand/dat-doctor
joehand/dat-ignore
joehand/dat-json
Networking
karissa/hyperdiscovery
mafintosh/discovery-swarm
mafintosh/webrtc-swarm
joehand/dat-swarm-defaults
Lower level networking modules
maxogden/discovery-channel
mafintosh/dns-discovery
mafintosh/multicast-dns
webtorrent/bittorrent-dht
mafintosh/utp-native
mafintosh/signalhub
Storage
datproject/dat-storage
datproject/dat-secret-storage
Random Access
juliangruber/abstract-random-access
mafintosh/multi-random-access
mafintosh/random-access-file
mafintosh/random-access-memory
mafintosh/random-access-page-files
datproject/dat-http
substack/random-access-idb
Other Related Dat Project Modules
mafintosh/peer-network
mafintosh/hyperdht
Dat Project Organization Stuff
datproject/datproject.org
datproject/discussions
datproject/design
datproject/dat-elements
kriesse/dat-colors
kriesse/dat-icons
juliangruber/dat.json
Outdated
juliangruber/dat.haus
poga/hyperfeed
yoshuawuyts/normcore
yoshuawuyts/github-to-hypercore
poga/hyperspark
juliangruber/hypercore-index
juliangruber/hyperdrive-encoding
mafintosh/hyperdrive-http-server
joehand/hyperdrive-http
joehand/dat-push
joehand/dat-backup
joehand/archiver-server
joehand/archiver-api
poga/hyperdrive-ln
substack/hyperdrive-multiwriter
substack/hyperdrive-named-archives
substack/git-dat
CfABrigadePhiladelphia/jawn
maxogden/dat-archiver
juliangruber/hyperdrive-stats
karissa/hypercore-stats-server
mafintosh/hypercore-stats-ui
karissa/zip-to-hyperdrive
joehand/url-dat
joehand/tar-dat
joehand/hyperdrive-duplicate

mirror-folder

npm travis

Small module to mirror a folder to another folder.

Supports watch mode as well where it will continuously watch the src folder and mirror new entries as they are created/removed.

npm install mirror-folder

Usage

var mirror = require('mirror-folder')

mirror('/Users/maf/cool-stuff', '/Users/maf/cool-stuff-mirror', function (err) {
  if (err) throw err
  console.log('Folder was mirrored')
})

API

var progress = mirror(src, dst, [options], [callback])

Mirror src to dst. Returns a progress event emitter.

Options include:

{
  watch: false, // keep watching the src and mirror new entries,
  dereference: false, // dereference any symlinks
  equals: fun, // optional function to determine if two entries are the same, see below
  ignore: null, // optional function to ignore file paths on src or dest
  dryRun: false // emit all events but don't write/del files
}

The equals function looks like this:

function equals (src, dst, cb) {
  console.log('src.name', src.name)
  console.log('src.stat', src.stat)
  console.log('dst.name', dst.name)
  console.log('dst.stat', dst.stat)
  cb(null, true) // callback with true if they are the same or false if not
}

Per default the equals function will check if mtime is larger on the src entry or if the size is different

The ignore function looks like this:

function ignore (file) {
  // ignore any files with secret in them
  if (file.indexOf('secret') > -1) return true
  return false
}

If you are using a custom fs module (like graceful-fs) you can pass that in with the src or dst like this:

mirror({name: '/Users/maf/cool-stuff', fs: customFs}, {name: '/Users/maf/cool-stuff-mirror', fs: anotherFs})

progress.on('pending', {name, live})

Emitted when file/dir added to pending queue.

progress.pending

Array of items pending to be processed.

progress.on('put', src, dst)

Emitted when a file/folder is copied from the src to the dst folder.

progress.on('put-data', data)

Emitted when a file chunk is read from the src.

progress.on('put-end', src, dst)

Emitted at the end of a write stream (files only).

progress.on('del', dst)

Emitted when a file/folder is deleted from the dst folder.

progress.on('ignore', src, dst)

Emitted when a file/folder is ignored (either src or dst).

progress.on('skip', src, dst)

Emitted when a file/folder is skipped. Either src file already is equal to dst file or file does not exist in either place.

progress.on('end')

Emitted when the mirror ends (not emitted in watch mode). The mirror callback is called when this event is emitted as well

progress.on('error', err)

Emitted when a critical error happens. If you pass a mirror callback you don't need to listen for this.

progress.destory()

Stop mirroring files. If using watch mode, close the file watcher.

License

MIT