{"id":23616908,"url":"https://github.com/bytealex/zlib-stream-rs","last_synced_at":"2026-05-05T02:39:59.106Z","repository":{"id":45617909,"uuid":"407552579","full_name":"ByteAlex/zlib-stream-rs","owner":"ByteAlex","description":"A websocket zlib-stream implementation in rust","archived":false,"fork":false,"pushed_at":"2021-12-05T16:33:19.000Z","size":35,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-14T17:11:18.826Z","etag":null,"topics":["cloudflare","flate2","hacktoberfest","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/ByteAlex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-17T13:34:45.000Z","updated_at":"2022-09-17T20:01:09.000Z","dependencies_parsed_at":"2022-08-31T11:14:28.519Z","dependency_job_id":null,"html_url":"https://github.com/ByteAlex/zlib-stream-rs","commit_stats":null,"previous_names":["zerotwo-bot/zlib-stream-rs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteAlex%2Fzlib-stream-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteAlex%2Fzlib-stream-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteAlex%2Fzlib-stream-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByteAlex%2Fzlib-stream-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ByteAlex","download_url":"https://codeload.github.com/ByteAlex/zlib-stream-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239494504,"owners_count":19648137,"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":["cloudflare","flate2","hacktoberfest","rust"],"created_at":"2024-12-27T18:14:59.444Z","updated_at":"2026-05-05T02:39:59.099Z","avatar_url":"https://github.com/ByteAlex.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zlib-stream-rs\n\nA simple utility crate to make decompressing from zlib-stream easier.\n\nThis crate is based of [flate2](https://github.com/rust-lang/flate2-rs) and their \n[clouflare zlib backend](https://github.com/cloudflare/zlib).\n\n## Usage\n1. StreamExt using `stream` feature\n```rust\nuse zlib_stream::stream::ZlibStream; \n\nasync fn setup\u003cV: AsRef\u003c[u8]\u003e + Sized, T: Stream\u003cItem=V\u003e + Unpin\u003e(stream: T) {\n    let mut stream = ZlibStream::new(stream);\n    \n    loop {\n        let data: Option\u003cResult\u003cVec\u003cu8\u003e, zlib_stream::ZlibDecompressionError\u003e\u003e = stream.next().await;\n        do_something(data);\n    }\n}\n```\n2. Barebone Implementation\n```rust\nuse zlib_stream::{ZlibStreamDecompressor, ZlibDecompressionError};\n\nfn worker_loop() {\n    let mut decompress: ZlibStreamDecompressor = ZlibStreamDecompressor::new();\n    \n    loop {\n        let mut frame: Vec\u003cu8\u003e = get_compressed_frame();\n        match decompress.decompress(frame) {\n            Ok(vec) =\u003e process_data(vec),\n            Err(ZlibDecompressionError::NeedMoreData) =\u003e continue,\n            Err(_err) =\u003e panic!(\"Broken frame!\"),\n        }\n    }\n}\n```\n\n3. High-throughput (reused output buffer)\n```rust\nuse zlib_stream::{ZlibDecompressionError, ZlibStreamDecompressor};\n\nfn worker_loop() {\n    let mut decompress = ZlibStreamDecompressor::new();\n    let mut output = Vec::with_capacity(1024 * 128);\n\n    loop {\n        let frame: Vec\u003cu8\u003e = get_compressed_frame();\n        match decompress.decompress_into(frame, \u0026mut output) {\n            Ok(()) =\u003e process_data(\u0026output),\n            Err(ZlibDecompressionError::NeedMoreData) =\u003e continue,\n            Err(_err) =\u003e panic!(\"Broken frame!\"),\n        }\n    }\n}\n```\n\n4. Highest throughput (internal reusable output buffer)\n```rust\nuse zlib_stream::{ZlibDecompressionError, ZlibStreamDecompressor};\n\nfn worker_loop() {\n    let mut decompress = ZlibStreamDecompressor::new();\n\n    loop {\n        let frame: Vec\u003cu8\u003e = get_compressed_frame();\n        match decompress.decompress_ref(frame) {\n            Ok(data) =\u003e process_data(data),\n            Err(ZlibDecompressionError::NeedMoreData) =\u003e continue,\n            Err(_err) =\u003e panic!(\"Broken frame!\"),\n        }\n    }\n}\n```\n\n5. Memory protection for fragmented frames\n```rust\nuse zlib_stream::ZlibStreamDecompressor;\n\nlet mut decompress = ZlibStreamDecompressor::with_buffer_size_and_limit(\n    1024 * 128, // output buffer size\n    1024 * 1024 // max buffered partial-frame bytes\n);\n\n// after protocol errors/out-of-sync streams\ndecompress.reset();\n```\n\n6. `bytes` integration (`bytes-api` feature)\n```rust\nuse bytes::Bytes;\nuse zlib_stream::ZlibStreamDecompressor;\n\nlet mut decompress = ZlibStreamDecompressor::new();\nlet frame: Bytes = get_bytes_frame();\nlet payload = decompress.decompress_bytes(frame)?;\n```\n\n## Benchmarking\nRun the Criterion suite:\n\n```bash\ncargo bench --bench decompress\n```\n\n## Release Tuning\nFor maximum throughput in production binaries:\n\n1. Use CPU-specific code generation when possible:\n```bash\nRUSTFLAGS=\"-C target-cpu=native\" cargo build --release\n```\n\n2. Consider these release profile settings in the consuming binary:\n```toml\n[profile.release]\nlto = \"fat\"\ncodegen-units = 1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytealex%2Fzlib-stream-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytealex%2Fzlib-stream-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytealex%2Fzlib-stream-rs/lists"}