{"id":20514033,"url":"https://github.com/webreflection/web-compressor","last_synced_at":"2025-07-14T00:38:32.811Z","repository":{"id":65993313,"uuid":"241279552","full_name":"WebReflection/web-compressor","owner":"WebReflection","description":"A gzip/deflate compressor based on De/CompressionStream buffers and base64","archived":false,"fork":false,"pushed_at":"2020-06-13T13:53:56.000Z","size":49,"stargazers_count":20,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T22:13:52.631Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.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,"zenodo":null}},"created_at":"2020-02-18T05:23:09.000Z","updated_at":"2025-04-17T12:17:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c85e595-7c0f-4e41-8965-55b15772d2b3","html_url":"https://github.com/WebReflection/web-compressor","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/WebReflection/web-compressor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fweb-compressor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fweb-compressor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fweb-compressor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fweb-compressor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/web-compressor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fweb-compressor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265228197,"owners_count":23731068,"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":[],"created_at":"2024-11-15T21:14:28.275Z","updated_at":"2025-07-14T00:38:32.804Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebCompressor\n\n\u003csup\u003e**Social Media Photo by [Tarik Haiga](https://unsplash.com/@tar1k) on [Unsplash](https://unsplash.com/)**\u003c/sup\u003e\n\nA gzip/deflate compressor based on De/CompressionStream buffers and base64.\n\n## API\n\nThe class in a nutshell:\n\n```js\nclass WebCompressor {\n  constructor(\n    format: string,  // deflate (default), gzip, or others\n    method: string   // base64 (default) or utf-16\n  )\n\n  async compress(any:string | arrayBuffer): Promise\u003carrayBuffer\u003e\n  // the returned arrayBuffer has a special toString() method\n  // so that it's possible to use it either as buffer or as string\n\n  async decompress(any:string | arrayBuffer): Promise\u003cstring\u003e\n  // the returned string is the one that was originally compressed\n}\n```\n\n#### About the compression method\n\nThe `utf-16` compression method makes it possible to shrink into a JavaScript string any compressed `utf-8` buffer, producing on average half up to 1/3rd of the equivalent _base64_ output.\n\nYou can test some `localStorage` [benchmark here](https://gist.github.com/WebReflection/7bab57a330e4a318049fe2680ba09ed3) to verify `utf-16` grants 2.5X extra entries, compared to _base64_.\n\nFor the time being though, the `utf-16` method is not used as default, for the simple reason that it's not standardized as much as base64 is.\n\n\n## Example\n\n**[Live Demo](https://codepen.io/WebReflection/pen/XWbKJQq?editors=0011)** that requires a browser compatible with [De/CompressionStream](https://wicg.github.io/compression/) such as Chrome 80+.\n\n```js\nimport WebCompressor from 'web-compressor';\n// const WebCompressor = require('web-compressor');\n\n// by default, arguments are `deflate` and `base64`\nconst {compress, decompress} = new WebCompressor('gzip');\n\ncompress('This string is long enough to be worth using compression'.repeat(10))\n  .then(arrayBuffer =\u003e {\n\n    // the compressed arrayBuffer has a special toString implementation\n    const asString = '' + arrayBuffer;\n\n    // such string is either the base64 version of the compressed buffer\n    // or its utf-16 representation, accordingly with the method\n    console.log('compressed length', asString.length);\n\n    // when decompressing you can pass either the buffer or its string\n    decompress(asString || buffer).then(originalString =\u003e {\n      console.log('original length', originalString.length);\n      console.log(originalString.slice(0, 56));\n    });\n  });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fweb-compressor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fweb-compressor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fweb-compressor/lists"}