本文整理汇总了TypeScript中jszip.generateAsync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript generateAsync函数的具体用法?TypeScript generateAsync怎么用?TypeScript generateAsync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generateAsync函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: downloadProject
export async function downloadProject(project: Project, uri?: string) {
const zipFile: JSZip = new JSZip();
let zipName: string = "wasm-project.zip";
if (uri !== undefined) {
zipName = `wasm-project-${uri}.zip`;
}
const queue: Array<{filePrefix: string; file: File}> = [];
project.mapEachFile((f: File) => queue.push({filePrefix: "", file: f}));
while (queue.length > 0) {
const {filePrefix, file} = queue.shift();
const fileName = filePrefix + file.name;
if (file instanceof Directory) {
file.mapEachFile(f => queue.push({filePrefix: fileName + "/", file: f}));
zipFile.folder(fileName);
continue;
}
zipFile.file(fileName, file.data);
}
await zipFile.generateAsync({type: "blob", mimeType: "application/zip"}).then((blob: Blob) => {
// Creating <a> to programmatically click for downloading zip via blob's URL
const link = document.createElement("a");
link.download = zipName;
link.href = URL.createObjectURL(blob);
// A fix for making link clickable in Firefox
// Explicity adding link to DOM for Firefox
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
}
示例2: it
it("works", async () => {
const nar = new JSZip();
nar.file("descript.txt", descript);
const narData = await nar.generateAsync({type: "arraybuffer"});
const dir = await NarLoader.loadFromBuffer(narData);
assert(dir.new("descript.txt").isFileSync());
const descriptInfo = dir.descriptInfoByTypeSync("ghost");
assert(descriptInfo.shiori === "shiolink.dll");
});
示例3: Template
}).then(results => {
zip.generateAsync({ type: 'nodebuffer' }).then(blob => {
// writeFileSync('final.zip', blob);
let t = Template();
let s3BucketVal = Ref(`${name}S3BucketParam`);
let s3KeyVal = Ref(`${name}S3KeyParam`);
if (bucket) {
s3BucketVal = bucket;
t = t.add(Parameter(`${name}S3BucketParam`, { Type: 'String' }));
}
if (key) {
s3KeyVal = key;
t = t.add(Parameter(`${name}S3KeyParam`, { Type: 'String' }));
}
if (parameters && parameters.length > 0) {
parameters.map(p => {
t = t.add(Parameter(`${name}${p}`, { Type: 'String' }));
});
}
const props: any = {
Code: {
S3Bucket: s3BucketVal,
S3Key: s3KeyVal,
},
FunctionName: options.FunctionName,
Handler: options.Handler,
MemorySize: options.MemorySize,
Role:
parameters && parameters.includes('Role')
? Ref(`${name}Role`)
: options.Role,
Runtime: options.Runtime,
Timeout: options.Timeout,
// Tags: options.Tags ? options.Tags.length > 0 : null
};
if (Object.keys(options.Environment).length > 0) {
props.Environment = options.Environment;
}
if (options.Tags.length > 0) {
props.Tags = options.Tags;
}
const fn = Lambda.Function(name, props);
res({
FunctionResource: fn,
Zip: blob,
});
});
});
示例4: asyncForEach
(async () => {
await asyncForEach(EXPORTED_FPS, async (fps) => {
const numSteps = Math.ceil(anim.duration / 1000 * fps);
const svgSprite = await SpriteSerializer.createSvgSprite(vl, anim, numSteps);
const cssSprite = SpriteSerializer.createCss(vl.width, vl.height, anim.duration, numSteps);
const fileName = `sprite_${fps}fps`;
const htmlSprite = SpriteSerializer.createHtml(`${fileName}.svg`, `${fileName}.css`);
const spriteFolder = zip.folder(`${fps}fps`);
spriteFolder.file(`${fileName}.html`, htmlSprite);
spriteFolder.file(`${fileName}.css`, cssSprite);
spriteFolder.file(`${fileName}.svg`, svgSprite);
});
zip.generateAsync({ type: 'blob' }).then(content => {
downloadFile(content, `spritesheet_${vl.name}.zip`);
});
})();
示例5: readRegExpFiles
function readRegExpFiles(regExp: string): void {
let files = readFiles(filePath);
//读取文件
if (files) {
for (let i: number = 0, iLen: number = files.length; i < iLen; i++) {
let file: string = files[i];
if (file.match(regExp)) {
console.log(`读取文件:${file}`);
zip.file(file.substring(file.lastIndexOf('\\') + 1), fs.readFileSync(file));
}
}
zip.generateAsync({ type: "nodebuffer" })
.then(function (content) {
// see FileSaver.js
writeFile(`${filePath}\\output.zip`, content);
});
}
}
示例6: create
export function create(callback: (blob: Blob) => any) {
let zip = new JSZip();
let mainfsfolder = zip.folder("mainfs");
let mainfsDirCount = mainfs.getDirectoryCount();
for (let d = 0; d < mainfsDirCount; d++) {
let dirFolder = mainfsfolder.folder(d.toString());
let dirFileCount = mainfs.getFileCount(d);
for (let f = 0; f < dirFileCount; f++) {
let file = mainfs.get(d, f);
let name = f.toString();
if (FORM.isForm(file))
name += ".form";
else if (MTNX.isMtnx(file))
name += ".mtnx";
dirFolder.file(name, file);
}
}
zip.generateAsync({type: "blob"}).then(callback);
}
示例7: exportSvg
exportSvg() {
// Export standalone SVG frames.
const vl = this.getVectorLayerWithoutHiddenLayers();
const anim = this.getAnimationWithoutHiddenBlocks();
if (!anim.blocks.length) {
// Just export an SVG if there are no animation blocks defined.
const svg = SvgSerializer.toSvgString(vl);
downloadFile(svg, `${vl.name}.svg`);
return;
}
const zip = new JSZip();
EXPORTED_FPS.forEach(fps => {
const numSteps = Math.ceil(anim.duration / 1000 * fps);
const svgs = SpriteSerializer.createSvgFrames(vl, anim, numSteps);
const length = (numSteps - 1).toString().length;
const fpsFolder = zip.folder(`${fps}fps`);
svgs.forEach((s, i) => {
fpsFolder.file(`frame${_.padStart(i.toString(), length, '0')}.svg`, s);
});
});
zip.generateAsync({ type: 'blob' }).then(content => {
downloadFile(content, `frames_${vl.name}.zip`);
});
}
示例8: images
export function images() {
let zip = new JSZip();
let mainfsfolder = zip.folder("mainfs");
let mainfsDirCount = mainfs.getDirectoryCount();
for (let d = 0; d < mainfsDirCount; d++) {
let dirFolder = mainfsfolder.folder(d.toString());
let dirFileCount = mainfs.getFileCount(d);
for (let f = 0; f < dirFileCount; f++) {
try {
let fileBuffer = mainfs.get(d, f);
if (FORM.isForm(fileBuffer)) {
let formUnpacked = FORM.unpack(fileBuffer)!;
if (formUnpacked.BMP1.length) {
formUnpacked.BMP1.forEach((bmpEntry: any, idx: number) => {
let dataUri = arrayBufferToDataURL(bmpEntry.parsed.src, bmpEntry.parsed.width, bmpEntry.parsed.height);
dirFolder.file(`${f}.${idx}.png`, dataUri.substr(dataUri.indexOf(',') + 1), { base64: true });
});
}
}
else {
// Maybe an ImgPack?
let imgs = _readImgsFromMainFS(d, f)!;
imgs.forEach((imgInfo, idx) => {
let dataUri = arrayBufferToDataURL(imgInfo.src!, imgInfo.width, imgInfo.height);
dirFolder.file(`${f}.${idx}.png`, dataUri.substr(dataUri.indexOf(',') + 1), { base64: true });
});
if (imgs.length > 1) {
let tilesBuf = fromTiles(_readPackedFromMainFS(d, f)!, imgs.length, 1, imgs[0].width * 4, imgs[0].height);
let tilesUrl = arrayBufferToDataURL(tilesBuf, imgs[0].width * imgs.length, imgs[0].height);
dirFolder.file(`${f}.all.png`, tilesUrl.substr(tilesUrl.indexOf(',') + 1), { base64: true });
}
}
}
catch (e) {}
}
}
zip.generateAsync({type: "blob"}).then((blob: Blob) => {
saveAs(blob, `mp${romhandler.getGameVersion()}-images.zip`);
});
function _readPackedFromMainFS(dir: number, file: number) {
let imgPackBuffer = mainfs.get(dir, file);
let imgArr = fromPack(imgPackBuffer);
if (!imgArr || !imgArr.length)
return;
let dataViews = imgArr.map(imgInfo => {
return new DataView(imgInfo.src!);
});
return dataViews;
}
function _readImgsFromMainFS(dir: number, file: number) {
let imgPackBuffer = mainfs.get(dir, file);
let imgArr = fromPack(imgPackBuffer);
if (!imgArr || !imgArr.length)
return;
return imgArr;
}
}