New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fs-tools

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-tools - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

13

HISTORY.md

@@ -0,5 +1,12 @@

0.2.4 / 2012-08-19
------------------
* Added FsTools.move()
* Added FsTools.tmpdir()
0.2.3 / 2012-08-09
------------------
* Added removeSync method
* Added FsTools.removeSync() method

@@ -12,2 +19,3 @@

0.2.1 / 2012-02-09

@@ -18,2 +26,3 @@ ------------------

0.2.0 / 2012-02-08

@@ -25,2 +34,3 @@ ------------------

0.1.1 / 2012-02-06

@@ -31,2 +41,3 @@ ------------------

0.1.0 / 2011-11-24

@@ -33,0 +44,0 @@ ------------------

@@ -25,2 +25,3 @@ /**

var dirname = require('path').dirname;
var crypto = require('crypto');

@@ -506,1 +507,80 @@

};
/**
* FsTools.move(source, destination, callback) -> Void
* - source (String): Source filename
* - destination (String): Destination filename
*
* Moves file from `source` to `destination`.
**/
module.exports.move = function move(source, destination, callback) {
fs.lstat(source, function (err, stats) {
if (err) {
callback(err);
return;
}
fs.rename(source, destination, function (err) {
if (!err) {
callback();
return;
}
// TODO: Needs testing coverage
// normally err.code can be:
// - EXDEV (different partitions/devices)
// - ENOTEMPTY (source and destination are not-empty dirs)
// - EISDIR (destionation is dir, source is file)
async.series([
async.apply(fstools.copy, source, destination),
async.apply(fstools.remove, source)
], function (err/*, results*/) {
callback();
});
});
});
};
/**
* FsTools.tmpdir([template = /tmp/fstools.XXXXXX])
* - template (String): Temporary directory pattern.
*
* Returns non-existing (at the moment of request) temporary directory path.
* `template` must contain a substring with at least 3 consecutive `X`, that
* will be replaced with pseudo-random string of the same length.
*
*
* ##### Example
*
* fstools.tmpdir('/tmp/fooXXX'); // -> '/tmp/fooa2f'
* fstools.tmpdir('/tmp/fooXXX'); // -> '/tmp/foocb1'
* fstools.tmpdir('/tmp/foo-XXXXXX'); // -> '/tmp/foo-ad25e0'
**/
module.exports.tmpdir = function tmpdir(template) {
var match = (template || '/tmp/fstools.XXXXXX').match(/^(.*?)(X{3,})(.*?)$/),
attempts, length, random, pathname;
if (!match) {
throw new Error("Invalid tmpdir template: " + template);
}
attempts = 5;
length = match[2].length;
// Do not try more than attempts of times
while (attempts--) {
random = crypto.randomBytes(Math.ceil(length / 2)).toString('hex').substring(0, length);
pathname = (match[1] || '') + random + (match[3] || '');
if (!fs.existsSync(pathname)) {
// Generated pathname is uniq - return it
return pathname;
}
}
throw new Error("Failed to generate uniq tmpdir with template: " + template);
};

2

package.json
{
"name" : "fs-tools",
"version" : "0.2.3",
"version" : "0.2.4",
"description" : "fs helper utilities (walk, copy, mkdir -p)",

@@ -5,0 +5,0 @@ "keywords" : ["fs", "file", "utils"],

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc