Callback method can be used by tempDir
when you don't want to return a Promise.
Options used by tempDir
to create a temporary directory with files
Callback method can be used by tempDirWithFiles
when you don't want to return a Promise.
Options used by tempFileOfSize
call, see description of the method.
Callback method can be used by tempFile
when you don't want to return a Promise.
This is a rewrite of the GoLang os.TempDir method, with additional functionality.
tempDir
creates a new temporary directory in the directory dir. The directory name is generated by taking
pattern and applying a random string to the end. If pattern includes a "*", the random string replaces the last "*".
tempDir
returns the name of the new directory. If dir is the empty string, tempDir
uses the default directory for
temporary files (see os.tmpdir()). Multiple programs calling tempDir
simultaneously will not choose the same
directory. It is the caller's responsibility to remove the directory when no longer needed.
If options.default
is set to true
in the options
argument, tempDir
will make use of NodeJs's
fs.promises.mkdtemp method, giving as
prefix
the options.pattern
value (which becomes mandatory).
// will create a temporary file using the OS temporary
// folder and a random token as filename
const fh = tempDir()
// will create a temporary file using the OS temporary
// folder and a random token prefixed by 'tempjs_' as filename
const fh = tempDir({ patern: 'tempjs_' })
// will create a temporary file using the OS temporary
// folder and a random token prefixed by 'tempjs_' and
// suffixed by '.txt' as filename
const fh = tempDir({ patern: 'tempjs_*.txt' })
optional
optional
Returns Promise if callback is not defined, void if callback is defined.
tempDirWithFiles
creates a new temporary directory in the directory dir. New directory will recursively contain
other a max of options.maxSubFolders
(can be randomized) directories to max depth of options.maxDepth
(can
be randomized). Also, each folder will contain a maximum number of options.maxFilesPerDir
(can be randomized),
each file having the max size of options.maxFileSize
(can be randomized).
To randomize values, set options.randomize
to true.
For the main parent folder, function will also inherit the parameters of tempDir
.
Will return a touple of values where:
optional
optional
Returns Promise if callback is not defined, void if callback is defined.
This is a rewrite of the GoLang os.TempFile method, with additional functionality.
tempFile creates a new temporary file in the directory dir, opens the file for reading and writing, and returns the
resulting FileHandle
. The filename is generated by taking pattern and adding a random string to the end. If
pattern includes a "*", the random string replaces the last "*". If dir is the empty string, tempFile
uses the
default directory for temporary files (see os.tmpdir()
). Multiple programs calling tempFile
simultaneously
will not choose the same file. The caller can use f.name to find the pathname of the file. It is the caller's
responsibility to remove the file when no longer needed.
// will create a temporary file using the OS temporary
// folder and a random token as filename
const fh = tempFile()
// will create a temporary file using the OS temporary
// folder and a random token prefixed by 'tempjs_' as filename
const fh = tempFile({ patern: 'tempjs_' })
// will create a temporary file using the OS temporary
// folder and a random token prefixed by 'tempjs_' and
// suffixed by '.txt' as filename
const fh = tempFile({ patern: 'tempjs_*.txt' })
Optional
Optional
Returns Promise if callback is not defined, void if callback is defined.
tempFileOfSize behaves exactly like tempFile
, however it will write random data in the file, of a mentioned size.
It is developer's responsibility to make sure size input is correct. See: https://www.npmjs.com/package/bytes for
behavior. File's write/read cursor will be at the end of file.
// will create a temporary file of 50Mb
const fh = tempFileOfSize({ size: '50Mb' })
Optional
Optional
Returns Promise if callback is not defined, void if callback is defined.
Generated using TypeDoc
Options used by
tempDir
to create a temporary directory