src/zip.js
function preprocessToRezip(contentsZip) {
  return zipEntriesFromBuffer(contentsZip).then(result => {
    const manifestList = Array.from(result.entries.keys()).filter(
      file => path.basename(file) === "manifest.json"
    );
    if (manifestList.length === 0) {
      throw new Error("The zip file has no manifest.json");
    } else if (manifestList.length > 1) {
      throw new Error("The zip file has many manifest.json files");
    }
    result.manifestPath = manifestList[0];
    const manifestEntry = result.entries.get(result.manifestPath);
    return getManifestJsonFromEntry(result.zipFile, manifestEntry).then(json =>
      Object.assign(result, { manifestJson: json })
    );
  });
}
function preprocessToRezip(contentsZip) {
  return zipEntriesFromBuffer(contentsZip).then(result => {
    const manifestList = Array.from(result.entries.keys()).filter(
      file => path.basename(file) === "manifest.json"
    );
    if (manifestList.length === 0) {
      throw new Error("The zip file has no manifest.json");
    } else if (manifestList.length > 1) {
      throw new Error("The zip file has many manifest.json files");
    }
    result.manifestPath = manifestList[0];
    const manifestEntry = result.entries.get(result.manifestPath);
    return getManifestJsonFromEntry(result.zipFile, manifestEntry).then(json =>
      Object.assign(result, { manifestJson: json })
    );
  });
}
function preprocessToRezip ( contentsZip ) { return zipEntriesFromBuffer ( contentsZip ) . then ( result => { const manifestList = Array . from ( result . entries . keys ( ) ) . filter ( file => path . basename ( file ) === "manifest.json" ) ; if ( manifestList . length === 0 ) { throw new Error ( "The zip file has no manifest.json" ) ; } else if ( manifestList . length > 1 ) { throw new Error ( "The zip file has many manifest.json files" ) ; } result . manifestPath = manifestList [ 0 ] ; const manifestEntry = result . entries . get ( result . manifestPath ) ; return getManifestJsonFromEntry ( result . zipFile , manifestEntry ) . then ( json => Object . assign ( result , { manifestJson : json } ) ) ; } ) ; }
Create an intermediate representation for contents.zip
@typedef {{zipFile: !yauzl.ZipFile,entries: !Map<string, !yauzl.ZipEntry>, manifestJson: Object, manifestPath: string}} PreprocessedContentsZip
@param {!Buffer} contentsZip
@return {Promise<PreprocessedContentsZip>}
Create an intermediate representation for contents . zip