compression.md
February 27, 2025 ยท View on GitHub
Compression
Description
Compression and Decompression tools
Usage
compressStream
A Browser compatible Gzip compression function
import { compressStream } from 'gis-tools-ts';
const inputData: Uint8Array = new Uint8Array(100);
// supports gzip, deflate, deflate-raw
// also supports brotli and zstd if using locally
const compressedData = await compressStream(inputData, 'gzip');
decompressStream
A Browser compatible Gzip decompression function
import { decompressStream } from 'gis-tools-ts';
const inputData: Uint8Array = new Uint8Array(100);
// supports gzip, deflate, deflate-raw
// also supports brotli and zstd if using locally
const decompressedData = await decompressStream(inputData, 'gzip');
Zipped Folder Reader
Iterate over the items in a zip file
import { iterZipFolder } from 'gis-tools-ts';
const inputData: Uint8Array = new Uint8Array(100);
for await (const item of iterZipFolder(inputData)) {
const { filename, comment } = item;
const file = await item.read();
}
LZW Decoder
Decompress the LZW data
import { lzwDecoder } from 'gis-tools-ts';
const inputData: Uint8Array = new Uint8Array(100);
const decompressedData = lzwDecoder(inputData);
Polyfills
If you are running the code locally like Bun/Deno/NodeJS/etc., you may need to use the "local" polyfill to get access to all compression and decompression tools:
import 'gis-tools-ts/polyfills/local';
On the browser, if you want to keep the bundle size smaller but need support for older browsers:
import 'gis-tools-ts/polyfills/decompression';