Skip to content

Instantly share code, notes, and snippets.

@alexis-martel
alexis-martel / main.js
Last active April 30, 2024 08:55
How to use the native Compression Streams API to compress and decompress strings in JavaScript
async function compressAndEncode(inputString) {
const encoder = new TextEncoder();
// Create a ReadableStream from the input string
const inputReadableStream = new ReadableStream({
start(controller) {
controller.enqueue(encoder.encode(inputString));
controller.close();
}
});