本文整理匯總了TypeScript中archiver類的典型用法代碼示例。如果您正苦於以下問題:TypeScript archiver類的具體用法?TypeScript archiver怎麽用?TypeScript archiver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了archiver類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createZip
// Create a zip file of the fixture data using the given zlib compression level.
function createZip(level: number): void {
const output = fs.createWriteStream(`${outputFolder}/zipfs_fixtures_l${level}.zip`);
const options = { zlib: { level: level } };
const archive = archiver('zip', options);
archive.on('error', (err: any) => {
throw err;
});
archive.pipe(output);
addFolder(archive, srcFolder);
archive.finalize();
}
示例2: send_zip
function send_zip(path: string, name: string, res: express.Response){
res.setHeader('Content-disposition', 'attachment; filename='+name+'.zip');
res.setHeader('Content-type', 'application/zip');
let archive = archiver('zip');
archive.on('error', (e: Error) => {
socket_manager.broadcast('report-error', e);
res.end();
});
archive.pipe(res);
archive.directory(path, name, {name: name+'.zip'});
archive.finalize();
}
示例3: Promise
return new Promise((resolve, reject) => {
this.out.action.start(`Zipping export`)
const before = Date.now()
const archive = archiver('zip')
archive.directory(this.exportDir, false)
const output = fs.createWriteStream(this.exportPath)
archive.pipe(output)
output.on('close', () => {
console.log(archive.pointer() + ' total bytes')
this.out.action.stop(chalk.cyan(`${Date.now() - before}ms`))
resolve()
})
archive.finalize()
})
示例4: archiver
let finalBuffer = await new Promise<Buffer>((resolve, reject) => {
let archive = archiver('zip');
archive.on('warning', function (err: any) {
if (err.code === 'ENOENT') {
console.log(err);
} else {
// throw error
reject(err);
}
});
archive.on('data', data => buffers.push(data));
archive.on('error', reject);
archive.on('end', () => resolve(Buffer.concat(buffers)));
filesToAdd.forEach(elem => archive.append(elem.content, { name: elem.path }));
archive.finalize();
});
示例5: asyncUploadWorkspaceDump
private asyncUploadWorkspaceDump(url: string) {
const storagePath = this.ctx.extensionContext.storagePath
// TODO: handle multi-root workspaces
const rootPath = vscode.workspace.rootPath
if (storagePath === undefined || rootPath === undefined) {
this.logError('Cannot start workspace dump b/c of workspace state:', { storagePath, rootPath })
return
}
if (!fs.existsSync(storagePath)) fs.mkdirSync(storagePath)
const outputPath = path.join(storagePath, 'workspace-dump.zip')
if (fs.existsSync(outputPath)) fs.unlinkSync(outputPath)
const output = fs.createWriteStream(outputPath)
const zip = archiver('zip')
zip.on('error', (err) => this.logError('zip error', safeError(err)))
zip.on('warning', (err) => this.logError('zip warning', safeError(err)))
zip.on('finish', () => {
this.ctx.extensionOut.appendLine('zip - finished')
fs.createReadStream(outputPath).pipe(
request.put(url, {
qs: {
client: this.machineId,
project: this.projectId,
session: this.sessionId
}
})
.on('error', (err) => this.logError('zip upload connection error', url, safeError(err)))
.on('complete', (resp) => {
if (!(resp.statusCode >= 200 && resp.statusCode < 300)) {
this.logError('zip upload http error', url, resp.statusCode, resp.body)
} else {
this.ctx.extensionOut.appendLine('zip - http upload finished')
}
})
)
})
this.ctx.extensionOut.appendLine('zip - starting')
zip.pipe(output)
zip.glob('./**/*.{scala,sc,sbt,java}', { cwd: rootPath })
zip.glob('./**/.dotty-ide{.json,-artifact}', { cwd: rootPath })
zip.finalize()
}
示例6: Promise
return new Promise((resolve, reject) => {
output.on('close', function () {
resolve(); // the installer needs to wait for the filestream to be closed here
});
let archive = archiver('zip');
archive.on('warning', function (err: any) {
if (err.code === 'ENOENT') {
console.log(err);
} else {
// throw error
reject(err);
}
});
archive.on('error', reject);
archive.pipe(output);
filesToAdd.forEach(elem => archive.append(elem.content, { name: elem.path }));
archive.finalize();
});
示例7: zipAll
static async zipAll(): Promise<Buffer> {
const zipPath = path.join(__dirname, '../global_data');
const zipFile = `${zipPath}.zip`;
if (fs.existsSync(zipFile)) {
fs.unlinkSync(zipFile);
}
const output = fs.createWriteStream(zipFile);
const archive = archiver('zip');
let isClose = false;
archive.on('error', (err: Error) => {
Log.error(`zip global data error: ${err.message}`);
});
output.on('close', () => { isClose = true; });
output.on('end', () => { isClose = true; });
archive.pipe(output);
archive.directory(zipPath, false);
// const folders = fs.readdirSync(zipPath);
// folders.forEach(f => {
// if (fs.statSync(path.join(zipPath, f)).isDirectory) {
// archive.directory(path.join(zipPath, f), f);
// }
// });
await archive.finalize();
while (!isClose) {
await new Promise((resolve, reject) => {
setTimeout(resolve, 100);
});
}
return fs.readFileSync(zipFile);
}
示例8: cpy
(async () => {
//------------------------------------
utils.printTaskHeading('Clean');
shell.rm('-rf', 'dist/tmp');
shell.mkdir('-p', 'dist/tmp');
//------------------------------------
utils.printTaskHeading('Build frontend');
shell.exec('npm run build', { cwd: 'frontend' });
shell.cp('-r', 'frontend/build/.', 'plugins/versionpress/admin/public/gui');
//------------------------------------
utils.printTaskHeading('Copy files to dist/tmp');
const filesToCopy = [
'.',
// everything except...
'!vendor',
'!tests',
'!.idea',
'!.gitignore',
'!ruleset.xml',
];
await cpy(filesToCopy, '../../dist/tmp', {
cwd: 'plugins/versionpress',
parents: true,
dot: true,
});
//------------------------------------
utils.printTaskHeading('Install production Composer dependencies');
shell.exec('composer install -d dist/tmp --no-dev --prefer-dist --ignore-platform-reqs --optimize-autoloader');
shell.rm('dist/tmp/composer.{json,lock}');
//------------------------------------
utils.printTaskHeading('Update version in plugin file');
let version = shell.exec('git describe --tags').stdout.trim();
const versionpressPhpPath = 'dist/tmp/versionpress.php';
let content = await fs.readFile(versionpressPhpPath, { encoding: 'utf8' });
content = content.replace(/^Version: (.*)$/m, 'Version: ' + version);
await fs.writeFile(versionpressPhpPath, content, { encoding: 'utf8' });
//------------------------------------
utils.printTaskHeading('Produce ZIP file');
const outFilePath = `dist/versionpress-${version}.zip`;
const outFile = fs.createWriteStream(outFilePath);
const archive = archiver('zip');
archive.pipe(outFile);
archive.directory('dist/tmp/', 'versionpress');
await archive.finalize();
//------------------------------------
utils.printTaskHeading('Remove temp directory');
shell.rm('-rf', 'dist/tmp');
//------------------------------------
utils.printTaskHeading('Done!');
console.log(' ');
console.log('Build ready: ' + chalk.white.bold.bgGreen(outFilePath));
console.log(' ');
})();
示例9: Archiver
readableObjectMode: true,
writeableObjectMode: true,
decodeStrings: true,
encoding: 'test',
highWaterMark: 1,
objectmode: true,
comment: 'test',
forceLocalTime: true,
forceZip64: true,
store: true,
zlib: {},
gzip: true,
gzipOptions: {},
};
Archiver('zip', options);
const archiver = Archiver.create('zip');
const writeStream = fs.createWriteStream('./archiver.d.ts');
const readStream = fs.createReadStream('./archiver.d.ts');
archiver.abort();
archiver.pipe(writeStream);
archiver.append(readStream, { name: 'archiver.d.ts' });
archiver.append(readStream, { date: '05/05/1991' });
archiver.append(readStream, { date: new Date() });
archiver.append(readStream, { mode: 1 });
archiver.append(readStream, { mode: 1, stats: new fs.Stats() });