{"id":15387063,"url":"https://github.com/gkjohnson/client-side-zip-server","last_synced_at":"2025-11-13T22:52:48.422Z","repository":{"id":66338436,"uuid":"133728149","full_name":"gkjohnson/client-side-zip-server","owner":"gkjohnson","description":"Intercepting fetch requests and serving zip file data from a ServiceWorker.","archived":false,"fork":false,"pushed_at":"2018-05-19T20:02:02.000Z","size":70,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T20:11:24.614Z","etag":null,"topics":["browser","client","client-side","fetch","intercept","javascript","middleware","request","service","service-worker","serviceworker","zip"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gkjohnson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-16T22:09:06.000Z","updated_at":"2025-04-13T21:51:54.000Z","dependencies_parsed_at":"2023-02-24T23:00:27.202Z","dependency_job_id":null,"html_url":"https://github.com/gkjohnson/client-side-zip-server","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"53c1a3e4def52b080ff0540ee319be5e1002a805"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gkjohnson/client-side-zip-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fclient-side-zip-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fclient-side-zip-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fclient-side-zip-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fclient-side-zip-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkjohnson","download_url":"https://codeload.github.com/gkjohnson/client-side-zip-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkjohnson%2Fclient-side-zip-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267265291,"owners_count":24061534,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["browser","client","client-side","fetch","intercept","javascript","middleware","request","service","service-worker","serviceworker","zip"],"created_at":"2024-10-01T14:51:49.927Z","updated_at":"2025-11-13T22:52:43.403Z","avatar_url":"https://github.com/gkjohnson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# client-side-zip-server\n\nUses a service worker to set up a client-side service for intercepting fetch requests and responding with the contents of a loaded zip file. Request passes through to the server if no file is found.\n\n## Use\n\n### ZipServer\n\nZipServer registers a ServiceWorker and encapsulates everything necessary to fetch data from a zip file.\n\n```js\n// Import the service and jszip for creating zipped content\nimport './ZipServer.js'\nimport './node_modules/jszip/dist/jszip.min.js'\n\n// Create the service\nconst zs = new ZipServer();\nzs\n    .register()\n    .then(() =\u003e {\n    \n        // generate the zip file\n        const zip = new JSZip();\n        zip.file('test.text', 'hello!');\n        zip.file('/folder/file.txt', 'I\\'m in a folder!');\n        return zip.generateAsync({ type: 'arraybuffer' });\n        \n    })\n    .then(b =\u003e {\n        \n        // Add the file, save the id so it can be removed after\n        // the requests are made\n        const id = zs.addZip(b).id;\n        fetch('test.py').then(res =\u003e res.text()).then(o =\u003e console.log(o))\n        fetch('/folder/file.txt').then(res =\u003e res.text()).then(o =\u003e console.log(o))\n        zs.remove(id);\n        \n        // hello!\n        // I'm in a folder!\n        \n    });\n            \n```\n\n### As an Addition\n\nIf a service worker is already being employed, then the `ZipResolver` class can be used independently. See [zipServerWorker.js](./zipServerWorker.js) for an example of how to extend an existing ServiceWorker.\n\n## API\n\n### ZipServer\n\n#### ready\n\nGetter indicating whether the service is ready to be used and intercept requests.\n\n#### enabled\n\nGetter / Setter for toggling serving zip files. If set to `false`, files from the zip folders will _not_ be resolved (though the files will not be removed). Set the `true` to reenable serving.\n\nNOTE: This setting is optimistic and assumes nothing else has changed the enabled state in the ServiceWorker. If another client causes the ServiceWorker to be restarted then this setting could be out of sync.\n\n#### register()\n\nRegisters a service worker for the zip service. If an equivelant service worker is already registered, then it uses the existing worker. If a different worker is registered, then the other worker is unregistered.\n\n#### unregister()\n\nUnregisters the worker if it has been registered. Keep in mind that service workers are shared across open webpages, so this could cause other pages to stop working. This should only be used when the the service should be uninstalled for good.\n\n#### addZip(ArrayBuffer, transfer = true)\n\nRegisters the the zip file data with the request interceptor service so the data can be served. This makes the data accessible across all clients controlled by the zip service worker.\n\nIf `transfer` is true and the data is an ArrayBuffer, then it's ownership is transferred to the service worker, making it unavailable in the main thread.\n\nReturns an object of the form `{ id, dispose }`. Call `dispose` to remove the zip file from the service.\n\n#### addDataTransfer(dataTransfer)\n\nCreates a zip from a [DataTransfer](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) object. This can be used to create and serve files that were dragged onto the page and captured using the `'drop'` event.\n\n#### remove(id)\n\nRemoves the zip file from the service, meaning no fetch requests will return its data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkjohnson%2Fclient-side-zip-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkjohnson%2Fclient-side-zip-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkjohnson%2Fclient-side-zip-server/lists"}