Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# multiSync(method, files) | ||
|
||
[`copySync`](copy-sync.md) or [`moveSync`](move-sync.md) multiple files or directories. | ||
|
||
- `method` `<String>` Methods may be `copySync` or `moveSync`. | ||
- `files` `<Object>` Destinations, options and callback functions for each file. Each key of `<Object>` is referred to `src` (see: [`copySync`](copy-sync.md) or [`moveSync`](move-sync.md)). | ||
- `dest` `<String>` | ||
- `opts` `<Object>` | ||
- `overwrite` `<boolean>`: default is `true` for [`copySync`](copy-sync.md) or default is `false` for [`moveSync`](move-sync.md) | ||
- `errorOnExist` `<boolean>`: for [`copySync`](copy-sync.md) | ||
- `dereference` `<boolean>`: for [`copySync`](copy-sync.md) | ||
- `preserveTimestamps` `<boolean>`: for [`copySync`](copy-sync.md) | ||
- `filter` `<Function>`: for [`copySync`](copy-sync.md) | ||
|
||
## Example: | ||
|
||
```js | ||
const fs = require('fs-extra') | ||
|
||
let files = { | ||
'/tmp/myfile': { | ||
target: '/tmp/mynewfile' | ||
}, | ||
|
||
'/tmp/mysecondfile': { | ||
target: '/tmp/mysecondnewfile' | ||
} | ||
} | ||
|
||
fs.multiSync('copy', files) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# multi(method, files[, callback]) | ||
|
||
[`copy`](copy.md) or [`move`](move.md) multiple files or directories. | ||
|
||
- `method` `<String>` Methods may be `copy` or `move`. | ||
- `files` `<Object>` Destinations, options and callback functions for each file. Each key of `<Object>` is referred to `src` (see: [`copy`](copy.md) or [`move`](move.md)). | ||
- `dest` `<String>` | ||
- `opts` `<Object>` | ||
- `overwrite` `<boolean>`: default is `true` for [`copy`](copy.md) or default is `false` for [`move`](move.md) | ||
- `errorOnExist` `<boolean>`: fot [`copy`](copy.md) | ||
- `dereference` `<boolean>`: [`copy`](copy.md) | ||
- `preserveTimestamps` `<boolean>`: [`copy`](copy.md) | ||
- `filter` `<Function>`: [`copy`](copy.md) | ||
- `callback` `<Function>` | ||
- `callback` `<Function>` | ||
|
||
## Example: | ||
|
||
```js | ||
const fs = require('fs-extra') | ||
|
||
let files = { | ||
'/tmp/myfile': { | ||
target: '/tmp/mynewfile', | ||
callback: err => { | ||
if (err) console.error(err) | ||
else console.log('myfile success!') | ||
} | ||
}, | ||
|
||
'/tmp/mysecondfile': { | ||
target: '/tmp/mysecondnewfile' | ||
} | ||
} | ||
|
||
fs.multi('copy', files, () => console.log('multiple processes completed')) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
multiSync: require('./multi-sync') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fs = { | ||
copy: require('../copy-sync'), | ||
move: require('../move-sync') | ||
} | ||
|
||
const multiSync = (method, arr) => { | ||
for (const [src, prop] of Object.entries(arr)) { | ||
fs[method](src, prop.target, prop.opts) | ||
} | ||
} | ||
|
||
module.exports = multiSync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
multi: require('./multi') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const fs = { | ||
copy: require('../copy'), | ||
move: require('../move') | ||
} | ||
|
||
const multi = async function (method, files, callback) { | ||
for (const [src, prop] of Object.entries(files)) { | ||
if (typeof prop.callback !== 'function') prop.callback = err => { if (err) console.error(err) } | ||
await fs[method](src, prop.dest, prop.opts, prop.callback) | ||
} | ||
callback() | ||
} | ||
|
||
module.exports = multi |