tmp-promise
Advanced tools
Comparing version
{ | ||
"name": "tmp-promise", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "The tmp package with promises support and disposers.", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
"bluebird": "^3.5.0", | ||
"tmp": "0.0.33" | ||
"tmp": "0.1.0" | ||
}, | ||
@@ -28,0 +28,0 @@ "devDependencies": { |
@@ -5,3 +5,3 @@ # tmp-promise | ||
The [tmp](https://github.com/raszi/node-tmp) package with promises support. | ||
The [tmp](https://github.com/raszi/node-tmp) package with promises support. If you want to use `tmp` with `async/await` then this helper might be for you. | ||
@@ -33,2 +33,16 @@ This documentation is mostly copied from that package's - but with promise usage instead of callback usage adapted. | ||
With Node.js 10 and es - modules: | ||
```js | ||
import { file } from 'tmp-promise' | ||
(async () => { | ||
const {fd, path, cleanup} = await file(); | ||
// work with file here in fd | ||
cleanup(); | ||
})(); | ||
``` | ||
Or the older way: | ||
```javascript | ||
@@ -50,3 +64,16 @@ var tmp = require('tmp-promise'); | ||
With Node.js 10 and es - modules: | ||
```js | ||
import { withFile } from 'tmp-promise' | ||
withFile(async ({path, fd}) => { | ||
// when this function returns or throws - release the file | ||
await doSomethingWithFile(db); | ||
}); | ||
``` | ||
Or the older way: | ||
```js | ||
tmp.withFile(o => { | ||
@@ -53,0 +80,0 @@ console.log("File: ", o.path); |
var accessSync = require('fs').accessSync | ||
var assert = require('assert') | ||
var extname = require('path').extname | ||
var existsSync = require('fs').existsSync | ||
@@ -20,3 +21,3 @@ var tmp = require('.') | ||
assert.strictEqual(extname(filepath), '.txt') | ||
}, {postfix: '.txt'}) | ||
}, {discardDescriptor: true, postfix: '.txt'}) | ||
.then(function() | ||
@@ -23,0 +24,0 @@ { |
13041
4.41%309
9.57%6
-14.29%118
-0.84%2
100%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated