Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
wrench-sui
Advanced tools
Readme
While I love Node.js, I've found myself missing some functions. Things like recursively deleting/chmodding a directory (or even deep copying a directory), or even a basic line reader, shouldn't need to be re-invented time and time again.
That said, here's my attempt at a re-usable solution, at least until something more formalized gets integrated into Node.js (hint hint). wrench.js is fairly simple to use - check out the documentation/examples below:
In previous versions of Wrench, we went against the OS-default behavior of not deleting a directory unless the operation is forced. In 1.5.0, this has been changed to be the behavior people expect there to be - if you try to copy over a directory that already exists, you'll get an Error returned or thrown stating that you need to force it.
Something like this will do the trick:
wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up', {
forceDelete: true
});
If you desire the older behavior of Wrench... hit up your package.json. If you happen to find bugs in the 1.5.0 release please feel free to file them on the GitHub issues tracker for this project, or send me a pull request and I'll get to it as fast as I can. Thanks!
If this breaks enough projects I will consider rolling it back. Please hit me up if this seems to be the case.
npm install wrench
var wrench = require('wrench'),
util = require('util');
// Recursively create directories, sub-trees and all.
wrench.mkdirSyncRecursive(dir, 0777);
// Recursively delete the entire sub-tree of a directory, then kill the directory
wrench.rmdirSyncRecursive('my_directory_name', failSilently);
// Recursively read directories contents.
wrench.readdirSyncRecursive('my_directory_name');
// Recursively chmod the entire sub-tree of a directory
wrench.chmodSyncRecursive('my_directory_name', 0755);
// Recursively chown the entire sub-tree of a directory
wrench.chownSyncRecursive("directory", uid, gid);
// Deep-copy an existing directory
wrench.copyDirSyncRecursive('directory_to_copy', 'location_where_copy_should_end_up', {
forceDelete: bool, // Whether to overwrite existing directory or not
excludeHiddenUnix: bool, // Whether to copy hidden Unix files or not (preceding .)
preserveFiles: bool, // If we're overwriting something and the file already exists, keep the existing
preserveTimestamps: bool, // Preserve the mtime and atime when copying files
inflateSymlinks: bool, // Whether to follow symlinks or not when copying files
filter: regexpOrFunction, // A filter to match files against; if matches, do nothing (exclude).
whitelist: bool, // if true every file or directory which doesn't match filter will be ignored
include: regexpOrFunction, // An include filter (either a regexp or a function)
exclude: regexpOrFunction // An exclude filter (either a regexp or a function)
});
// Note: If a RegExp is provided then then it will be matched against the filename. If a function is
// provided then the signature should be the following:
// function(filename, dir) { return result; }
// Read lines in from a file until you hit the end
var f = new wrench.LineReader('x.txt');
while(f.hasNextLine()) {
util.puts(f.getNextLine());
}
// Note: You will need to close that above line reader at some point, otherwise
// you will run into a "too many open files" error. f.close() or fs.closeSync(f.fd) are
// your friends, as only you know when it is safe to close.
// Recursively read directories contents
var files = [];
wrench.readdirRecursive('my_directory_name', function(error, curFiles) {
// curFiles is what you want
});
// If you're feeling somewhat masochistic
wrench.copyDirRecursive(srcDir, newDir, {forceDelete: bool /* See sync version */}, callbackfn);
Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath)
FAQs
A forked version of wrenchjs that includes a critical recursive file fix. Credits to the original author(s) Ryan McGrath.
The npm package wrench-sui receives a total of 9,317 weekly downloads. As such, wrench-sui popularity was classified as popular.
We found that wrench-sui 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.