mirror-folder
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 =
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, can also be a custom watch functiondereference: false // dereference any symlinksequals: fun // optional function to determine if two entries are the same, see belowignore: null // optional async function to ignore file paths on src or destdryRun: false // emit all events but don't write/del files,keepExisting: false // whether to delete extra files in the destination that are not present in the sourceskipSpecial: true // skip any files that are not regular files,ensureParents: false // ensure that all parent directories exist before creating children.
The equals function looks like this:
{consoleconsoleconsoleconsole// 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:
{// ignore any files with secret in themif file > -1 return processreturn process}
If you want to use a custom watch function on the src fs, the watch
option should take the form:
var { ... }
If you are using a custom fs module (like graceful-fs) you can pass that in
with the src
or dst
like this:
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.destroy()
Stop mirroring files. If using watch mode, close the file watcher.
License
MIT