当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jszip.file函数代码示例

本文整理汇总了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;
    }
开发者ID:dolanmiu,项目名称:docx,代码行数:27,代码来源:next-compiler.ts

示例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;
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:7,代码来源:jszip-tests.ts

示例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;
		},
开发者ID:AhmadAlyTanany,项目名称:code-server,代码行数:10,代码来源:requirefs.ts

示例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");
 });
开发者ID:Ikagaka,项目名称:NarLoader,代码行数:12,代码来源:basic.ts

示例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 };
}
开发者ID:captbaritone,项目名称:winamp2-js,代码行数:33,代码来源:skinParserUtils.ts

示例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;
}
开发者ID:ReneSchumacher,项目名称:VSTS-Tasks,代码行数:25,代码来源:utils.ts

示例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);
  });
}
开发者ID:hleal18,项目名称:WebAssemblyStudio,代码行数:30,代码来源:download.ts

示例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;
  }
开发者ID:ewaldbenes,项目名称:Anno2018-js,代码行数:9,代码来源:upload.ts

示例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);
         }
     }
 });
开发者ID:928PJY,项目名称:docfx,代码行数:10,代码来源:common.ts

示例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);
                        })
                    }
                }

            });
开发者ID:sethdorris,项目名称:3dzip,代码行数:16,代码来源:UploadComponent.ts


注:本文中的jszip.file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。