Projekt

Obecné

Profil

Stáhnout (2 KB) Statistiky
| Větev: | Revize:
1
# move-concurrently
2

    
3
Move files and directories.
4

    
5
```
6
const move = require('move-concurrently')
7
move('/path/to/thing', '/new/path/thing').then(() => {
8
  // thing is now moved!
9
}).catch(err => {
10
  // oh no!
11
})
12
```
13

    
14
Uses `rename` to move things as fast as possible.
15

    
16
If you `move` across devices or on filesystems that don't support renaming
17
large directories.  That is, situations that result in `rename` returning
18
the `EXDEV` error, then `move` will fallback to copy + delete.
19

    
20
When recursively copying directories it will first try to rename the
21
contents before falling back to copying.  While this will be slightly slower
22
in true cross-device scenarios, it is MUCH faster in cases where the
23
filesystem can't handle directory renames.
24

    
25
When copying ownership is maintained when running as root.  Permissions are
26
always maintained.  On Windows, if symlinks are unavailable then junctions
27
will be used.
28

    
29
## INTERFACE
30

    
31
### move(from, to, options) → Promise
32

    
33
Recursively moves `from` to `to` and resolves its promise when finished.
34
If `to` already exists then the promise will be rejected with an `EEXIST`
35
error.
36

    
37
Starts by trying to rename `from` to `to`.
38

    
39
Options are:
40

    
41
* maxConcurrency – (Default: `1`) The maximum number of concurrent copies to do at once.
42
* isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
43
  an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
44
  fails then we'll try making a junction instead.
45

    
46
Options can also include dependency injection:
47

    
48
* Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
49
* fs - (Default: `require('fs')`) The filesystem module to use.  Can be used
50
  to use `graceful-fs` or to inject a mock.
51
* writeStreamAtomic - (Default: `require('fs-write-stream-atomic')`) The
52
  implementation of `writeStreamAtomic` to use.  Used to inject a mock.
53
* getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.
(2-2/4)