{"id":15354773,"url":"https://github.com/bokuweb/zstd-wasm","last_synced_at":"2025-05-16T05:04:26.758Z","repository":{"id":37912213,"uuid":"368422578","full_name":"bokuweb/zstd-wasm","owner":"bokuweb","description":"Zstandard for browser, Node.js and Deno","archived":false,"fork":false,"pushed_at":"2025-05-14T07:56:10.000Z","size":2968,"stargazers_count":134,"open_issues_count":16,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T08:46:58.178Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bokuweb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":null,"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},"funding":{"github":["bokuweb"]}},"created_at":"2021-05-18T06:22:26.000Z","updated_at":"2025-05-07T23:15:05.000Z","dependencies_parsed_at":"2024-02-04T09:26:59.470Z","dependency_job_id":"0f0421e3-21b3-4c07-af70-fccbd9833797","html_url":"https://github.com/bokuweb/zstd-wasm","commit_stats":{"total_commits":133,"total_committers":6,"mean_commits":"22.166666666666668","dds":"0.42105263157894735","last_synced_commit":"83a8803e28fc04bf90f5df8ebbf6d9965cc8eb72"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bokuweb%2Fzstd-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bokuweb%2Fzstd-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bokuweb%2Fzstd-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bokuweb%2Fzstd-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bokuweb","download_url":"https://codeload.github.com/bokuweb/zstd-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471060,"owners_count":22076585,"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-10-01T12:20:56.794Z","updated_at":"2025-05-16T05:04:25.727Z","avatar_url":"https://github.com/bokuweb.png","language":"TypeScript","funding_links":["https://github.com/sponsors/bokuweb"],"categories":["TypeScript"],"sub_categories":[],"readme":"# zstd-wasm\n\n\u003cimg src=\"https://github.com/bokuweb/zstd-wasm/workflows/Continuous%20Integration/badge.svg\" alt=\"Build Status\" /\u003e \u003ca href=\"https://www.npmjs.com/package/@bokuweb/zstd-wasm\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@bokuweb/zstd-wasm.svg\" alt=\"Build Status\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@bokuweb/zstd-wasm\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@bokuweb/zstd-wasm.svg\" /\u003e\u003c/a\u003e\n\nZstandard for browser, Node.js and Deno.\nFor now support only simple API.\n\n## installation\n\n```\nnpm install @bokuweb/zstd-wasm\n```\n## examples\n\n### Node.js\n\nPlayground: https://runkit.com/bokuweb/60f1172a58aae5001aea2418\n\n``` js\nconst { init, compress, decompress } = require('@bokuweb/zstd-wasm');\n\n(async () =\u003e {\n  await init();\n  const compressed = compress(Buffer.from('Hello zstd!!'), 10);\n  const res = decompress(compressed);\n  Buffer.from(res).toString(); // Hello zstd!!\n})();\n```\n\n### Deno\n\nSee also, https://github.com/bokuweb/zstd-wasm/tree/master/examples/deno\n\n``` ts\nimport { init, decompress, compress } from 'https://deno.land/x/zstd_wasm/deno/zstd.ts';\n\nawait init();\nconst encoder = new TextEncoder();\nconst buffer = encoder.encode('Hello World');\nconst compressed = compress(buffer, 10);\nconst decompressed = decompress(compressed);\nconst decoder = new TextDecoder();\nconsole.log(decoder.decode(decompressed));\n```\n### without bundlers\n\n``` js\nimport { init, compress, decompress } from '@bokuweb/zstd-wasm';\n\n(async () =\u003e {\n  await init('./zstd.wasm'); // Please deploy `node_modules/@bokuweb/zstd-wasm/lib/wasm/zstd.wasm` to your hosting server.\n  const compressed = compress(Buffer.from('Hello zstd!!'), 10);\n  const res = decompress(compressed);\n  Buffer.from(res).toString(); // Hello zstd!!\n})();\n```\n\n---\n\n### with `vite`\n\nPlease set following config in `vite.config.js`.\n\n``` js\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n  optimizeDeps: {\n    exclude: ['@bokuweb/zstd-wasm'],\n    esbuildOptions: {\n      target: 'es2020',\n    },\n  },\n});\n```\n\n---\n\n### with webpack4\n\nWe need to use `file-loader` with webpack4.\nThis is because, webpack doesn’t work well with wasm modules created with Emscripten.\nSee, https://github.com/webpack/webpack/issues/7352\n\n\n``` js\nimport { init, compress, decompress } from '@bokuweb/zstd-wasm';\n\n(async () =\u003e {\n  await init();\n  const compressed = compress(Buffer.from('Hello zstd!!'), 10);\n  const res = decompress(compressed);\n  Buffer.from(res).toString(); // Hello zstd!!\n})();\n```\n\nIn this case, please install `file-loader` by yourself.\n\n- webpack.config.js\n``` js\n{\n  // ...snipped\n  module: {\n    rules: [\n      {\n        test: /zstd\\.wasm$/,\n        type: 'javascript/auto',\n        loader: 'file-loader', // Please use file loader\n      },\n    ],\n  },\n}\n```\n\n---\n\n### with webpack5\n\nWe need to use `Asset Modules` with webpack5.\nThis is because, webpack doesn’t work well with wasm modules created with Emscripten.\nSee, https://github.com/webpack/webpack/issues/7352\n\n\n``` js\nimport { init, compress, decompress } from '@bokuweb/zstd-wasm';\n\n(async () =\u003e {\n  await init();\n  const compressed = compress(Buffer.from('Hello zstd!!'), 10);\n  const res = decompress(compressed);\n  Buffer.from(res).toString(); // Hello zstd!!\n})();\n```\n\n- webpack.config.js\n``` js\n{\n  // ...snipped\n  module: {\n    rules: [\n      {\n        test: /zstd\\.wasm/,\n        type: 'asset/resource',\n      },\n    ],\n  },\n  // ...snipped\n}\n```\n\n## Using dictionary\n\n1. Create the dictionary\n\n`zstd --train FullPathToTrainingSet/* -o dictionaryName`\n\n2. Compress with dictionary\n\n```typescript\nconst dict = readFileSync('./dict');\nconst compressed = compressUsingDict(createCCtx(), buffer, dict, 10);\n```\n\n3. Decompress with dictionary\n\n``` typescript\nconst dict = readFileSync('./dict');\nconst decompressed = decompressUsingDict(createDCtx(), buffer, dict);\n```\n\nSee also [example](./test/compress_using_dict.test.ts)\n\n## API\n\n### async init(path?: string): Promise\u003cvoid\u003e\n\nInitialize module.\nPlease specify path to `zstd.wasm` without bunders on browser.\n\n### compress(buffer: Uint8Array, compressionLevel?: number): Uint8Array\n\n- buffer: data to compress.\n- compressionLevel: (optional) compression level, default value is 3\n\n**Example:**\n\n```typescript\nconst compressed = compress(buffer, 10);\n```\n\n### decompress(buffer: Uint8Array): Uint8Array\n\n- buffer: data to decompress.\n\n**Example:**\n\n```typescript\nconst decompressed = decompress(buffer);\n```\n\n### compressUsingDict(cctx: number, buffer: Uint8Array, dict: Uint8Array, compressionLevel?: number): Uint8Array\n\n- cctx: a pointer to compress context. please create cctx with `createCCtx`.\n- buffer: data to compress.\n- dict: dictionary data.\n- compressionLevel: (optional) compression level, default value is 3\n\n**Example:**\n\n```typescript\nconst dict = readFileSync('./dict');\nconst compressed = compressUsingDict(createCCtx(), buffer, dict, 10);\n```\n\n### createCCtx(): number\n\n- create a pointer to compress context.\n\n### decompressUsingDict(dctx: number, dict: Uint8Array): Uint8Array\n\n- dctx: a pointer to decompress context. please create cctx with `createDCtx`.\n- buffer: data to decompress.\n- dict: dictionary data.\n\n**Example:**\n\n```typescript\nconst dict = readFileSync('./dict');\nconst decompressed = decompressUsingDict(createDCtx(), buffer, dict);\n```\n\n### createDCtx(): number\n\n- create a pointer to decompress context.\n\n\n## License\n\nTypeScript glue is provided under the MIT License, and the zstd is provided by Facebook under the BSD 3-Clause License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbokuweb%2Fzstd-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbokuweb%2Fzstd-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbokuweb%2Fzstd-wasm/lists"}