{"id":13998554,"url":"https://github.com/blacha/binparse","last_synced_at":"2025-09-22T21:30:53.240Z","repository":{"id":37796204,"uuid":"290913296","full_name":"blacha/binparse","owner":"blacha","description":"Typed binary parsing for typescript","archived":false,"fork":false,"pushed_at":"2023-09-04T17:45:23.000Z","size":397,"stargazers_count":14,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-12T18:57:07.421Z","etag":null,"topics":["binary","parser","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/blacha.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-08-28T00:38:28.000Z","updated_at":"2024-12-09T09:43:09.000Z","dependencies_parsed_at":"2024-01-15T19:45:05.655Z","dependency_job_id":"3a4b6844-88c4-4702-92a2-c11c2c023913","html_url":"https://github.com/blacha/binparse","commit_stats":{"total_commits":101,"total_committers":2,"mean_commits":50.5,"dds":0.3564356435643564,"last_synced_commit":"83c8515e298fafa6d68d7c504fdf2f1927b78c25"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacha%2Fbinparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacha%2Fbinparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacha%2Fbinparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacha%2Fbinparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blacha","download_url":"https://codeload.github.com/blacha/binparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233885573,"owners_count":18745607,"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":["binary","parser","typescript"],"created_at":"2024-08-09T19:01:46.587Z","updated_at":"2025-09-22T21:30:47.955Z","avatar_url":"https://github.com/blacha.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# binparse\n\nTyped binary object parser\n\n```typescript\nimport { bp } from 'binparse';\n\nconst simpleParser = bp.object('SimpleObject', {\n  id: bp.lu16,\n  x: bp.u8,\n  y: bp.u8,\n});\n\nconst { value, offset } = simpleParser.read([0x01, 0x00, 0x01, 0x02]);\n\n/** byte offset of where the reader finished */\noffset; // 3\n\n/** Parsed object */\nvalue.id; // 0x01\nvalue.x; // 0x01;\nvalue.y; // 0x02\n\nvalue.unk1; // Typescript error\n```\n\nHeavily inspired by [zod](https://github.com/vriad/zod)\n\n## Arrays\n\nRead in a variable length array of points\n\nLoad the length in as a variable which can be referenced by the array parser for the length\n\n```typescript\nimport { bp } from 'binparse';\n\nconst PointParser = bp.object('Point', {\n  /** X Offset */\n  x: bp.lu16,\n  /** Y Offset */\n  y: bp.lu16,\n});\n\nconst PointsParser = bp.object('SimpleObject', {\n  // Number of points to read\n  length: bp.variable('len', bp.u8),\n  // Array of points with length \"len\"\n  points: bp.array('Points', PointParser, 'len'),\n});\n\nconst points = PointsParser.read([0x01, 0x01, 0x00, 0x02, 0x00]);\n```\n\n## BitFlags\n\n```typescript\nimport { bp } from 'binparse';\n\nconst FlagParser = bp.bits('Flags', {\n  isRed: 1,\n  isGreen: 1,\n  isBlue: 1,\n  isAlpha: 1,\n});\n\nconst { value } = FlagParser.read([0b0101]);\n\nvalue.isRed; // true\nvalue.isGreen; // false\nvalue.isBlue; // true\nvalue.isAlpha; // false\n```\n\n## Explicit offsets\n\n```typescript\nimport { bp } from 'binparse';\n\nconst sparseParser = bp.object('Sparse', {\n  first: bp.at(0x30, bp.lu32), // Read a lu32 at 0x30\n  second: bp.at(0x60, bp.lu32), // Read a lu32 at 0x60\n});\nsparseParser.size; // 0x64\n```\n\n## Performance\n\nContinuos performance monitoring is done using [hyperfine](https://github.com/sharkdp/hyperfine) and [hyperfine-action](https://github.com/blacha/hyperfine-action)\n\nResults can be found at [benchmarks.html](https://blacha.github.io/binparse/benchmarks.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacha%2Fbinparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblacha%2Fbinparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacha%2Fbinparse/lists"}