本文整理汇总了TypeScript中yauzl.open函数的典型用法代码示例。如果您正苦于以下问题:TypeScript open函数的具体用法?TypeScript open怎么用?TypeScript open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了open函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: read
public read(filename: string, onEntry: (entry: IUnzipEntry) => void, onError: (err: Error) => void, onClose: () => void): void {
yauzl.open(filename, {lazyEntries: true, autoClose: true}, (err, zipfile) => {
if (err) {
return onError(err);
}
if (!zipfile) {
return onError(new Error('No zip data found in file'));
}
zipfile.on('error', (err2) => {
onError(err2);
});
zipfile.on('entry', (entry) => {
if (/\/$/.test(entry.fileName)) {
// Directory file names end with '/'.
// Note that entries for directories themselves are optional.
// An entry's fileName implicitly requires its parent directories to exist.
zipfile.readEntry();
} else {
const wrapper = new YauzlUnzipEntry(entry, zipfile);
onEntry(wrapper);
}
});
zipfile.once('end', () => {
onClose();
});
zipfile.readEntry();
});
}
开发者ID:ffalt,项目名称:xlsx-extract,代码行数:28,代码来源:unzip.ts
示例2: Promise
return new Promise((resolve, reject) => {
yauzl.open(filePath, { lazyEntries: true }, function (err: any, zipfile: any) {
if (err) throw err;
zipfile.readEntry();
zipfile.on("entry", function (entry: any) {
let desiredPath = path.join(targetDirectory, entry.fileName);
//let desiredPath = targetDirectory + entry.fileName;
if (/\/$/.test(entry.fileName)) {
// directory file names end with '/'
mkdirp(desiredPath, function (err: any) {
if (err) throw err;
zipfile.readEntry();
});
} else {
// file entry
zipfile.openReadStream(entry, function (err: any, readStream: any) {
if (err) throw err;
// ensure parent directory exists
mkdirp(path.dirname(desiredPath), function (err: any) {
if (err) throw err;
readStream.pipe(fs.createWriteStream(desiredPath));
readStream.on("end", function () {
zipfile.readEntry();
resolve();
});
});
});
}
});
});
});
开发者ID:into-cps,项目名称:intocps-ui,代码行数:31,代码来源:Downloader.ts
示例3: Promise
return new Promise((resolve, reject) => {
_openZip(zipFile, lazy ? { lazyEntries: true } : undefined, (error?: Error, zipfile?: ZipFile) => {
if (error) {
reject(toExtractError(error));
} else {
resolve(zipfile);
}
});
});
开发者ID:PKRoma,项目名称:vscode,代码行数:9,代码来源:zip.ts
示例4: Promise
return new Promise((resolve, reject) => {
yauzl.open(zipPath, { lazyEntries: true }, (err, zipfile) => {
if (err) throw err
zipfile.on('close', () => {
fs.removeSync(zipPath)
resolve()
})
zipfile.readEntry()
zipfile.on('error', (err) => {
reject(err)
})
zipfile.on('entry', entry => {
if (/\/$/.test(entry.fileName)) {
const fileNameArr = entry.fileName.replace(/\\/g, '/').split('/')
fileNameArr.shift()
const fileName = fileNameArr.join('/')
fs.ensureDirSync(path.join(path.dirname(zipPath), fileName))
zipfile.readEntry()
} else {
zipfile.openReadStream(entry, (err, readStream) => {
if (err) throw err
const filter = new Transform()
filter._transform = function (chunk, encoding, cb) {
cb(undefined, chunk)
}
filter._flush = function (cb) {
cb()
zipfile.readEntry()
}
const fileNameArr = entry.fileName.replace(/\\/g, '/').split('/')
fileNameArr.shift()
const fileName = fileNameArr.join('/')
const writeStream = fs.createWriteStream(path.join(path.dirname(zipPath), fileName))
writeStream.on('close', () => {})
readStream
.pipe(filter)
.pipe(writeStream)
})
}
})
})
})
开发者ID:YangShaoQun,项目名称:taro,代码行数:42,代码来源:index.ts
示例5: e
return new Promise<Manifest>((c, e) => {
yauzl.open(packagePath, (err, zipfile) => {
if (err) {
return e(err);
}
const onEnd = () => e(new Error('Manifest not found'));
zipfile.once('end', onEnd);
zipfile.on('entry', entry => {
if (!/^extension\/package\.json$/i.test(entry.fileName)) {
return;
}
zipfile.removeListener('end', onEnd);
zipfile.openReadStream(entry, (err, stream) => {
if (err) {
return e(err);
}
const buffers = [];
stream.on('data', buffer => buffers.push(buffer));
stream.once('error', e);
stream.once('end', () => {
try {
console.log(Buffer.concat(buffers).toString('utf8'));
c(JSON.parse(Buffer.concat(buffers).toString('utf8')));
} catch (err) {
e(err);
}
});
});
});
});
});
开发者ID:waderyan,项目名称:vscode-vsce,代码行数:36,代码来源:publish.ts
示例6: Writable
import * as yauzl from 'yauzl';
import { Writable } from 'stream';
yauzl.open('path/to/file.zip', {lazyEntries: true}, (err, zipfile) => {
if (err) {
throw err;
}
if (zipfile) {
zipfile.readEntry();
zipfile.on('entry', entry => {
if (/\/$/.test(entry.fileName)) {
zipfile.readEntry();
} else {
zipfile.openReadStream(entry, (err, readStream) => {
if (err) {
throw err;
}
if (readStream) {
readStream.on('end', () => {
zipfile.readEntry();
});
readStream.pipe(new Writable());
}
});
}
});
}
});
yauzl.open('options.zip', {strictFileNames: true}, () => {});
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:30,代码来源:yauzl-tests.ts
示例7: open
return new Promise<ZipFile>((resolve, reject) => {
open(zipPath, (err, zipFile) => err ? reject(err) : resolve(zipFile));
}).then(zipFile => new Promise((resolve, reject) => {
开发者ID:webstp,项目名称:extension-manager,代码行数:3,代码来源:utils.ts
注:本文中的yauzl.open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论