{"id":15099864,"url":"https://github.com/bcrist/zig-percent-encoding","last_synced_at":"2026-02-06T04:33:04.368Z","repository":{"id":243583545,"uuid":"812811847","full_name":"bcrist/zig-percent-encoding","owner":"bcrist","description":"Percent (URL) Encoding and Decoding for Zig","archived":false,"fork":false,"pushed_at":"2024-07-06T02:07:17.000Z","size":34,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-18T14:53:35.967Z","etag":null,"topics":["encoding","percent-encoding","urlencode","zig","zig-library","zig-package","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/bcrist.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":"2024-06-09T23:53:14.000Z","updated_at":"2025-04-27T02:12:54.000Z","dependencies_parsed_at":"2025-03-27T13:47:42.009Z","dependency_job_id":"6ded6dfe-388b-4c5c-a923-34a2d09f8bf1","html_url":"https://github.com/bcrist/zig-percent-encoding","commit_stats":null,"previous_names":["bcrist/zig-percent-encoding"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bcrist/zig-percent-encoding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcrist%2Fzig-percent-encoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcrist%2Fzig-percent-encoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcrist%2Fzig-percent-encoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcrist%2Fzig-percent-encoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bcrist","download_url":"https://codeload.github.com/bcrist/zig-percent-encoding/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcrist%2Fzig-percent-encoding/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29150691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T02:39:25.012Z","status":"ssl_error","status_checked_at":"2026-02-06T02:37:22.784Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["encoding","percent-encoding","urlencode","zig","zig-library","zig-package","ziglang"],"created_at":"2024-09-25T17:28:24.836Z","updated_at":"2026-02-06T04:33:04.354Z","avatar_url":"https://github.com/bcrist.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Percent (URL) Encoding and Decoding for Zig\n\nThis library can be used in a variety of ways:\n\n* Use `encode()` or `decode()` directly as an iterator.  They will return slices of the output until the whole input string has been encoded or decoded.\n* Use `encode_alloc()` or `decode_alloc()`.  It will always return a single slice allocated from the provided allocator, even if the output is identical to the input.\n* Use `encode_append()` or `decode_append()`.  Instead of an allocator, you can pass a `*std.ArrayList(u8)` and the result will be appended to it.  The input string must not be owned by the ArrayList.\n* Use `encode_maybe_append()` or `decode_maybe_append()`.  Similar to `*_append()`, except the ArrayList won't be modified if the input and output are identical.  The input string must not be owned by the ArrayList.  Returns either the input string, or a slice from the ArrayList.  The ArrayList does not need to be empty and won't be cleared before appending.\n* Use `std.fmt.Formatter` aware APIs with `fmtEncoded()`.\n\n`Encode_Options` can specify which kinds of bytes are encoded independently for:\n* ASCII alphabetical characters (`[A-Za-z]`)\n* Decimal digits (`[0-9]`)\n* spaces\n* ASCII symbols\n* C0 control characters and bytes \u003e= 0x80\n\nThe default `Encode_Options` is conservative; it will encode `application/x-www-form-urlencoded` data according to [HTML's rules](https://url.spec.whatwg.org/#concept-urlencoded-serializer), except that spaces will be encoded as `%20` instead of `+`. Servers generally don't care if `%20` or `+` is used, so this shouldn't be a problem, and it means it can also be used safely to escape URI data.  Encoding spaces as `+` can be enabled explicitly if desired.\n\nWhen decoding, `+` _will_ be treated as a space by default, so make sure you turn this off explicitly if you're processing data where `+` is meant to be an unencoded literal `+`.\n\n## Encoding with `std`\n\nConsider using the standard library's [`std.Uri.Component.percentEncode`](https://ziglang.org/documentation/master/std/#std.Uri.Component.percentEncode) when:\n* You have a writer available\n* You don't mind creating an `isValidChar` helper function to pass in\n* You don't need to encode spaces as `+`\n\n## Decoding with `std`\n\nThe standard library provides [`std.Uri.percentDecodeInPlace`](https://ziglang.org/documentation/master/std/#std.Uri.percentDecodeInPlace)/[`std.Uri.percentDecodeBackwards`](https://ziglang.org/documentation/master/std/#std.Uri.percentDecodeBackwards) however these require a preallocated mutable output buffer.  Additionally, they do not support decoding `+` as a space.\n\n## Performance comparison\n\nIt's highly unlikely that percent encoding/decoding will be a bottleneck for most applications, but some performance comparisons with the `std` implementations are provided in the `benchmark.zig` file and can be run with `zig build benchmark`.  As with all microbenchmarks, take the results with several grains of salt.\n\nHere are the results from my machine:\n\n|                                  | Debug     | Release   |\n| -------------------------------- | --------- | --------- |\n| percent_encoding.encode_append   | 6.2 ns/B  | 1.7 ns/B  |\n| percent_encoding.fmtEncoded      | 7.8 ns/B  | 1.9 ns/B  |\n| percent_encoding.encode_writer   | 8.0 ns/B  | 1.8 ns/B  |\n| std.Uri.Component.percentEncode  | 12 ns/B   | 2.4 ns/B  |\n| percent_encoding.decode_in_place | 7.7 ns/B  | 0.84 ns/B |\n| std.Uri.percentDecodeInPlace     | 8.9 ns/B  | 0.83 ns/B |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcrist%2Fzig-percent-encoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbcrist%2Fzig-percent-encoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcrist%2Fzig-percent-encoding/lists"}