Better file copier
Self proclaimed better file copier then the rest.
Better file copier is a node package to allow you to copy a file or folder.
Yeah.... as simple as that...
But why bother making one?
Why?
- Because some major folder recursive copy package are unable to handle big file (greater than 0x1fffffe8 characters). Better Copy will copy anything regardless it size!
- Another file copier may hit your RAM harder the larger the file you copy. Better file copier will ensure that won't happen!
- More customize event on the process of copying, such as onBeforeCopy, or onAfterCopy, etc
- Options to switch into the OS' native file copy command
- Because I'm bored!
Usage
Bare minimum command :
const bCopy = require('better-copy');
bCopy('/path/to/your/moreThan2TBFiles.ext', '/path/to/destination/file.ext')
await bCopy('/path/to/your/moreThan2TBFiles.ext', '/path/to/destination/file.ext')
const bCopy = require('better-copy');
bCopy('/path/to/your/moreThan2TBFiles.ext', '/path/to/destination/file.ext',
(result) => {
console.log(result)
})
bCopy('/path/to/your/moreThan2TBFiles.ext', '/path/to/destination/file.ext')
.then((result) => {
console.log(result)
})
Resolved result is an iterable object containing pairs of source & destination path :
{
"/source/path/1" : [
"/destination/path/1",
"/destination/path/2"
...
]
"/source/path/2" : [...]
}
A single command to copy both file or folders :
const bCopy = require('better-copy');
bCopy('/path/to/your/file.txt', '/path/to/destination/folder');
bCopy('/path/to/your/folder', '/path/to/destination/folder');
Copy from & into multiple file/directory at once:
const bCopy = require('better-copy');
bCopy(['/path/to/your/folder1', '/path/to/some/file.txt'], '/path/to/destination/folder');
bCopy(['/path/to/your/folder1', '/path/to/some/file.txt'],
[
'/path/to/destination/folder',
'/path/to/other/folder'
]);
Get content of directory recursively
Walk a directory
const bCopy = require('better-copy');
var dirContent = await bCopy.walk("your/directory/path");
Walk a directory
const bCopy = require('better-copy');
bCopy.walk("your/directory/path", {
onFile : function(filepath, stats) {
console.log("File:", arguments);
},
onDir : function(filepath, stats) {
console.log("folder", arguments);
}
})
.then((folderContents) => {
console.log("Walk finished", folderContents)
})
Options
Default options
bCopy('/path/to/your/folder1', '/path/to/destination/folder',
{
filter:function(from, to) {
return true;
},
onAfterCopy : function(from, to) {},
onBeforeCopy : function(from, to) {},
overwrite : false,
useShell : false,
});
Filtering example
var path = require('path');
copy('F:/source/', ['F:/destination/'], {
filter:function(from, to) {
console.log("handling ", from);
if (path.extname(from).toLowerCase() == '.zip') {
console.log("extension is zip, skipping")
return true;
}
return false;
}
})
.then(function(result) {
console.log("Copied files :", result)
})
Example : onAfterCopy
bCopy('/path/to/your/folder1', '/path/to/destination/folder',
{
onAfterCopy : function(from, to) {
fs.unlink(from);
},
});
License
MIT License
Copyright (c) 2020 Dreamsaviors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.