{"id":13736871,"url":"https://github.com/status-im/nim-snappy","last_synced_at":"2026-03-12T10:31:48.575Z","repository":{"id":37080338,"uuid":"155870727","full_name":"status-im/nim-snappy","owner":"status-im","description":"Nim implementation of Snappy compression algorithm","archived":false,"fork":false,"pushed_at":"2025-02-13T11:18:22.000Z","size":1606,"stargazers_count":27,"open_issues_count":3,"forks_count":3,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-02-22T17:43:34.168Z","etag":null,"topics":["compression","lzw-compression","snappy","zippy"],"latest_commit_sha":null,"homepage":null,"language":"Nim","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/status-im.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2018-11-02T13:37:02.000Z","updated_at":"2024-10-24T10:01:59.000Z","dependencies_parsed_at":"2024-01-06T12:02:49.360Z","dependency_job_id":"ca55c6f5-84fb-45d5-afb9-84db89678b04","html_url":"https://github.com/status-im/nim-snappy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/status-im%2Fnim-snappy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/status-im%2Fnim-snappy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/status-im%2Fnim-snappy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/status-im%2Fnim-snappy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/status-im","download_url":"https://codeload.github.com/status-im/nim-snappy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240371761,"owners_count":19790888,"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":["compression","lzw-compression","snappy","zippy"],"created_at":"2024-08-03T03:01:30.143Z","updated_at":"2026-03-12T10:31:43.523Z","avatar_url":"https://github.com/status-im.png","language":"Nim","funding_links":[],"categories":["Algorithms"],"sub_categories":["Compression"],"readme":"# Snappy\n[![Build Status](https://travis-ci.org/status-im/nim-snappy.svg?branch=master)](https://travis-ci.org/status-im/nim-snappy)\n[![Build status](https://ci.appveyor.com/api/projects/status/g4y9874tx0biv3t1/branch/master?svg=true)](https://ci.appveyor.com/project/nimbus/nim-snappy/branch/master)\n![nimble](https://img.shields.io/badge/available%20on-nimble-yellow.svg?style=flat-square)\n![license](https://img.shields.io/github/license/citycide/cascade.svg?style=flat-square)\n![Github action](https://github.com/status-im/nim-snappy/workflows/CI/badge.svg)\n\nCompression and decompression utilities for the `snappy` compression algorithm:\n\n* [Overview](http://google.github.io/snappy/)\n* [Format description](https://github.com/google/snappy/blob/main/format_description.txt)\n\nThe main module, `snappy`, contains in-memory encoders and decoders:\n\n* `compress`/`uncompress` work with caller-allocated buffers\n  * No dynamic memory allocation (the functions require ~20kb stack space)\n  * Exception-free\n* `encode`/`decode` are convenience wrappers for the above that take care of\n  memory allocation\n  * Simplified error reporting\n  * Suitable for small buffers mainly\n\nFramed encodings are also supported via functions carrying the `Framed` suffix.\n\n* [Framing format](https://github.com/google/snappy/blob/main/framing_format.txt)\n\n## Stream support\n\nThe library supports compression and decompression for the following libraries\n\n* [faststreams](https://github.com/status-im/nim-faststreams)\n  * `import snappy/faststreams`\n* [std/streams](https://nim-lang.org/docs/streams.html)\n  * `import snappy/streams` (incomplete)\n\n## API\n\n### In-memory\n\n```nim\nimport snappy\n\nfunc compress*(\n  input: openArray[byte],\n  output: var openArray[byte]): Result[int, CodecError]\nfunc encode*(input: openArray[byte]): seq[byte]\nfunc uncompress*(input: openArray[byte], output: var openArray[byte]):\n  Result[int, CodecError]\nfunc decode*(input: openArray[byte], maxSize = maxUncompressedLen): seq[byte]\n```\n\n### faststreams\n\n:warning: BETA API, subject to change\n\nWhen using faststreams, errors are reported via exceptions.\n\nUncompressing raw snappy is not covered in streaming mode due to the requirement that full uncompressed data must be available during decompression.\n\n```nim\nimport snappy/faststreams\n\nproc compress*(input: InputStream, output: OutputStream)\nproc compressFramed*(input: InputStream, output: OutputStream)\nproc uncompressFramed*(input: InputStream, output: OutputStream)\n```\n\n### std/streams\n\n:warning: BETA API, subject to change\n\n```nim\nimport snappy/streams\n\nproc compress*(input: Stream, inputLen: int, output: Stream)\n# TODO compressFramed\n# TODO uncompressFramed\n```\n\n## Examples\n```Nim\nimport snappy\nvar source = readFile(\"readme.md\")\nvar encoded = snappy.encode(toOpenArrayByte(source, 0, source.len-1))\nvar decoded = snappy.decode(encoded)\nassert equalMem(decoded[0].addr, source[0].addr, source.len)\n```\n\n## Performance\n\nGenerally, performance is on par with the C++ implementation, shown as `cppLib`.\n\nFramed encoding is slower due to the extra CRC32C processing.\n\nThe table shows average time to compress data in `ms` on x86_64. Lower is better.\n\n```\n        inMemory,      fastStreams,       nimStreams,           cppLib,      Samples,         Size,         Test\n  0.086 /  0.056,   0.087 /  0.000,   0.112 /  0.000,   0.088 /  0.029,          100,       102400, html\n  0.117 /  0.093,   0.118 /  0.094,   0.000 /  0.000,   0.000 /  0.000,          100,       102400, html(framed)\n  1.052 /  0.480,   1.073 /  0.000,   1.322 /  0.000,   1.005 /  0.335,          100,       702087, urls.10K\n  1.260 /  0.775,   1.286 /  0.785,   0.000 /  0.000,   0.000 /  0.000,          100,       702087, urls.10K(framed)\n  0.008 /  0.005,   0.022 /  0.000,   0.092 /  0.000,   0.008 /  0.005,          100,       123093, fireworks.jpeg\n  0.051 /  0.047,   0.067 /  0.057,   0.000 /  0.000,   0.000 /  0.000,          100,       123093, fireworks.jpeg(framed)\n  0.010 /  0.006,   0.021 /  0.000,   0.066 /  0.000,   0.009 /  0.005,          100,       102400, paper-100k.pdf\n  0.046 /  0.050,   0.057 /  0.054,   0.000 /  0.000,   0.000 /  0.000,          100,       102400, paper-100k.pdf(framed)\n  0.374 /  0.218,   0.378 /  0.000,   0.451 /  0.000,   0.357 /  0.118,          100,       409600, html_x_4\n  0.491 /  0.386,   0.498 /  0.392,   0.000 /  0.000,   0.000 /  0.000,          100,       409600, html_x_4(framed)\n  0.334 /  0.186,   0.345 /  0.000,   0.399 /  0.000,   0.331 /  0.126,          100,       152089, alice29.txt\n  0.382 /  0.251,   0.392 /  0.251,   0.000 /  0.000,   0.000 /  0.000,          100,       152089, alice29.txt(framed)\n  0.300 /  0.165,   0.311 /  0.000,   0.354 /  0.000,   0.300 /  0.114,          100,       129301, asyoulik.txt\n  0.343 /  0.220,   0.352 /  0.222,   0.000 /  0.000,   0.000 /  0.000,          100,       129301, asyoulik.txt(framed)\n  0.907 /  0.483,   0.932 /  0.000,   1.086 /  0.000,   0.880 /  0.327,          100,       426754, lcet10.txt\n  1.053 /  0.675,   1.075 /  0.680,   0.000 /  0.000,   0.000 /  0.000,          100,       426754, lcet10.txt(framed)\n  1.241 /  0.646,   1.272 /  0.000,   1.477 /  0.000,   1.201 /  0.466,          100,       481861, plrabn12.txt\n  1.387 /  0.856,   1.425 /  0.861,   0.000 /  0.000,   0.000 /  0.000,          100,       481861, plrabn12.txt(framed)\n  0.076 /  0.050,   0.075 /  0.000,   0.096 /  0.000,   0.076 /  0.025,          100,       118588, geo.protodata\n  0.110 /  0.095,   0.112 /  0.098,   0.000 /  0.000,   0.000 /  0.000,          100,       118588, geo.protodata(framed)\n  0.279 /  0.183,   0.287 /  0.000,   0.338 /  0.000,   0.273 /  0.121,          100,       184320, kppkn.gtb\n  0.346 /  0.261,   0.354 /  0.263,   0.000 /  0.000,   0.000 /  0.000,          100,       184320, kppkn.gtb(framed)\n  0.024 /  0.018,   0.026 /  0.000,   0.032 /  0.000,   0.024 /  0.014,          100,        14564, Mark.Twain-Tom.Sawyer.txt\n  0.030 /  0.021,   0.031 /  0.021,   0.000 /  0.000,   0.000 /  0.000,          100,        14564, Mark.Twain-Tom.Sawyer.txt(framed)\n 23.814 /  8.608,  27.362 /  0.000,  48.342 /  0.000,  22.157 /  6.958,           50,     38942424, state-2560000-114a593d-0d5e08e8.ssz\n 36.075 / 25.389,  39.979 / 28.497,   0.000 /  0.000,   0.000 /  0.000,           50,     38942424, state-2560000-114a593d-0d5e08e8.ssz(framed)```\n```\n\n## Installation via nimble\n\n```bash\nnimble install snappy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatus-im%2Fnim-snappy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatus-im%2Fnim-snappy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatus-im%2Fnim-snappy/lists"}