Comparing version 0.0.30 to 0.0.31
@@ -36,2 +36,5 @@ /*! | ||
EBADF = _c.EBADF || _c.os.errno.EBADF, | ||
ENOENT = _c.ENOENT || _c.os.errno.ENOENT, | ||
DIR_MODE = 448 /* 0700 */, | ||
@@ -224,2 +227,22 @@ FILE_MODE = 384 /* 0600 */, | ||
if (opts.discardDescriptor) { | ||
return fs.close(fd, function _discardCallback(err) { | ||
if (err) { | ||
// Low probability, and the file exists, so this could be | ||
// ignored. If it isn't we certainly need to unlink the | ||
// file, and if that fails too its error is more | ||
// important. | ||
try { | ||
fs.unlinkSync(name); | ||
} catch (e) { | ||
err = e; | ||
} | ||
return cb(err); | ||
} | ||
cb(null, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts)); | ||
}); | ||
} | ||
if (opts.detachDescriptor) { | ||
return cb(null, name, fd, _prepareTmpFileRemoveCallback(name, -1, opts)); | ||
} | ||
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts)); | ||
@@ -350,3 +373,5 @@ }); | ||
try { | ||
fs.closeSync(fdPath[0]); | ||
if (0 <= fdPath[0]) { | ||
fs.closeSync(fdPath[0]); | ||
} | ||
} | ||
@@ -357,3 +382,3 @@ catch (e) { | ||
// by the user, in which case we will simply ignore the error | ||
if (e.errno != -(_c.EBADF || _c.os.errno.EBADF) && e.errno != -(_c.ENOENT || _c.os.errno.ENOENT)) { | ||
if (e.errno != -EBADF && e.errno != -ENOENT) { | ||
// reraise any unanticipated error | ||
@@ -403,12 +428,13 @@ throw e; | ||
return function _cleanupCallback() { | ||
if (called) return; | ||
return function _cleanupCallback(next) { | ||
if (!called) { | ||
var index = _removeObjects.indexOf(_cleanupCallback); | ||
if (index >= 0) { | ||
_removeObjects.splice(index, 1); | ||
} | ||
var index = _removeObjects.indexOf(_cleanupCallback); | ||
if (index >= 0) { | ||
_removeObjects.splice(index, 1); | ||
called = true; | ||
removeFunction(arg); | ||
} | ||
called = true; | ||
removeFunction(arg); | ||
if (next) next(null); | ||
}; | ||
@@ -415,0 +441,0 @@ } |
{ | ||
"name": "tmp", | ||
"version": "0.0.30", | ||
"name": "tmp", | ||
"version": "0.0.31", | ||
"description": "Temporary file and directory creator", | ||
"author": "KARASZI István <github@spam.raszi.hu> (http://raszi.hu/)", | ||
"author": "KARASZI István <github@spam.raszi.hu> (http://raszi.hu/)", | ||
"keywords": [ | ||
"temporary", | ||
"tmp", | ||
"temp", | ||
"tempdir", | ||
"tempfile", | ||
"tmpdir", | ||
"tmpfile" | ||
], | ||
"license": "MIT", | ||
"repository": "raszi/node-tmp", | ||
"homepage": "http://github.com/raszi/node-tmp", | ||
"keywords": [ "temporary", "tmp", "temp", "tempdir", "tempfile", "tmpdir", "tmpfile" ], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/raszi/node-tmp.git" | ||
}, | ||
"bugs": { | ||
"url": "http://github.com/raszi/node-tmp/issues" | ||
}, | ||
"main": "lib/tmp.js", | ||
"scripts": { | ||
"test": "vows test/*-test.js" | ||
}, | ||
"engines": { | ||
"node": ">=0.4.0" | ||
}, | ||
"dependencies": { | ||
"os-tmpdir": "~1.0.1" | ||
}, | ||
"devDependencies": { | ||
"vows": "~0.7.0" | ||
}, | ||
"main": "lib/tmp.js", | ||
"files": ["lib/"], | ||
"scripts": { | ||
"test": "vows test/*-test.js" | ||
} | ||
} |
@@ -167,2 +167,41 @@ # Tmp | ||
### Controlling the Descriptor | ||
As a side effect of creating a unique file `tmp` gets a file descriptor that is | ||
returned to the user as the `fd` parameter. The descriptor may be used by the | ||
application and is closed when the `removeCallback` is invoked. | ||
In some use cases the application does not need the descriptor, needs to close it | ||
without removing the file, or needs to remove the file without closing the | ||
descriptor. Two options control how the descriptor is managed: | ||
* `discardDescriptor` - if `true` causes `tmp` to close the descriptor after the file | ||
is created. In this case the `fd` parameter is undefined. | ||
* `detachDescriptor` - if `true` causes `tmp` to return the descriptor in the `fd` | ||
parameter, but it is the application's responsibility to close it when it is no | ||
longer needed. | ||
```javascript | ||
var tmp = require('tmp'); | ||
tmp.file({ discardDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) { | ||
if (err) throw err; | ||
// fd will be undefined, allowing application to use fs.createReadStream(path) | ||
// without holding an unused descriptor open. | ||
}); | ||
``` | ||
```javascript | ||
var tmp = require('tmp'); | ||
tmp.file({ detachDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) { | ||
if (err) throw err; | ||
cleanupCallback(); | ||
// Application can store data through fd here; the space used will automatically | ||
// be reclaimed by the operating system when the descriptor is closed or program | ||
// terminates. | ||
}); | ||
``` | ||
### Asynchronous directory creation | ||
@@ -169,0 +208,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
308
2
21920
4
417