@particle/tmp
Tools for working with temporary files and directories.
Installation
npm install @particle/tmp --save
const tmp = require('@particle/tmp');
API
@particle/tmp
-
@particle/tmp
-
static
-
.setGracefulCleanup ⇒
undefined
-
.createDir([options]) ⇒
Promise.<(TmpDir|Error)>
-
.createFile([options]) ⇒
Promise.<(TmpFile|Error)>
-
.setGracefulCleanup ⇒
-
inner
-
~TmpOptions :
Object
-
~TmpDir :
Object
-
~TmpFile :
Object
-
~TmpOptions :
-
static
undefined
tmp.setGracefulCleanup ⇒ Enables cleanup of temporary files even when an uncaught exception occurs
Kind: static property of @particle/tmp
Example
tmp.setGracefulCleanup();
Promise.<(TmpDir|Error)>
tmp.createDir([options]) ⇒ Create a new directory within the user's temp dir
Kind: static method of @particle/tmp
Returns: Promise.<(TmpDir|Error)>
- A resolved promise containing either info
about the newly created directory or an error
Param | Type | Description |
---|---|---|
[options] | TmpOptions |
Options object |
Example
const dir = await tmp.createDir();
dir.path; // '/path/to/the/new/tmp/dir'
await dir.cleanup(); // remove newly created temp directory
Promise.<(TmpFile|Error)>
tmp.createFile([options]) ⇒ Create a new file within the user's temp dir
Kind: static method of @particle/tmp
Returns: Promise.<(TmpFile|Error)>
- A resolved promise containing either info
about the newly created file or an error
Param | Type | Description |
---|---|---|
[options] | TmpOptions |
Options object |
Example
const file = await tmp.createFile();
file.fd; // 61344
file.path; // '/path/to/the/new/tmp/file'
await file.cleanup(); // remove newly created temp file
Object
@particle/tmp~TmpOptions : Kind: inner typedef of @particle/tmp
Properties
Name | Type | Default | Description |
---|---|---|---|
[mode] | string |
"0600" |
File mode to create with, uses 0600 on file creation and 0700 on directory creation by default |
[prefix] | string |
"particle-" |
Prefix assigned to created files and directories |
[dir] | string |
"<based on environment>" |
Temp directory location |
[tries] | number |
3 |
Number of times to try getting a unique filename before giving up |
[keep] | boolean |
false |
Retain the created temporary file or directory |
[unsafeCleanup] | boolean |
true |
Recursively remove the created temporary directory, even when it's not empty |
Object
@particle/tmp~TmpDir : Kind: inner typedef of @particle/tmp
Properties
Name | Type | Description |
---|---|---|
path | string |
Filename of newly created temp directory |
cleanup | function |
Function to call to remove newly created temp directory |
Object
@particle/tmp~TmpFile : Kind: inner typedef of @particle/tmp
Properties
Name | Type | Description |
---|---|---|
path | string |
Filename of newly created temp file |
fd | number |
File descriptor of newly created temp file |
cleanup | function |
Function to call to remove newly created temp file |
NOTE: Unfortunately, docs have a nasty habit of falling out of date. When in doubt, check usage in tests