{"id":18011240,"url":"https://github.com/deno-library/compress","last_synced_at":"2025-04-10T02:25:37.725Z","repository":{"id":44749493,"uuid":"277287373","full_name":"deno-library/compress","owner":"deno-library","description":"compress and uncompress for Deno","archived":false,"fork":false,"pushed_at":"2025-03-26T03:48:17.000Z","size":214,"stargazers_count":40,"open_issues_count":1,"forks_count":6,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-03T00:06:29.670Z","etag":null,"topics":["deflate","deno","gzip","tar","tgz","zip"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/deno-library.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":null,"patreon":null,"open_collective":"deno-library","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2020-07-05T11:27:32.000Z","updated_at":"2025-03-31T08:40:48.000Z","dependencies_parsed_at":"2024-12-26T00:07:01.336Z","dependency_job_id":"8debd5f1-02a4-47a8-8e51-af1e0fc2d620","html_url":"https://github.com/deno-library/compress","commit_stats":{"total_commits":111,"total_committers":11,"mean_commits":"10.090909090909092","dds":0.3873873873873874,"last_synced_commit":"fb749ad8a0b51f7fbfcaaff23a368492bbe0b18e"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Fcompress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Fcompress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Fcompress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deno-library%2Fcompress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deno-library","download_url":"https://codeload.github.com/deno-library/compress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143641,"owners_count":21054813,"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":["deflate","deno","gzip","tar","tgz","zip"],"created_at":"2024-10-30T03:07:56.060Z","updated_at":"2025-04-10T02:25:37.699Z","avatar_url":"https://github.com/deno-library.png","language":"TypeScript","funding_links":["https://opencollective.com/deno-library"],"categories":["TypeScript"],"sub_categories":[],"readme":"# compress\n\n[![JSR Version](https://jsr.io/badges/@deno-library/compress)](https://jsr.io/@deno-library/compress)\n[![deno.land/x/compress](https://deno.land/badge/compress/version)](https://deno.land/x/compress)\n[![LICENSE](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/deno-library/compress/blob/main/LICENSE)\n\nUtilities to compress and uncompress for Deno!\n\n- [x] `tar`\n- [x] `deflate`\n- [x] `gzip`\n- [x] `tgz`\n- [x] `zip`\n- [x] `brotli`\n\n## Changelog\n\n[changelog](./changelog.md)\n\n# Usage\n\nIf you want to read and write files, you need the following [permissions](https://deno.land/manual/getting_started/permissions):\n\n\u003e --allow-read --allow-write\n\n## `tar`\n\nv0.5.5\nUse `@std/tar` instead of `@std/archive` due to deprecation\nIf you want to use the old API, you can do it\n\n\u003e import { tar } from \"jsr:@deno-library/compress/tar_archive/mod.ts\";\n\n### Definition\n\n```ts\n// JSR\nimport { tar } from \"jsr:@deno-library/compress\";\n// or\n// import { tar } from \"jsr:@deno-library/compress@0.5.5\";\n// or\n// import { tar } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// or only import tar\n// import { tar } from \"https://deno.land/x/compress@v0.5.5/tar/mod.ts\";\nexport interface compressInterface {\n  excludeSrc?: boolean;      // does not contain the src directory\n  debug?: boolean;           // list the files and folders\n}\nexport interface uncompressInterface {\n  debug?: boolean;           // list the files and folders\n}\ntar.compress(src, dest, options?: compressInterface): Promise\u003cvoid\u003e;\ntar.uncompress(src, dest, options?: uncompressInterface): Promise\u003cvoid\u003e;\n```\n\n### Example\n\n```ts\n// JSR\nimport { tar } from \"jsr:@deno-library/compress\";\n// or\n// import { tar } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// compress folder\nawait tar.compress(\"./test\", \"./test.tar\");\n// compress folder, exclude src directory\nawait tar.compress(\"./test\", \"./test.tar\", { excludeSrc: true });\n// compress file\nawait tar.compress(\"./test.txt\", \"./test.tar\");\n// uncompress\nawait tar.uncompress(\"./test.tar\", \"./dest\");\n```\n\n## `deflate`\n\nThis library contains a pure TypeScript implementation of\n[deflate](https://en.wikipedia.org/wiki/Deflate), and you can\nuse deflate on its own:\n\n```ts\n// JSR\nimport {\n  deflate,\n  /** Compress data using deflate, and do not append a zlib header. */\n  deflateRaw,\n  inflate,\n  inflateRaw,\n} from \"jsr:@deno-library/compress\";\n// or\n// import { deflate, inflate, deflateRaw, inflateRaw } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// or only import deflate, inflate, deflateRaw, inflateRaw\n// import { deflate, inflate, deflateRaw, inflateRaw } from \"https://deno.land/x/compress@v0.5.5/zlib/mod.ts\";\nconst str = \"hello world!\";\nconst bytes = new TextEncoder().encode(str);\n// with zlib header\nconst compressed = deflate(bytes);\nconst decompressed = inflate(compressed);\n// no zlib header\nconst compressed = deflateRaw(bytes);\nconst decompressed = inflateRaw(compressed);\n```\n\n## `gzip`\n\n### Definition\n\n```ts\ninterface GzipOptions {\n  level: number;\n  timestamp?: number;\n  name?: string;\n}\ngzip(bytes: Uint8Array, options?:GzipOptions): Uint8Array;\ngunzip(bytes: Uint8Array): Uint8Array;\ngzipFile(src: string, dest: string): Promise\u003cvoid\u003e;\ngunzipFile(src: string, dest: string): Promise\u003cvoid\u003e;\nclass GzipStream {\n  compress(src: string, dest: string): Promise\u003cvoid\u003e;\n  uncompress(src: string, dest: string): Promise\u003cvoid\u003e;\n  on(event: \"progress\", listener: (percent: string) =\u003e void): this;\n}\n```\n\n### Example\n\nLet's compress and uncompress a file. (`gzip` only supports compressing\nand decompressing a single file.)\n\n**stream mode**\\\nUseful for reading and writing large files.\n\n```ts\nimport { GzipStream } from \"jsr:@deno-library/compress\";\n// or\n// import { GzipStream } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// or only import GzipStream\n// import { GzipStream } from \"https://deno.land/x/compress@v0.5.5/gzip/mod.ts\";\nconst gzip = new GzipStream();\ngzip.on(\"progress\", (progress: string) =\u003e {\n  console.log(progress); // 0.00% =\u003e 100.00%\n});\nawait gzip.compress(\"./big.mkv\", \"./big.mkv.gz\");\nawait gzip.uncompress(\"./big.mkv.gz\", \"./big.mkv\");\n```\n\n**no stream mode**\\\n(This is loading all data into memory, so we can't get a `progress` event.)\n\n```ts\nimport { gunzipFile, gzipFile } from \"jsr:@deno-library/compress\";\n// or\n// import { gunzipFile, gzipFile } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// or only import gzipFile, gunzipFile\n// import { gzipFile, gunzipFile } from \"https://deno.land/x/compress@v0.5.5/gzip/mod.ts\";\nawait gzipFile(\"./deno.txt\", \"./deno.txt.gz\");\nawait gunzipFile(\"./deno.txt.gz\", \"./deno.txt\");\n```\n\n**`gzip` a string or a byte array**\n\n\u003e This is a pure TypeScript implementation, almost as fast as a Rust\n\u003e implementation.\n\n```ts\nimport { gunzip, gzip } from \"jsr:@deno-library/compress\";\n// or\n// import { gunzip, gzip } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// or only import gzip, gunzip\n// import { gzip, gunzip } from \"https://deno.land/x/compress@v0.5.5/zlib/mod.ts\";\n// gzip\nconst bytes = new TextEncoder().encode(\"hello\");\nconst compressed = gzip(bytes);\n// gunzip\nconst decompressed = gunzip(compressed);\n```\n\n## `tgz`\n\nv0.5.5\nUse `@std/tar` instead of `@std/archive` due to deprecation\nIf you want to use the old API, you can do it\n\n\u003e import { tgz } from \"jsr:@deno-library/compress/tgz_archive/mod.ts\";\n\n### Definition\n\n```ts\nimport { tgz } from \"jsr:@deno-library/compress\";\n// or\n// import { tgz } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// or only import tgz\n// import { tgz } from \"https://deno.land/x/compress@v0.5.5/tgz/mod.ts\";\nexport interface compressInterface {\n  excludeSrc?: boolean;      // does not contain the src directory\n  debug?: boolean;           // list the files and folders\n}\nexport interface uncompressInterface {\n  debug?: boolean;           // list the files and folders\n}\ntgz.compress(src, dest, options?: compressInterface): Promise\u003cvoid\u003e;\ntgz.uncompress(src, dest, options?: uncompressInterface): Promise\u003cvoid\u003e;\n```\n\n### Example\n\n```ts\nimport { tgz } from \"jsr:@deno-library/compress\";\n// or\n// import { tgz } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// compress folder\nawait tgz.compress(\"./test\", \"./test.tar.gz\");\n// compress folder, exclude src directory\nawait tgz.compress(\"./test\", \"./test.tar.gz\", { excludeSrc: true });\n// compress file\nawait tgz.compress(\"./test.txt\", \"./test.tar.gz\");\n// uncompress\nawait tgz.uncompress(\"./test.tar.gz\", \"./dest\");\n```\n\n## `zip`\n\n### Definition\n\n```ts\nimport { zip } from \"jsr:@deno-library/compress\";\n// or\n// import { zip } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// or only import zip\n// import { zip } from \"https://deno.land/x/compress@v0.5.5/zip/mod.ts\";\n\nexport interface compressInterface {\n  excludeSrc?: boolean;      // does not contain the src directory\n  debug?: boolean;           // list the files and folders\n}\nexport interface uncompressInterface {\n  debug?: boolean;           // list the files and folders\n}\nzip.compress(src, dest, options?: compressInterface): Promise\u003cvoid\u003e;\nzip.uncompress(src, dest, options?: uncompressInterface): Promise\u003cvoid\u003e;\n```\n\n### Example\n\n```ts\nimport { zip } from \"jsr:@deno-library/compress\";\n// or\n// import { zip } from \"https://deno.land/x/compress@v0.5.5/mod.ts\";\n// compress folder\nawait zip.compress(\"./test\", \"./test.tar.gz\");\n// compress folder, exclude src directory\nawait zip.compress(\"./test\", \"./test.tar.gz\", { excludeSrc: true });\n// compress file\nawait zip.compress(\"./test.txt\", \"./test.tar.gz\");\n// uncompress\nawait zip.uncompress(\"./test.tar.gz\", \"./dest\");\n```\n\n## `brotli`\n\n### Example\n\n```ts\nimport { brotli } from \"jsr:@deno-library/compress\";\nconst compressedBuffer = await brotli.compress(inputString);\n//const compressedBuffer = brotli.compressSync(inputString);\n\n// deno version \u003e= v2.1.8 / 2025.01.30\n// https://github.com/denoland/deno/pull/27815\nconst uncompressedBuffer = await brotli.uncompress(compressedBuffer);\n// const uncompressedBuffer = brotli.uncompressSync(compressedBuffer);\n```\n\n[brotli example file](test/brotli.test.ts)\n\n# test\n\n```ts\ndeno test --allow-read --allow-write\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeno-library%2Fcompress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeno-library%2Fcompress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeno-library%2Fcompress/lists"}