本文整理汇总了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();
});
}
示例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();
});
});
});
}
});
});
});
示例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);
}
});
});
示例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)
})
}
})
})
})
示例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);
}
});
});
});
});
});
示例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}, () => {});
示例7: open
return new Promise<ZipFile>((resolve, reject) => {
open(zipPath, (err, zipFile) => err ? reject(err) : resolve(zipFile));
}).then(zipFile => new Promise((resolve, reject) => {