本文整理汇总了TypeScript中jszip.file函数的典型用法代码示例。如果您正苦于以下问题:TypeScript file函数的具体用法?TypeScript file怎么用?TypeScript file使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: compile
public compile(file: File): JSZip {
const zip = new JSZip();
const xmlifiedFileMapping = this.xmlifyFile(file);
for (const key in xmlifiedFileMapping) {
if (!xmlifiedFileMapping[key]) {
continue;
}
const obj = xmlifiedFileMapping[key] as IXmlifyedFile | IXmlifyedFile[];
if (Array.isArray(obj)) {
for (const subFile of obj) {
zip.file(subFile.path, subFile.data);
}
} else {
zip.file(obj.path, obj.data);
}
}
for (const data of file.Media.Array) {
const mediaData = data.stream;
zip.file(`word/media/${data.fileName}`, mediaData);
}
return zip;
}
示例2: createTestZip
function createTestZip(): JSZip {
const zip = new JSZip();
zip.file("test.txt", "test string");
zip.file("test", null, { dir: true });
zip.file("test/test.txt", "test string");
return zip;
}
示例3: Error
read: (fsPath: string): Uint8Array => {
const file = zip.file(fsPath);
if (!file) {
throw new Error(`file "${fsPath}" not found`);
}
// TODO: Should refactor to allow a promise.
// tslint:disable-next-line no-any
return zip.file(fsPath).async("uint8array") as any;
},
示例4: it
it("works", async () => {
const nar = new JSZip();
nar.file("install.txt", install);
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 installInfo = dir.installInfoSync();
assert(installInfo.type === "ghost");
const descriptInfo = dir.descriptInfoByTypeSync("ghost");
assert(descriptInfo.shiori === "shiolink.dll");
});
示例5: getPlaylistStyle
export async function getPlaylistStyle(zip: JSZip): Promise<PlaylistStyle> {
const files = zip.file(getFilenameRegex("PLEDIT", "txt"));
const file = files[0];
if (file == null) {
return DEFAULT_SKIN.playlistStyle;
}
const ini = await file.async("text");
if (ini == null) {
return DEFAULT_SKIN.playlistStyle;
}
const data = ini && Utils.parseIni(ini).text;
if (!data) {
// Corrupt or missing PLEDIT.txt file.
return DEFAULT_SKIN.playlistStyle;
}
// Winamp seems to permit colors that contain too many characters.
// For compatibility with existing skins, we normalize them here.
["normal", "current", "normalbg", "selectedbg", "mbFG", "mbBG"].forEach(
colorKey => {
let color = data[colorKey];
if (!color) {
return;
}
if (color[0] !== "#") {
color = `#${color}`;
}
data[colorKey] = color.slice(0, 7);
}
);
return { ...DEFAULT_SKIN.playlistStyle, ...data };
}
示例6: createZipStream
export function createZipStream(rootPath : string, includeFolder: boolean) : NodeJS.ReadableStream {
let zip = new Zip();
let filePaths = getAllFiles(rootPath, /*recursive=*/ true);
for (let i = 0; i < filePaths.length; i++) {
let filePath = filePaths[i];
let parentFolder = path.dirname(rootPath);
let relativePath = includeFolder ? path.relative(parentFolder, filePath) : path.relative(rootPath, filePath);
zip.file(relativePath, fs.createReadStream(filePath), { compression: 'DEFLATE' });
}
let currentFile = null;
let zipStream = zip.generateNodeStream({
base64: false,
compression: 'DEFLATE',
type: 'nodebuffer',
streamFiles: true
}, function(chunk) {
if (chunk.currentFile != currentFile) {
currentFile = chunk.currentFile;
tl.debug(chunk.currentFile ? "Deflating file: " + chunk.currentFile + ", progress %" + chunk.percent : "done");
}
});
return zipStream;
}
示例7: 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);
});
}
示例8: findFileCaseInsensitive
private findFileCaseInsensitive(zip: JSZip, path: string): JSZip.JSZipObject {
const caseInsensitiveFileName = new RegExp(escapeStringRegexp(path), "i");
const file = zip.file(caseInsensitiveFileName)[0];
if (file === undefined) {
throw new Error(`Could not find file ${path}.`);
}
return file;
}
示例9:
fs.readdirSync(assetFolder).forEach(file => {
let filePath = path.join(assetFolder, file);
if (fs.lstatSync(filePath).isFile()) {
let ext = path.extname(filePath);
if (ext !== '.xml' && ext !== '.pdb') {
let content = fs.readFileSync(filePath);
zip.file(file, content);
}
}
});
示例10:
Zipper.loadAsync(event.target.result).then((data) => {
console.log("data", data.files);
for (var item in data.files) {
console.log("file", item);
if (item == "meta.json") {
Zipper.file('meta.json').async('string').then((data) => {
var contents = JSON.parse(data);
var success = this.JsonService.setData(contents);
console.log(contents);
this.routeHandler(contents);
})
}
}
});