本文整理汇总了TypeScript中tar-fs.extract函数的典型用法代码示例。如果您正苦于以下问题:TypeScript extract函数的具体用法?TypeScript extract怎么用?TypeScript extract使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了extract函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: unTarGz
private async unTarGz(zipLocation: string, unzipLocation: string): Promise<void> {
return Promise.resolve(
fs
.createReadStream(zipLocation)
.pipe(zlib.createGunzip())
.pipe(tar.extract(unzipLocation))
);
}
示例2: downloadJDK
https.get(url, (res) => {
if (res.statusCode === 302) {
// Redirected.
ended = true;
downloadJDK(res.headers['location'], destPath, cb);
return;
}
// Will be NaN if not given by server.
let contentLength = parseInt(res.headers['content-length']);
let progressBytes = 0;
let startTime = new Date().getTime();
function printStatus() {
let percent = "??";
if (!isNaN(contentLength)) {
percent = ((progressBytes/contentLength)*100).toFixed(0);
}
let lastPrint = new Date().getTime();
// bytes => kbytes
let dlSoFar = progressBytes >> 10;
let rate = dlSoFar / ((lastPrint - startTime) / 1000);
console.log(`[${percent}%] Received ${dlSoFar} KB [${rate.toFixed(2)} KB/s]`);
}
let interval = setInterval(function() {
printStatus();
}, 5000);
function end(err?: Error) {
if (!ended) {
ended = true;
clearInterval(interval);
cb(err);
}
}
res.pipe(gunzip()).pipe(tarFs.extract(destPath)).on('error', end).on('finish', end);
res.on('data', (d: Buffer) => {
progressBytes += d.length;
});
}).on('error', (err: Error) => {
示例3: resolve
.on('response', response => {
if (response.statusCode === 200) {
stream
.pipe(zlib.createGunzip())
.pipe(tar.extract(destination, {
map: header => {
header.name = header.name.substring(header.name.indexOf('/'));
return header;
}
}))
.on('finish', () => {
resolve(destination);
stream.destroy();
Logger.info(`Downloaded ${url} successfuly.`);
});
} else {
reject(`Failed to download ${url}. Status code: ${response.statusCode}.`);
stream.destroy();
}
});