root / HServer / 00.Server / 00.Program / node_modules / ncp / README.md
이력 | 보기 | 이력해설 | 다운로드 (2.69 KB)
1 |
# ncp - Asynchronous recursive file & directory copying |
---|---|
2 |
|
3 |
[](http://travis-ci.org/AvianFlu/ncp) |
4 |
|
5 |
Think `cp -r`, but pure node, and asynchronous. `ncp` can be used both as a CLI tool and programmatically. |
6 |
|
7 |
## Command Line usage |
8 |
|
9 |
Usage is simple: `ncp [source] [dest] [--limit=concurrency limit] |
10 |
[--filter=filter] --stopOnErr` |
11 |
|
12 |
The 'filter' is a Regular Expression - matched files will be copied. |
13 |
|
14 |
The 'concurrency limit' is an integer that represents how many pending file system requests `ncp` has at a time. |
15 |
|
16 |
'stoponerr' is a boolean flag that will tell `ncp` to stop immediately if any |
17 |
errors arise, rather than attempting to continue while logging errors. The default behavior is to complete as many copies as possible, logging errors along the way. |
18 |
|
19 |
If there are no errors, `ncp` will output `done.` when complete. If there are errors, the error messages will be logged to `stdout` and to `./ncp-debug.log`, and the copy operation will attempt to continue. |
20 |
|
21 |
## Programmatic usage |
22 |
|
23 |
Programmatic usage of `ncp` is just as simple. The only argument to the completion callback is a possible error. |
24 |
|
25 |
```javascript |
26 |
var ncp = require('ncp').ncp; |
27 |
|
28 |
ncp.limit = 16; |
29 |
|
30 |
ncp(source, destination, function (err) { |
31 |
if (err) { |
32 |
return console.error(err); |
33 |
} |
34 |
console.log('done!'); |
35 |
}); |
36 |
``` |
37 |
|
38 |
You can also call ncp like `ncp(source, destination, options, callback)`. |
39 |
`options` should be a dictionary. Currently, such options are available: |
40 |
|
41 |
* `options.filter` - a `RegExp` instance, against which each file name is |
42 |
tested to determine whether to copy it or not, or a function taking single |
43 |
parameter: copied file name, returning `true` or `false`, determining |
44 |
whether to copy file or not. |
45 |
|
46 |
* `options.transform` - a function: `function (read, write) { read.pipe(write) }` |
47 |
used to apply streaming transforms while copying. |
48 |
|
49 |
* `options.clobber` - boolean=true. if set to false, `ncp` will not overwrite |
50 |
destination files that already exist. |
51 |
|
52 |
* `options.dereference` - boolean=false. If set to true, `ncp` will follow symbolic |
53 |
links. For example, a symlink in the source tree pointing to a regular file |
54 |
will become a regular file in the destination tree. Broken symlinks will result in |
55 |
errors. |
56 |
|
57 |
* `options.stopOnErr` - boolean=false. If set to true, `ncp` will behave like `cp -r`, |
58 |
and stop on the first error it encounters. By default, `ncp` continues copying, logging all |
59 |
errors and returning an array. |
60 |
|
61 |
* `options.errs` - stream. If `options.stopOnErr` is `false`, a stream can be provided, and errors will be written to this stream. |
62 |
|
63 |
Please open an issue if any bugs arise. As always, I accept (working) pull requests, and refunds are available at `/dev/null`. |