本文整理汇总了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);
});