
Security News
Node.js Moves Toward Stable TypeScript Support with Amaro 1.0
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
better-copy
Advanced tools
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?
Bare minimum command :
const bCopy = require('better-copy');
//bCopy(from, to, options, callback)
bCopy('/path/to/your/moreThan2TBFiles.ext', '/path/to/destination/file.ext')
// the process is asynchronous
await bCopy('/path/to/your/moreThan2TBFiles.ext', '/path/to/destination/file.ext')
const bCopy = require('better-copy');
//use callback instead of the default promise
bCopy('/path/to/your/moreThan2TBFiles.ext', '/path/to/destination/file.ext',
(result) => {
console.log(result)
})
//...is equal with :
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');
// copy file to a directory, assuming the same file name
bCopy('/path/to/your/file.txt', '/path/to/destination/folder');
// copy directory recursively
bCopy('/path/to/your/folder', '/path/to/destination/folder');
Copy from & into multiple file/directory at once:
const bCopy = require('better-copy');
// use an array as parameter for more than one input path
bCopy(['/path/to/your/folder1', '/path/to/some/file.txt'], '/path/to/destination/folder');
// Copy some file from multiple source into multiple directory
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');
// use an array as parameter for more than one input path
bCopy.walk("your/directory/path", {
onFile : function(filepath, stats) {
// when meet a file
console.log("File:", arguments);
},
onDir : function(filepath, stats) {
// when meet a folder
console.log("folder", arguments);
}
})
.then((folderContents) => {
// the recursive content of folder in array format
console.log("Walk finished", folderContents)
})
Default options
// The default value of the options parameter
bCopy('/path/to/your/folder1', '/path/to/destination/folder',
{
filter:function(from, to) {
// return false to exclude
// return true to include
return true;
},
onAfterCopy : function(from, to) {},
onBeforeCopy : function(from, to) {},
overwrite : false, // will overwrite the target if set true
useShell : false, // use shell copy if possible (not all OS are supported)
});
Filtering example
// Copy only the zip file
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
// delete source file after successfull copy (aka: move)
bCopy('/path/to/your/folder1', '/path/to/destination/folder',
{
onAfterCopy : function(from, to) {
fs.unlink(from);
},
});
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.
FAQs
Huge files & directory copier
The npm package better-copy receives a total of 11 weekly downloads. As such, better-copy popularity was classified as not popular.
We found that better-copy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.