本文整理匯總了TypeScript中fs-extra.mkdtemp函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mkdtemp函數的具體用法?TypeScript mkdtemp怎麽用?TypeScript mkdtemp使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mkdtemp函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: async
const withTempDirectory = async (fn: (dir: string) => Promise<void>) => {
const dir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-update-spec-'))
try {
await fn(dir)
} finally {
cp.spawnSync('rm', ['-r' , dir])
}
}
示例2: reject
return new Promise<string>((resolve, reject) => {
const tempDir = Path.join(Os.tmpdir(), `${name}-`)
Fs.mkdtemp(tempDir, (err, directory) => {
if (err) {
reject(err)
} else {
const fullPath = Path.join(directory, name)
resolve(fullPath)
}
})
})
示例3: it
it('should copy the electron dir to the build dir if everything is ok and enabled', async () => {
const electronDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-tmp-'));
await fs.writeFile(path.resolve(electronDir, 'electron'), 'hi i am electron I swear');
p.config.electronPath = electronDir;
const fn = p.getHook('packageAfterExtract')!;
await fn(null, tmpDir, null, process.platform, process.arch);
expect(await fs.pathExists(path.resolve(tmpDir, 'touch'))).to.equal(false);
expect(await fs.pathExists(path.resolve(tmpDir, 'electron'))).to.equal(true);
expect(await fs.readFile(path.resolve(tmpDir, 'electron'), 'utf8')).to.equal('hi i am electron I swear');
});
示例4: fn
export async function withTempDirectory<T>(fn: (directory: string) => Promise<T>): Promise<T> {
const directory = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-download-'));
let result: T;
try {
result = await fn(directory);
} catch (err) {
await fs.remove(directory);
throw err;
}
try {
await fs.remove(directory);
} catch {
// Ignore error, it's just a temp dir
}
return result;
}
示例5: Buffer
fs.fchmod(fd, modeNum, errorCallback);
fs.fchmod(fd, modeStr, errorCallback);
fs.fchmodSync(fd, modeNum);
fs.fchmodSync(fd, modeStr);
fs.lchmod(path, modeStr, errorCallback);
fs.lchmod(path, modeNum, errorCallback);
fs.lchmodSync(path, modeNum);
fs.lchmodSync(path, modeStr);
fs.statSync(path);
fs.lstatSync(path);
fs.read(0, new Buffer(""), 0, 0, null).then(x => {
const a = x.buffer;
const b = x.bytesRead;
});
fs.write(0, new Buffer(""), 0, 0, null).then(x => {
const a = x.buffer;
const b = x.bytesWritten;
});
// $ExpectType Promise<void>
fs.writeFile("foo.txt", "i am foo", { encoding: "utf-8" });
// $ExpectType Promise<string>
fs.mkdtemp("foo");
fs.copyFile("src", "dest").then();
fs.copyFile("src", "dest", fs.constants.COPYFILE_EXCL).then();
fs.copyFile("src", "dest", errorCallback);
示例6: before
before(async () => {
dir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-forge-test-'));
});
示例7: getTempFilePath
export async function getTempFilePath(name: string): Promise<string> {
const tempDir = Path.join(Os.tmpdir(), `${name}-`)
const directory = await FSE.mkdtemp(tempDir)
return Path.join(directory, name)
}
示例8: beforeEach
beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'forge-test-'));
await fs.writeFile(path.resolve(tmpDir, 'touch'), 'hey');
});
示例9: it
it('All Files with `--dest`', async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'eclint-'));
expect(tmpDir).to.be.ok.and.be.a('string');
const files = await eclint(['fix', '--dest', tmpDir]);
expect(files).to.have.length.above(10);
});
示例10: beforeEach
beforeEach(async () => {
cacheDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-download-spec-'));
cache = new Cache(cacheDir);
});