XuelesszzZ 94af2b8e7b 6-30-5 | hace 1 año | |
---|---|---|
.. | ||
lib | hace 1 año | |
node_modules | hace 1 año | |
LICENSE.md | hace 1 año | |
README.md | hace 1 año | |
package.json | hace 1 año |
polyfills, and extensions, of the core fs
module.
fs.rm
polyfill for node versions < 14.14.0fs.mkdir
polyfill adding support for the recursive
and force
options in node versions < 10.12.0fs.copyFile
extended to accept an owner
optionfs.mkdir
extended to accept an owner
optionfs.mkdtemp
extended to accept an owner
optionfs.writeFile
extended to accept an owner
optionfs.withTempDir
addedfs.cp
polyfill for node < 16.7.0owner
optionThe copyFile
, mkdir
, mkdtemp
, writeFile
, and withTempDir
functions
all accept a new owner
property in their options. It can be used in two ways:
{ owner: { uid: 100, gid: 100 } }
- set the uid
and gid
explicitly{ owner: 100 }
- use one value, will set both uid
and gid
the sameThe special string 'inherit'
may be passed instead of a number, which will
cause this module to automatically determine the correct uid
and/or gid
from the nearest existing parent directory of the target.
fs.withTempDir(root, fn, options) -> Promise
root
: the directory in which to create the temporary directoryfn
: a function that will be called with the path to the temporary directoryoptions
tmpPrefix
: a prefix to be used in the generated directory nameThe withTempDir
function creates a temporary directory, runs the provided
function (fn
), then removes the temporary directory and resolves or rejects
based on the result of fn
.
const fs = require('@npmcli/fs')
const os = require('os')
// this function will be called with the full path to the temporary directory
// it is called with `await` behind the scenes, so can be async if desired.
const myFunction = async (tempPath) => {
return 'done!'
}
const main = async () => {
const result = await fs.withTempDir(os.tmpdir(), myFunction)
// result === 'done!'
}
main()