{"id":22423330,"url":"https://github.com/prantlf/v-zstd","last_synced_at":"2025-08-01T07:32:10.215Z","repository":{"id":203588459,"uuid":"709952732","full_name":"prantlf/v-zstd","owner":"prantlf","description":"V bindings for zstd - a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios.","archived":false,"fork":false,"pushed_at":"2024-11-16T03:53:33.000Z","size":453,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-16T04:23:50.653Z","etag":null,"topics":["compression","v","vlang","zstd"],"latest_commit_sha":null,"homepage":"","language":"C","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/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2023-10-25T18:02:11.000Z","updated_at":"2024-11-16T03:53:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"77993f28-de17-4fd0-92a1-1a018bf43dea","html_url":"https://github.com/prantlf/v-zstd","commit_stats":null,"previous_names":["prantlf/v-zstd"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fv-zstd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fv-zstd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fv-zstd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fv-zstd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/v-zstd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228348371,"owners_count":17905899,"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","v","vlang","zstd"],"created_at":"2024-12-05T18:10:03.149Z","updated_at":"2025-08-01T07:32:10.186Z","avatar_url":"https://github.com/prantlf.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zstd for V\n\nV bindings for [zstd] - a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios.\n\nThis package uses the version 1.5.5 of [zstd].\n\n## Synopsis\n\n```v\nimport prantlf.zstd\n\nsrc := 'A text to compress.'.bytes()\ndst := zstd.compress(src)!\n```\n\n## Installation\n\nYou can install this package either from [VPM] or from GitHub:\n\n```txt\nv install prantlf.zstd\nv install --git https://github.com/prantlf/v-zstd\n```\n\n## Examples\n\n* [cmd/gzstd/gzstd.v]: simple command-line tool for compressing files\n* [cmd/gunzstd/gunzstd.v]: simple command-line tool for decompressing files\n\n## API\n\nThe API corresponds with the [zstd] C API. See also the [original API documentation].\n\n### Once\n\nIf you want to compress or decompress once, use the following convenience functions:\n\n```v\ncompress(src []u8) ![]u8\ncompress_with_level(src []u8, compression_level int) ![]u8\ndecompress(src []u8) ![]u8\n```\n\nIf you want to reuse the destination buffer for more compressions or decompressions, make sure to check the returned number of bytes written to it:\n\n```v\ncompress_to(mut dst []u8, src []u8) !int\ncompress_with_level_to(mut dst []u8, src []u8, compression_level int) !int\ndecompress_to(mut dst []u8, src []u8) !int\n```\n\nFinally, you can have the full controll over the memory pointers by using the unsafe functions:\n\n```v\ncompress_at(mut dst \u0026u8, dst_len int, src \u0026u8, src_len int) !int\ncompress_with_level_at(mut dst \u0026u8, dst_len int, src \u0026u8, src_len int, compression_level int) !int\ndecompress_at(mut dst \u0026u8, dst_len int, src \u0026u8, src_len int) !int\n```\n\n### Repeatedly\n\nIf you want to compress or decompress multiple times, you can gain better performance by creating a compression or decompression context and reuse it. You will be able to set compression and decompression parameters too:\n\n```v\ncctx := zstd.new_compress_context()\ndefer { cctx.free() }\ncctx.set_param(zstd.CompressParam.compression_level, zstd.max_compress_level)!\n\nsrc := 'A text to compress.'.bytes()\ndst := cctx.compress(src)!\n\ncctx.reset(zstd.ResetDir.session_only)\n\nsrc2 := 'Anoter text to compress.'.bytes()\ndst2 := cctx.compress(src2)!\n```\n\n#### Compression\n\n```v\nenum ResetDir {\n  session_only\n  parameters\n  session_and_parameters\n}\n\nnew_compress_context() !\u0026CompressContext\n(c \u0026CompressContext) free()\n(c \u0026CompressContext) reset(reset ResetDir)\n\nconst (\n  strategy_fast\n  strategy_dfast\n  strategy_greedy\n  strategy_lazy\n  strategy_lazy2\n  strategy_btlazy2\n  strategy_btopt\n  strategy_btultra\n  strategy_btultra2\n)\n\nenum CompressParam {\n  compression_level\n  window_log\n  hash_log\n  chain_log\n  search_log\n  min_match\n  target_length\n  strategy\n  enable_long_distance_matching\n  ldm_hash_log\n  ldm_min_match\n  ldm_bucket_size_log\n  ldm_hash_rate_log\n  content_size_flag\n  checksum_flag\n  dict_id_flag\n  nb_workers\n  job_size\n  overlap_log\n  rsyncable\n  format\n  force_max_window\n  force_attach_dict\n  literal_compression_mode\n  target_c_block_size\n  src_size_hint\n  enable_dedicated_dict_search\n  stable_in_buffer\n  stable_out_buffer\n  block_delimiters\n  validate_sequences\n  use_block_splitter\n  use_row_match_finder\n  prefetch_c_dict_tables\n  enable_seq_producer_fallback\n  max_block_size\n}\n\ncompress_param_bounds(param CompressParam) !(int, int)\n(c \u0026CompressContext) set_param(param CompressParam, value int) !\n(c \u0026CompressContext) get_param(param CompressParam) !int\n(c \u0026CompressContext) set_pledged_src_size(pledged_src_size int) !\n\n(c \u0026CompressContext) compress(src []u8) ![]u8\n(c \u0026CompressContext) compress_to(mut dst []u8, src []u8) !int\n(c \u0026CompressContext) compress_at(mut dst \u0026u8, dst_len int, src \u0026u8, src_len int) !int\n```\n\n#### Decompression\n\n```v\nenum ResetDir {\n  session_only\n  parameters\n  session_and_parameters\n}\n\nnew_decompress_context() !\u0026DecompressContext\n(d \u0026DecompressContext) free()\n(d \u0026DecompressContext) reset(reset ResetDir)\n\nenum DecompressParam {\n  window_log_max\n  format\n  stable_out_buffer\n  force_ignore_checksum\n  ref_multiple_d_dicts\n}\n\ndecompress_param_bounds(param DecompressParam) !(int, int)\n(d \u0026DecompressContext) set_param(param DecompressParam, value int) !\n(d \u0026DecompressContext) get_param(param DecompressParam) !int\n(d \u0026DecompressContext) set_max_window_size(max_window_size int) !\n\n(d \u0026DecompressContext) decompress(src []u8) ![]u8\n(d \u0026DecompressContext) decompress_to(mut dst []u8, src []u8) !int\n(d \u0026DecompressContext) decompress_at(mut dst \u0026u8, dst_len int, src \u0026u8, src_len int) !int\n```\n\n### Streaming\n\nIf you want to compress or decompress large data, or if the data comes chunk after chunk, you can use chunked compression or decompression functions:\n\n```v\ncctx := zstd.new_compress_context()!\ndefer { cctx.free() }\ncctx.set_param(zstd.CompressParam.checksum_flag, 1)!\nmut sctx := zstd.new_compress_stream_context()\n\nmut dst := []u8{cap: zstd.compress_bound(src.len)}\nmut dst_ref := \u0026dst\ndrain := fn [dst_ref] (buf \u0026u8, len int) ! {\n  unsafe { dst_ref.push_many(buf, len) }\n}\n\ncctx.compress_chunk(mut sctx, src, false, drain)!\n...\nunsafe { cctx.compress_chunk(mut sctx, data, len, true, drain)! }\n...\ncctx.compress_end(mut sctx)!\n```\n\n#### Compression\n\n```v\nconst (\n  compress_stream_out_size\n  compress_stream_in_size\n)\n\nnew_compress_stream_context() \u0026StreamContext\n(c \u0026CompressContext) compress_chunk(\n  mut sctx StreamContext, src []u8, last bool, drain fn (buf \u0026u8, len int) !) !\n(c \u0026CompressContext) compress_chunk_at(\n  mut sctx StreamContext, src \u0026u8, src_len int, last bool, drain fn (buf \u0026u8, len int) !) !\n```\n\n#### Decompression\n\n```v\nconst (\n  decompress_stream_out_size\n  decompress_stream_in_size\n)\n\nnew_decompress_stream_context() \u0026StreamContext\n(d \u0026DecompressContext) decompress_chunk(\n  mut sctx StreamContext, src []u8, last bool, drain fn (buf \u0026u8, len int) !) !\n(d \u0026DecompressContext) decompress_chunk_at(\n  mut sctx StreamContext, src \u0026u8, src_len int, last bool, drain fn (buf \u0026u8, len int) !) !\n```\n\n### Errors\n\nTHe following error codes can be checked by calling the `code` method of `IError`:\n\n```v\nconst (\n  err_no_error\n  err_generic\n  err_prefix_unknown\n  err_version_unsupported\n  err_frame_parameter_unsupported\n  err_frame_parameter_window_too_large\n  err_corruption_detected\n  err_checksum_wrong\n  err_literals_header_wrong\n  err_dictionary_corrupted\n  err_dictionary_wrong\n  err_dictionary_creation_failed\n  err_parameter_unsupported\n  err_parameter_combination_unsupported\n  err_parameter_out_of_bound\n  err_table_log_too_large\n  err_max_symbol_value_too_large\n  err_max_symbol_value_too_small\n  err_stability_condition_not_respected\n  err_stage_wrong\n  err_init_missing\n  err_memory_allocation\n  err_work_space_too_small\n  err_dst_size_too_small\n  err_src_size_wrong\n  err_dst_buffer_null\n  err_no_forward_progress_dest_full\n  err_no_forward_progress_input_empty\n  err_frame_index_too_large\n  err_seekable_io\n  err_dst_buffer_wrong\n  err_src_buffer_wrong\n  err_sequence_producer_failed\n  err_external_sequences_invalid\n  err_max_code\n)\n```\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.\n\n## License\n\nCopyright (c) 2023-2025 Ferdinand Prantl\n\nLicensed under the MIT license.\n\n[VPM]: https://vpm.vlang.io/packages/prantlf.zstd\n[zstd]: http://www.zstd.net/\n[original API documentation]: https://facebook.github.io/zstd/zstd_manual.html\n[cmd/gzstd/gzstd.v]: ./cmd/gzstd/gzstd.v\n[cmd/gunzstd/gunzstd.v]: ./cmd/gunzstd/gunzstd.v\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fv-zstd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fv-zstd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fv-zstd/lists"}