本文整理汇总了TypeScript中tar.x函数的典型用法代码示例。如果您正苦于以下问题:TypeScript x函数的具体用法?TypeScript x怎么用?TypeScript x使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了x函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: streamFrintExampleToDir
function streamFrintExampleToDir() {
request('https://codeload.github.com/frintjs/frint/tar.gz/master')
.on('error', deps.console.error)
.pipe(tar.x({
C: dir,
filter: path => path.indexOf(`frint-master/examples/${example}/`) === 0,
strip: 3,
}))
.on('error', deps.console.error)
.on('finish', () => deps.console.log('Done!'));
}
示例2: Promise
return new Promise((resolve, reject) => {
request(`https://codeload.github.com/${ctx.org}/${ctx.repo}/tar.gz/${ctx.branch}`)
.on('error', reject)
.pipe(tar.x({
C: ctx.outputDir,
filter: p => p.indexOf(`${ctx.repo}-${ctx.branch}/${ctx.examplePath}/`) === 0,
strip: 3,
}))
.on('error', reject)
.on('finish', () => resolve(ctx));
});
示例3: async
export const extractArchive = async (archive: Buffer, destination: string): Promise<string[]> => {
try {
if (!fse.existsSync(destination)) {
fse.mkdirSync(destination)
}
const buffStream = new stream.PassThrough()
const tarWriteStream = tar.x({ sync: true, strict: true, cwd: destination })
buffStream.end(archive)
buffStream.pipe(tarWriteStream)
await new Promise((resolve, reject) => {
tarWriteStream.on('end', resolve)
tarWriteStream.on('error', reject)
})
const files = await Promise.fromCallback<string[]>(cb => glob('**/*.*', { cwd: destination }, cb))
return files.map(filePath => forceForwardSlashes(filePath))
} catch (err) {
throw new VError(err, `[Archive] Error extracting archive to "${destination}"`)
}
}
示例4: reject
return new Promise<void>((resolve, reject) => {
this.$logger.trace(`Calling pacoteService.extractPackage for packageName: '${packageName}', destinationDir: '${destinationDirectory}' and options: ${options}`);
const source = pacote.tarball.stream(packageName, pacoteOptions);
source.on("error", (err: Error) => {
this.$logger.trace(`Error in source while trying to extract stream from ${packageName}. Error is ${err}`);
reject(err);
});
this.$logger.trace(`Creating extract tar stream with options: ${JSON.stringify(extractOptions, null, 2)}`);
const destination = tar.x(extractOptions);
source.pipe(destination);
destination.on("error", (err: Error) => {
this.$logger.trace(`Error in destination while trying to extract stream from ${packageName}. Error is ${err}`);
reject(err);
});
destination.on("finish", () => {
this.$logger.trace(`Successfully extracted '${packageName}' to ${destinationDirectory}`);
resolve();
});
});