Skip to content

Commit 486205b

Browse files
committed
fix #240
replace var by const
1 parent 0664e9a commit 486205b

File tree

6 files changed

+336
-612
lines changed

6 files changed

+336
-612
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## tmp v0.2.0
44

5-
- drop support for node version < v8
5+
- drop support for node version < v8.17.0
66

77
***BREAKING CHANGE***
88

9-
node version < v8 are no longer supported.
9+
node versions < v8.17.0 are no longer supported.
1010

1111
- [#216](https://github.com/raszi/node-tmp/issues/216)
1212

@@ -63,6 +63,12 @@
6363

6464
now using rimraf for removing directory trees.
6565

66+
- [#240](https://github.com/raszi/node-tmp/issues/240)
67+
68+
***DOCUMENTATION***
69+
70+
better documentation for `tmp.setGracefulCleanup()`.
71+
6672
- [#206](https://github.com/raszi/node-tmp/issues/206)
6773

6874
***DOCUMENTATION***
@@ -93,6 +99,7 @@
9399

94100
document unsafeCleanup option.
95101

102+
96103
### Miscellaneous
97104

98105
- stabilized tests

README.md

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ dependency to version 0.0.33.
5050
For node versions < 0.8 you must limit your node-tmp dependency to
5151
versions < 0.0.33.
5252

53-
### Node Versions < 8.12.0
54-
55-
The SIGINT handler will not work correctly with versions of NodeJS < 8.12.0.
56-
57-
### Windows
58-
59-
Signal handlers for SIGINT will not work. Pressing CTRL-C will leave behind
60-
temporary files and directories.
61-
6253
## How to install
6354

6455
```bash
@@ -74,7 +65,7 @@ Please also check [API docs][4].
7465
Simple temporary file creation, the file will be closed and unlinked on process exit.
7566

7667
```javascript
77-
var tmp = require('tmp');
68+
const tmp = require('tmp');
7869

7970
tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
8071
if (err) throw err;
@@ -94,9 +85,9 @@ tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
9485
A synchronous version of the above.
9586

9687
```javascript
97-
var tmp = require('tmp');
88+
const tmp = require('tmp');
9889

99-
var tmpobj = tmp.fileSync();
90+
const tmpobj = tmp.fileSync();
10091
console.log('File: ', tmpobj.name);
10192
console.log('Filedescriptor: ', tmpobj.fd);
10293

@@ -117,7 +108,7 @@ Simple temporary directory creation, it will be removed on process exit.
117108
If the directory still contains items on process exit, then it won't be removed.
118109

119110
```javascript
120-
var tmp = require('tmp');
111+
const tmp = require('tmp');
121112

122113
tmp.dir(function _tempDirCreated(err, path, cleanupCallback) {
123114
if (err) throw err;
@@ -137,9 +128,9 @@ you can pass the `unsafeCleanup` option when creating it.
137128
A synchronous version of the above.
138129

139130
```javascript
140-
var tmp = require('tmp');
131+
const tmp = require('tmp');
141132

142-
var tmpobj = tmp.dirSync();
133+
const tmpobj = tmp.dirSync();
143134
console.log('Dir: ', tmpobj.name);
144135
// Manual cleanup
145136
tmpobj.removeCallback();
@@ -155,7 +146,7 @@ It is possible with this library to generate a unique filename in the specified
155146
directory.
156147

157148
```javascript
158-
var tmp = require('tmp');
149+
const tmp = require('tmp');
159150

160151
tmp.tmpName(function _tempNameGenerated(err, path) {
161152
if (err) throw err;
@@ -169,9 +160,9 @@ tmp.tmpName(function _tempNameGenerated(err, path) {
169160
A synchronous version of the above.
170161

171162
```javascript
172-
var tmp = require('tmp');
163+
const tmp = require('tmp');
173164

174-
var name = tmp.tmpNameSync();
165+
const name = tmp.tmpNameSync();
175166
console.log('Created temporary filename: ', name);
176167
```
177168

@@ -182,9 +173,9 @@ console.log('Created temporary filename: ', name);
182173
Creates a file with mode `0644`, prefix will be `prefix-` and postfix will be `.txt`.
183174

184175
```javascript
185-
var tmp = require('tmp');
176+
const tmp = require('tmp');
186177

187-
tmp.file({ mode: 0644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileCreated(err, path, fd) {
178+
tmp.file({ mode: 0o644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileCreated(err, path, fd) {
188179
if (err) throw err;
189180

190181
console.log('File: ', path);
@@ -197,9 +188,9 @@ tmp.file({ mode: 0644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileC
197188
A synchronous version of the above.
198189

199190
```javascript
200-
var tmp = require('tmp');
191+
const tmp = require('tmp');
201192

202-
var tmpobj = tmp.fileSync({ mode: 0644, prefix: 'prefix-', postfix: '.txt' });
193+
const tmpobj = tmp.fileSync({ mode: 0o644, prefix: 'prefix-', postfix: '.txt' });
203194
console.log('File: ', tmpobj.name);
204195
console.log('Filedescriptor: ', tmpobj.fd);
205196
```
@@ -221,7 +212,7 @@ descriptor. Two options control how the descriptor is managed:
221212
longer needed.
222213

223214
```javascript
224-
var tmp = require('tmp');
215+
const tmp = require('tmp');
225216

226217
tmp.file({ discardDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
227218
if (err) throw err;
@@ -231,7 +222,7 @@ tmp.file({ discardDescriptor: true }, function _tempFileCreated(err, path, fd, c
231222
```
232223

233224
```javascript
234-
var tmp = require('tmp');
225+
const tmp = require('tmp');
235226

236227
tmp.file({ detachDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {
237228
if (err) throw err;
@@ -248,9 +239,9 @@ tmp.file({ detachDescriptor: true }, function _tempFileCreated(err, path, fd, cl
248239
Creates a directory with mode `0755`, prefix will be `myTmpDir_`.
249240

250241
```javascript
251-
var tmp = require('tmp');
242+
const tmp = require('tmp');
252243

253-
tmp.dir({ mode: 0750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path) {
244+
tmp.dir({ mode: 0o750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path) {
254245
if (err) throw err;
255246

256247
console.log('Dir: ', path);
@@ -262,9 +253,9 @@ tmp.dir({ mode: 0750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path)
262253
Again, a synchronous version of the above.
263254

264255
```javascript
265-
var tmp = require('tmp');
256+
const tmp = require('tmp');
266257

267-
var tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
258+
const tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
268259
console.log('Dir: ', tmpobj.name);
269260
```
270261

@@ -277,7 +268,7 @@ require tmp to create your temporary filesystem object in a different place than
277268
default `tmp.tmpdir`.
278269

279270
```javascript
280-
var tmp = require('tmp');
271+
const tmp = require('tmp');
281272

282273
tmp.dir({ template: 'tmp-XXXXXX' }, function _tempDirCreated(err, path) {
283274
if (err) throw err;
@@ -291,9 +282,9 @@ tmp.dir({ template: 'tmp-XXXXXX' }, function _tempDirCreated(err, path) {
291282
This will behave similarly to the asynchronous version.
292283

293284
```javascript
294-
var tmp = require('tmp');
285+
const tmp = require('tmp');
295286

296-
var tmpobj = tmp.dirSync({ template: 'tmp-XXXXXX' });
287+
const tmpobj = tmp.dirSync({ template: 'tmp-XXXXXX' });
297288
console.log('Dir: ', tmpobj.name);
298289
```
299290

@@ -305,9 +296,9 @@ The function accepts all standard options, e.g. `prefix`, `postfix`, `dir`, and
305296
You can also leave out the options altogether and just call the function with a callback as first parameter.
306297

307298
```javascript
308-
var tmp = require('tmp');
299+
const tmp = require('tmp');
309300

310-
var options = {};
301+
const options = {};
311302

312303
tmp.tmpName(options, function _tempNameGenerated(err, path) {
313304
if (err) throw err;
@@ -322,19 +313,22 @@ The `tmpNameSync()` function works similarly to `tmpName()`.
322313
Again, you can leave out the options altogether and just invoke the function without any parameters.
323314

324315
```javascript
325-
var tmp = require('tmp');
326-
var options = {};
327-
var tmpname = tmp.tmpNameSync(options);
316+
const tmp = require('tmp');
317+
const options = {};
318+
const tmpname = tmp.tmpNameSync(options);
328319
console.log('Created temporary filename: ', tmpname);
329320
```
330321

331322
## Graceful cleanup
332323

333-
One may want to cleanup the temporary files even when an uncaught exception
334-
occurs. To enforce this, you can call the `setGracefulCleanup()` method:
324+
If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the
325+
temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary
326+
object removal.
327+
328+
To enforce this, you can call the `setGracefulCleanup()` method:
335329

336330
```javascript
337-
var tmp = require('tmp');
331+
const tmp = require('tmp');
338332

339333
tmp.setGracefulCleanup();
340334
```

0 commit comments

Comments
 (0)