{"id":15065314,"url":"https://github.com/mclander/zip-process","last_synced_at":"2026-01-03T12:03:33.027Z","repository":{"id":57406077,"uuid":"122466156","full_name":"mclander/zip-process","owner":"mclander","description":null,"archived":false,"fork":false,"pushed_at":"2018-03-28T19:50:34.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T19:48:34.018Z","etag":null,"topics":["file","jszip","npmjs","process"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mclander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-22T10:50:09.000Z","updated_at":"2018-03-28T19:49:55.000Z","dependencies_parsed_at":"2022-09-26T17:01:44.325Z","dependency_job_id":null,"html_url":"https://github.com/mclander/zip-process","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclander%2Fzip-process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclander%2Fzip-process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclander%2Fzip-process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclander%2Fzip-process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mclander","download_url":"https://codeload.github.com/mclander/zip-process/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243838125,"owners_count":20355985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file","jszip","npmjs","process"],"created_at":"2024-09-25T00:36:39.443Z","updated_at":"2026-01-03T12:03:28.007Z","avatar_url":"https://github.com/mclander.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zip-process\n\nTiny module for easy modify \u0026 repack files in zip archives and zip-containers like Excel files.\nBased on [JSZip](https://stuk.github.io/jszip/).\n\n## Install\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```sh\n$ npm install zip-process\n```\n\n## API\n\nImagine that we have .xlsx file (zip container). And need to change all occurences 'John' to 'Fedor'. \n!Don't do that if not sure for avoid side-effects.\n\nNode.js\n```js\n\nconst zipProcess = require('zip-process');\nconst fs = require(fs);\n\n// zipProcess options\nconst options = {}; // All default\n\n// zipProcess calbacks (processors)\nconst callbacks = {\t\n  // We split binary \u0026\u0026 text processing, for binary use key 'binary', for text files 'string'\n  string: { \n    // aplly path filter we need to check all .xml \u0026\u0026 .xml.rels files\n    filter: relativePath =\u003e  !!/\\.xml(\\.rels)?$/.test(relativePath),\n\t\t\t\n    // just change it, and return new value\n    callback: (data, zipFileName) =\u003e  data \u0026\u0026 data.replace(/\\bJohn\\b/g, 'Fedor')\n  }\n}\n\n\nfs.readFile('./john.xlsx', function(err, source) {\n\n  if (err) { throw err; }\n\n  zipProcess(source, options, callbacks).then( out =\u003e {\n\n    const changed = source !== out;\n\n    if (changed) {\n      fs.writeFileSync('./fedor.xlsx', out);\n    }\n\n  }) ; // enf of zipProcess\n\n}); // end of fs.readFile\n\n```\n\nVanillaJS with [FileSaver](https://github.com/eligrey/FileSaver.js/)\n``` js\n\nvar xhr = new XMLHTTPRequest();\nxhr.open(\"GET\", './john.xlsx', true);\nxhr.responseType = 'arraybuffer';\nxhr.addEventListener('load',function(){\n  if (xhr.status === 200){\n\n    zipProcess(xhr.response, {}, {\n      string: {\n        filter: relativePath =\u003e  !!/\\.xml(\\.rels)?$/.test(relativePath),\n        callback: data =\u003e  data \u0026\u0026 data.replace(/\\bJohn\\b/g, 'Fedor')\n      }\n    }).then((result) =\u003e {\n\n      FileSaver.saveAs(\n        result \n        'fedor.xlsx',\n        true\n       );\n\n    });\n  }\n})\nxhr.send();\n```\n\nAs your might guess, I wrote this module special for work with Excel files, but other types of zip works fine too ;)\n\n\n## function `zipProcess(content, options, callbacks)`\n\nProcess zip content (binary) and returns promise. Where promise get in parameter new packed content. \n\n### content parameter\n\nZip file content (readed as binary).\n\n### options parameter\n\nIf ommited, blank or undefined, defaults options will be used.\n\nAwailable options:\n* removeSignature: Remove file if callback return exactly signature (default null)\n* compression: compress file 'DEFLATE' or not 'STORE' (default 'DEFLATE') as options.compession in [JSZip.generateAsync](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html)\n* extendOptions : all other options for options in [JSZip.generateAsync](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html) (default {})\n* type: (default: for Node application 'nodebuffer', for browser 'blob' ) as options.type in [JSZip.generateAsync](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html)\n\n### callbacks parameter\n\nHash of {string, binary, ...} with same structure {filter, callback, options}:\n\n``` js\n{\n  string: {\n    filter: function(relativePath, fileInfo){ ... },\n      callback: function(fileContent, relativePath, zipObject){ ... },\n      options: { ... }\n    },\n    binary: {\n      filter: ...\n      callback: ...\n      options: ...\n    },\n}\n```\n\n\n#### Section keys: `{string}`, `{binary}` and others\n\nString section used for work with text files. This mean that this files will be decoded \nby [zipObject.async('string')](https://stuk.github.io/jszip/documentation/api_zipobject/async.html). So binary \nfiles will be decoded by [zipObject.async('unit8array')](https://stuk.github.io/jszip/documentation/api_zipobject/async.html). Hint! you can use any other key for section, it will be translated to [zipObject.async(\u003cmy section key\u003e)](https://stuk.github.io/jszip/documentation/api_zipobject/async.html). Available types you can see in [JSZip documentation](https://stuk.github.io/jszip/documentation/api_zipobject/async.html).\n\nWarning! I dont know how national encoded files will works. I prefer to use UTF8 any way. \n\n#### Section structure\n\n##### `filter: function(relativePath, fileInfo)`\n\nThis function allow process only files within zip that you want. Realized directly by [JSZip.filter](https://stuk.github.io/jszip/documentation/api_jszip/filter.html).\n\nIf ommited, behaviour defined by section keys:\n* string - files with extension where defined mime-charset ( [mime.lookup(mime.charset(fileName))](https://www.npmjs.com/package/mime-types) ) or xml or xml based extensions\n* binary - all files which not string\n* any other key - all files in archive\n\n##### `callback: function(fileContent, relativePath, zipObject)`\n\nIf ommited, nothing changed.\n\nThis call back must return changed or unchanged content, undefined or signature for remove this file from archive. \n* If content changed, target file will be repacked with new content. \n* If content unchanged or undefined will nothing changed.\n* If `content === options.removeSignature` (default null), target file will be removed from archive.\n\n##### `options: {removeSignature: ...}`\n\nCan override option removeSignature.\n\n# webpack 1.x troubles\n\nI use `mime-types`, which use `mime-db`, which includes json file directly to code. So If you have not\nconfigure `json-loader` yet, just do it. \n\n# History\n0.2.6 - fix for IE support\n0.2.5 and above - fog of development\n\n# Author\n\nAlexander (mclander) Maksimenko , Sbertech, Moscow, Russia. \n\nAny comments and pull request will be appreciated.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmclander%2Fzip-process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmclander%2Fzip-process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmclander%2Fzip-process/lists"}