{"id":16562309,"url":"https://github.com/niteshbalusu11/zig-codec","last_synced_at":"2025-03-05T05:26:14.941Z","repository":{"id":227136057,"uuid":"770552028","full_name":"niteshbalusu11/zig-codec","owner":"niteshbalusu11","description":"A Zig Library for Encoding and Decoding Formats","archived":false,"fork":false,"pushed_at":"2024-03-19T22:41:31.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-15T16:52:43.234Z","etag":null,"topics":["base64","hex","zig"],"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/niteshbalusu11.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-03-11T18:42:08.000Z","updated_at":"2024-03-11T19:14:45.000Z","dependencies_parsed_at":"2024-11-15T07:41:10.989Z","dependency_job_id":null,"html_url":"https://github.com/niteshbalusu11/zig-codec","commit_stats":null,"previous_names":["niteshbalusu11/zig-codec"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niteshbalusu11%2Fzig-codec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niteshbalusu11%2Fzig-codec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niteshbalusu11%2Fzig-codec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niteshbalusu11%2Fzig-codec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niteshbalusu11","download_url":"https://codeload.github.com/niteshbalusu11/zig-codec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241587929,"owners_count":19986628,"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":["base64","hex","zig"],"created_at":"2024-10-11T20:35:41.855Z","updated_at":"2025-03-05T05:26:14.918Z","avatar_url":"https://github.com/niteshbalusu11.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zig-codec\n\nA Zig Library for Encoding and Decoding Formats\n\n- Using Zig master branch, I am on zig version `0.12.0-dev.3352+95cb93944`.\n\n## Installation\n\n- In your `build.zig.zon`\n\n```zig\n    .dependencies = .{\n        .zigcodec = .{\n            .url = \"https://github.com/niteshbalusu11/zig-codec/archive/\u003csome-commit-hash\u003e.tar.gz\",\n            // The compiler should give you the right hash to use and replace.\n            .hash = \"12209012a6baf146acc3bb13f3f84243bba8f266b18d775b2ba84de0038319a4a159\",\n        },\n    },\n```\n\n- In your `build.zig`\n\n```zig\n    const zigcodec = b.dependency(\"zigcodec\", .{\n        .target = target,\n        .optimize = optimize,\n    });\n\n    const zig_codec_module = b.addModule(\"zigcodec\", .{ .root_source_file = .{ .path = zigcodec.builder.pathFromRoot(\"src/lib.zig\") } });\n    exe.root_module.addImport(\"zigcodec\", zig_codec_module);\n\n\n    // IF YOU'RE USING BUILDING A LIBRARY, THEN IT'LL PROBABLY BE\n    // lib.root_module.addImport(\"zigbase64\", zig_codec_module);\n```\n\n## Example Hex Encoding and Decoding\n\n```zig\nconst hex = @import(\"zigcodec\").hex;\nconst std = @import(\"std\");\n\ntest \"hex encoding\" {\n    const allocator = std.testing.allocator;\n\n    const original_string = \"Hello, Zig!\";\n    const expected_hex = \"48656c6c6f2c205a696721\";\n\n    const bytes = original_string;\n    const hex_from_bytes = try hex.hexEncode(allocator, bytes);\n    defer allocator.free(hex_from_bytes);\n    try std.testing.expectEqualSlices(u8, expected_hex, hex_from_bytes);\n}\n\ntest \"hex decoding\" {\n    const allocator = std.testing.allocator;\n\n    const original_string = \"Hello, Zig!\";\n    const expected_hex = \"48656c6c6f2c205a696721\";\n\n    const decoded_bytes = try hex.hexDecode(allocator, expected_hex);\n    defer allocator.free(decoded_bytes);\n    try std.testing.expectEqualSlices(u8, original_string, decoded_bytes);\n}\n\ntest \"is valid hex\" {\n    const valid_hex = \"48656c6c6f2c205a696721\";\n    const invalid_hex = \"48656c6c6f20576f726c6x\";\n\n    try std.testing.expect(hex.isHex(valid_hex));\n    try std.testing.expect(!hex.isHex(invalid_hex));\n}\n```\n\n## Example Base64 Encoding and Decoding\n\n```zig\nconst std = @import(\"std\");\nconst base64 = @import(\"zigcodec\").base64;\n\ntest \"base64 encoding\" {\n    const allocator = std.testing.allocator;\n\n    const original_bytes = \"Hello, Zig!\";\n    const expected_base64 = \"SGVsbG8sIFppZyE=\";\n\n    const bytes = try base64.base64Encode(allocator, original_bytes);\n    defer allocator.free(bytes);\n    try std.testing.expectEqualSlices(u8, expected_base64, bytes);\n}\n\ntest \"base64 decoding\" {\n    const allocator = std.testing.allocator;\n\n    const original_base64 = \"SGVsbG8sIFppZyE=\";\n    const expected_bytes = \"Hello, Zig!\";\n\n    const bytes = try base64.base64Decode(allocator, original_base64);\n    defer allocator.free(bytes);\n\n    try std.testing.expectEqualSlices(u8, expected_bytes, bytes);\n}\n\ntest \"is base64\" {\n    const valid_base64 = \"SGVsbG8sIFppZyE=\";\n    const invalid_base64 = \"SGVsbG8sIFppZyE =\";\n\n    try std.testing.expect(base64.isBase64(valid_base64));\n    try std.testing.expect(!base64.isBase64(invalid_base64));\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniteshbalusu11%2Fzig-codec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniteshbalusu11%2Fzig-codec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniteshbalusu11%2Fzig-codec/lists"}