{"id":17968310,"url":"https://github.com/karlseguin/buffer.zig","last_synced_at":"2026-03-03T23:02:54.089Z","repository":{"id":176447033,"uuid":"657949972","full_name":"karlseguin/buffer.zig","owner":"karlseguin","description":"A poolable string builder (aka string buffer) for Zig","archived":false,"fork":false,"pushed_at":"2025-09-14T02:03:12.000Z","size":70,"stargazers_count":29,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-14T04:09:19.008Z","etag":null,"topics":["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/karlseguin.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-06-24T09:53:44.000Z","updated_at":"2025-09-14T02:03:16.000Z","dependencies_parsed_at":"2023-11-06T09:38:55.480Z","dependency_job_id":"a56691fe-dc4c-4707-b747-25a686c5c9a4","html_url":"https://github.com/karlseguin/buffer.zig","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"c9a9e33b1c4387cc730a42b4344fd3904a81854b"},"previous_names":["karlseguin/string_builer.zig","karlseguin/buffer.zig"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/karlseguin/buffer.zig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karlseguin%2Fbuffer.zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karlseguin%2Fbuffer.zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karlseguin%2Fbuffer.zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karlseguin%2Fbuffer.zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karlseguin","download_url":"https://codeload.github.com/karlseguin/buffer.zig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karlseguin%2Fbuffer.zig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30064791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"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":["zig"],"created_at":"2024-10-29T14:20:56.588Z","updated_at":"2026-03-03T23:02:54.084Z","avatar_url":"https://github.com/karlseguin.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# String Builder / Buffer For Zig\n\nBehaves a lot like a `std.ArrayList(u8)` but with a cleaner interface and pooling capabilities.\n\n```zig\nconst Buffer = @import(\"buffer\").Buffer;\n\n// Starts off with a static buffer of 100 bytes\n// If you go over this, memory will be dynamically allocated \n// It's like calling ensureTotalCapacity on an ArrrayList, but\n// those 100 bytes (aka the static portion of the buffer) are \n// re-used when pooling is used\n\nvar buf = try Buffer.init(allocator, 100);\n\ntry buf.writeByte('o');\ntry buf.write(\"ver 9000!1\");\nbuf.truncate(1);\n\nbuf.len();  // 10\nbuf.string(); // \"over 9000!\"\n```\n\nYou can access `\u0026buf.interface` to get an `*std.io.Writer`.\n\nYou can use `writeU16Big`, `writeU32Big`, `writeU64Big` and `writeU16Little`, `writeU32Little`, `writeU64Little` to write integer values.\n\n## Views\nA common pattern is to include a 2 or 4 byte payload length prefix to messages. However, this length might not until after the message is generated. The `skip` functions exist specifically to solve the problem:\n\n```zig\nvar buf = try Buffer.init(allocator, 100);\n\n// skip 4 bytes, reserving a \"view\" to the start of the skipped location\nvar view = buf.skip(4);\ntry buf.write(\"hello world\");\ntry buf.writeByte('!');\n\n// fill in those first 4 bytes with the lenght (which we now know.)\nview.writeU32Little(@intCast(buf.len());\n```\n\nThe `view` exposes most of the same methods as the Buffer, but cannot grow and does not perform bound checking.\n\n## Pooling\n\n```zig\nconst Pool = @import(\"string_builder\").Pool;\n\n\n// Creates pool of 100 Buffers, each configured with a static buffer\n// of 10000 bytes\nvar pool = try Pool.init(allocator, 100, 10000);\nvar buf = try pool.acquire();\ndefer pool.release(buf);\n```\n\nThe `Pool` is thread-safe. The `Buffer` is not thread safe.\n\nFor a more advanced use case, `pool.acquireWithAllocator(std.mem.Allocator)` can be used. This has a specific purpose: to allocate the static buffer upfront using [probably] a general purpose allocator, but for any dynamic allocation to happen with a [probably] arena allocator. This is meant for the case where an arena allocator is available which outlives the checked out buffer. In such cases, using the arena allocator for any potential dynamic allocation by the buffer will offer better performance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarlseguin%2Fbuffer.zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarlseguin%2Fbuffer.zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarlseguin%2Fbuffer.zig/lists"}