本文整理汇总了TypeScript中fs-extra.unlink函数的典型用法代码示例。如果您正苦于以下问题:TypeScript unlink函数的具体用法?TypeScript unlink怎么用?TypeScript unlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unlink函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('can commit when staged new file is then deleted', async () => {
let status,
files = null
const repo = await setupEmptyRepository()
const firstPath = path.join(repo.path, 'first')
const secondPath = path.join(repo.path, 'second')
await FSE.writeFile(firstPath, 'line1\n')
await FSE.writeFile(secondPath, 'line2\n')
await GitProcess.exec(['add', '.'], repo.path)
await FSE.unlink(firstPath)
status = await getStatusOrThrow(repo)
files = status.workingDirectory.files
expect(files.length).to.equal(1)
expect(files[0].path).to.contain('second')
expect(files[0].status).to.equal(AppFileStatus.New)
const toCommit = status.workingDirectory.withIncludeAllFiles(true)
await createCommit(repo, 'commit everything', toCommit.files)
status = await getStatusOrThrow(repo)
files = status.workingDirectory.files
expect(files).to.be.empty
const commit = await getCommit(repo, 'HEAD')
expect(commit).to.not.be.null
expect(commit!.summary).to.equal('commit everything')
})
示例2: Promise
return new Promise((resolve, reject) => {
unlink(filePath, (err: Error) => {
if (err) {
return reject(err);
}
return resolve();
});
});
示例3: it
it('returns empty when path is missing', async () => {
const repo = await setupEmptyRepository()
const path = Path.join(repo.path, '.git', 'description')
await FSE.unlink(path)
const actual = await getGitDescription(repo.path)
expect(actual).equals('')
})
示例4: reject
return new Promise<void>((resolve, reject) => {
fs.unlink(p, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
示例5: mkdirp
return Promise.all(IterableX.from(files).map(async ([newPath, newSource]) => {
const filePath = path.join(outDir, newPath);
await mkdirp(path.dirname(filePath));
if (newSource !== undefined) {
await fse.writeFile(filePath, newSource);
} else if (await fse.pathExists(filePath)) {
await fse.unlink(filePath);
}
}));
示例6: reject
fs.exists(path, exists => {
if (exists) {
// TODO: Should we check after unlinking to see if the file still exists?
fs.unlink(path, err => {
if (err) {
return reject(err);
}
resolve();
});
}
});
示例7: archiveAsync
await mio.usingAsync(seriesChapter.iteratorAsync(), async iterator => {
try {
await archiveAsync(chapter, iterator);
chapter.finalize();
await fs.rename(chapterPath + shared.extension.tmp, chapterPath);
console.log(`Finished ${seriesChapter.name} (${timer})`);
} catch (error) {
await fs.unlink(chapterPath + shared.extension.tmp);
throw error;
} finally {
chapter.abort();
}
});
示例8: clearVisitedPage
function clearVisitedPage(id) {
if (!visitedPages[id].pinned) {
io.emit("deleteKey", {
name: 'visitedPages',
key: id
});
if (visitedPages[id].progress == 100) {
// download completed but user requested to clear
// delete downloaded file
FILE.unlink(path.join(FILES_PATH, '../', visitedPages[id].path));
delete visitedPages[id];
} else {
// download is in progress
// partial file will be deleted by middleware function
visitedPages[id].cleared = true;
}
}
}
示例9: percentage
data.stream.on('data', (chunk) => {
downloadedLength += chunk.length;
var progress = percentage((downloadedLength / totalLength));
if (visitedPages[uniqid]) {
if (visitedPages[uniqid].cleared) { //download cancelled
stream.close();
FILE.unlink(completeFilePath); //delete incomplete file
delete visitedPages[uniqid];
io.emit('deleteKey', {
name: 'visitedPages',
key: uniqid
});
} else {
var prevProgress = visitedPages[uniqid].progress;
if ((progress - prevProgress) > 0.1 || progress == 100) { //don't clog the socket
visitedPages[uniqid].progress = progress;
visitedPages[uniqid].downloaded = prettyBytes(downloadedLength);
sendVisitedPagesUpdate(io, uniqid);
}
}
}
});
示例10: async
it.skip('resets discarded staged file', async () => {
const repoPath = repository!.path
const fileName = 'README.md'
const filePath = path.join(repoPath, fileName)
// modify the file
await FSE.writeFile(filePath, 'Hi world\n')
// stage the file, then delete it to mimic discarding
GitProcess.exec(['add', fileName], repoPath)
await FSE.unlink(filePath)
await resetPaths(repository!, GitResetMode.Mixed, 'HEAD', [filePath])
// then checkout the version from the index to restore it
await GitProcess.exec(
['checkout-index', '-f', '-u', '-q', '--', fileName],
repoPath
)
const status = await getStatusOrThrow(repository!)
expect(status.workingDirectory.files.length).to.equal(0)
})