README.md~ 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # move-concurrently
  2. Move files and directories.
  3. ```
  4. const move = require('move-concurrently')
  5. move('/path/to/thing', '/new/path/thing'), err => {
  6. if (err) throw err
  7. // thing is now moved!
  8. })
  9. ```
  10. Uses `rename` to move things as fast as possible.
  11. If you `move` across devices or on filesystems that don't support renaming
  12. large directories. That is, situations that result in `rename` returning
  13. the `EXDEV` error, then `move` will fallback to copy + delete.
  14. When recursively copying directories it will first try to rename the
  15. contents before falling back to copying. While this will be slightly slower
  16. in true cross-device scenarios, it is MUCH faster in cases where the
  17. filesystem can't handle directory renames.
  18. When copying ownership is maintained when running as root. Permissions are
  19. always maintained. On Windows, if symlinks are unavailable then junctions
  20. will be used.
  21. ## INTERFACE
  22. ### move(from, to, options) → Promise
  23. Recursively moves `from` to `to` and resolves its promise when finished.
  24. If `to` already exists then the promise will be rejected with an `EEXIST`
  25. error.
  26. Starts by trying to rename `from` to `to`.
  27. Options are:
  28. * maxConcurrency – (Default: `1`) The maximum number of concurrent copies to do at once.
  29. * isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
  30. an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
  31. fails then we'll try making a junction instead.
  32. Options can also include dependency injection:
  33. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  34. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  35. to use `graceful-fs` or to inject a mock.
  36. * writeStreamAtomic - (Default: `require('fs-write-stream-atomic')`) The
  37. implementation of `writeStreamAtomic` to use. Used to inject a mock.
  38. * getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.