https://github.com/zalari/string-compression-utils
Compress or decompress a string with native browser APIs
https://github.com/zalari/string-compression-utils
Last synced: about 1 year ago
JSON representation
Compress or decompress a string with native browser APIs
- Host: GitHub
- URL: https://github.com/zalari/string-compression-utils
- Owner: zalari
- License: mit
- Created: 2023-07-07T09:14:26.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-01T21:52:32.000Z (almost 3 years ago)
- Last Synced: 2025-06-05T12:40:46.358Z (about 1 year ago)
- Language: TypeScript
- Size: 115 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# String Compression
Compress or decompress a string with [**native** browser APIs](https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API)
with [`gzip`, `deflate`, or `deflate-raw`](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream/CompressionStream#format).\
Compatible to use with [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/atob) and
[`btoa`](https://developer.mozilla.org/en-US/docs/Web/API/btoa).
## Example Usage
```js
import { compress, decompress } from '@zalari/string-compression-utils';
const input = '{"id":1,"todo":"Do something nice for someone you care about","completed":true,"userId":26}';
const compressedString = await compress(input, 'gzip');
const urlFriendly = encodeURIComponent(compressedString);
const decodedString = decodeURIComponent(urlFriendly);
const output = await decompress(decodedString, 'gzip');
console.assert(input === output);
```