{"id":21277717,"url":"https://github.com/reececomo/tinybuf","last_synced_at":"2025-08-19T08:06:23.743Z","repository":{"id":224176120,"uuid":"762643968","full_name":"reececomo/tinybuf","owner":"reececomo","description":"⚡️ High-performance in-memory binary serializer for Node.js / HTML5","archived":false,"fork":false,"pushed_at":"2025-04-20T05:00:51.000Z","size":923,"stargazers_count":9,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-09T17:58:55.864Z","etag":null,"topics":["arraybuffer","binary","buffer","dto","encoding","js-binary","json","minify","serialization","typescript","typescript-binary"],"latest_commit_sha":null,"homepage":"https://npmjs.com/tinybuf","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/reececomo.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}},"created_at":"2024-02-24T09:34:32.000Z","updated_at":"2025-07-22T09:54:51.000Z","dependencies_parsed_at":"2024-03-13T04:27:26.620Z","dependency_job_id":"db9ca048-f76d-4717-aa6a-d1157bd63622","html_url":"https://github.com/reececomo/tinybuf","commit_stats":null,"previous_names":["reececomo/typescript-binary"],"tags_count":30,"template":false,"template_full_name":null,"purl":"pkg:github/reececomo/tinybuf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reececomo%2Ftinybuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reececomo%2Ftinybuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reececomo%2Ftinybuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reececomo%2Ftinybuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reececomo","download_url":"https://codeload.github.com/reececomo/tinybuf/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reececomo%2Ftinybuf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271121168,"owners_count":24702723,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["arraybuffer","binary","buffer","dto","encoding","js-binary","json","minify","serialization","typescript","typescript-binary"],"created_at":"2024-11-21T10:07:22.673Z","updated_at":"2025-08-19T08:06:23.720Z","avatar_url":"https://github.com/reececomo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔌 tinybuf \u0026nbsp;[![NPM version](https://img.shields.io/npm/v/tinybuf.svg?style=flat-square)](https://www.npmjs.com/package/tinybuf) [![Minzipped](https://badgen.net/bundlephobia/minzip/tinybuf)](https://bundlephobia.com/package/tinybuf) [![Downloads](https://img.shields.io/npm/dt/tinybuf.svg)](https://www.npmjs.com/package/tinybuf) [![Tests](https://github.com/reececomo/tinybuf/actions/workflows/tests.yml/badge.svg)](https://github.com/reececomo/tinybuf/actions/workflows/tests.yml) [![License](https://badgen.net/npm/license/tinybuf)](https://github.com/reececomo/tinybuf/blob/main/LICENSE)\n\n\u003cimg align=\"right\" src=\"docs/hero.png\" alt=\"tinybuf icon showing binary peeking out from behind a square.\" height=\"80\"\u003e\n\n⚡Fast, compressed binary serializers in Node.js and HTML5\n\n| | |\n| --------------------------------- | ---------------------------------------- |\n| 🔮 Simple, declarative API | 🔥 Blazing fast serialization |\n| 🗜️ Powerful [compression](https://github.com/reececomo/tinybuf/blob/main/docs/types.md) | 💾 ^50% smaller than [FlatBuffers](https://github.com/reececomo/tinybuf/blob/main/docs/comparison.md) |\n| 🍃 Zero dependencies | 🙉 Strong, inferred types |\n| 🌐 Node / browser | 🛡️ Built-in validation/transforms |\n| 🤏 `~4.4kb` minzipped | ✅ Property mangling ([Terser](https://terser.org/)) |\n\n## 💿 Install\n\n```\nnpm install tinybuf\n```\n\n## Basic Usage\n\n```ts\nimport { defineFormat, Type } from 'tinybuf';\n\nexport const GameWorldState = defineFormat({\n  frameNo: Type.UInt,\n  timeRemaining: Type.Float16,\n  players: [\n    {\n      id: Type.UInt,\n      position: {\n        x: Type.Float32,\n        y: Type.Float32\n      },\n      joystick: {\n        x: Type.Scalar8,\n        y: Type.Scalar8\n      },\n      actions: Type.Bools // [jump, attack]\n    }\n  ]\n});\n```\n\n### Encode\n\nFormats can then be encoded:\n\n```ts\nlet bytes: Uint8Array = GameWorldState.encode({\n  frameNo: 50,\n  timeRemaining: 59.334,\n  players: [\n    {\n      id: 1,\n      position: { x: 123.5, y: 456.75 },\n      joystick: { x: 0.75, y: -0.662 },\n      actions: [ /* jump: */ true,\n               /* attack: */ false ]\n    }\n  ]\n});\n\nbytes.byteLength\n// 16\n```\n\nOr directly from objects:\n\n```ts\nlet bytes: Uint8Array = GameWorldState.encode( world );\n\nbytes.byteLength\n// 16\n```\n\n### Decode\n\n#### To Object\n\nDecode as a strongly-typed object.\n\n```ts\nlet obj = GameWorldData.decode( bytes );\n// { frameNo: number; timeRemaining: number; … }\n```\n\n#### In-place\n\nExtract fields directly into an existing object (this minimizes memory footprint).\n\n```ts\nlet obj: Decoded\u003ctypeof GameWorldData\u003e = {} as any;\n\nGameWorldData.decodeInPlace( bytes, obj );\n```\n\n#### Parser \u0026ndash; Decoding registered formats\n\n- Register formats with `.on(format, handler, options?)`\n- Trigger format handlers with `.processBuffer(bytes)`\n\n```ts\nimport { bufferParser } from 'tinybuf';\n\n// register\nconst parser = bufferParser()\n  .on(MyChatMessage, msg =\u003e myHud.showChat(msg))\n  .on(GameWorldData, data =\u003e myWorld.update(data), {\n    decodeInPlace: true, // `data` gets recycled\n  });\n\n// parse\nparser.processBuffer( bytes );\n```\n\n## Types\n\n| **Type** | **JavaScript Type** | **Bytes** | **Notes** |\n| :--- | :--- | :--- | :--- |\n| `Int` | `number` | 1-4\u003csup\u003e\\*\u003c/sup\u003e | A signed integer from `-Number.MAX_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`. |\n| `Int8` | `number` | 1 | A signed integer from -128 to 127. |\n| `Int16` | `number` | 2 | A signed integer from -32,768 to 32,767. |\n| `Int32` | `number` | 4 | A signed integer from -2,147,483,648 to 2,147,483,647. |\n| `UInt` | `number` | 1-4\u003csup\u003e#\u003c/sup\u003e | An unsigned integer from 0 to `Number.MAX_SAFE_INTEGER`. |\n| `UInt8` | `number` | 1 | An unsigned integerfrom 0 to 255. |\n| `UInt16` | `number` | 2 | An unsigned integer from 0 to 65,535. |\n| `UInt32` | `number` | 4 | An unsigned integer from 0 to 4,294,967,295. |\n| `Float64` | `number` | 8 | A 64-bit double-precision floating-point number. |\n| `Float32` | `number` | 4 | A 32-bit single-precision floating-point number. |\n| `Float16` | `number` | 2 | A 16-bit half-precision floating-point number.\u003cbr/\u003e**Note:** Low precision. Maximum effective range ±65,504. |\n| `BFloat16` | `number` | 2 | A [bfloat16](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format) format 16-bit half-precision floating-point number.\u003cbr/\u003e**Note:** Lowest precision. Same effective range as `Float32`. |\n| `Scalar` | `number` | 1 | A signed scalar between -1.00 and 1.00 (two decimal precision). |\n| `UScalar` | `number` | 1 | A scalar between 0.00 and 1.00 (two decimal precision). |\n| `Bool` | `boolean` | 1 | A boolean value. |\n| `Bools` | `boolean[]` | 1\u003csup\u003e¶\u003c/sup\u003e | An array/tuple of boolean values (1 - 28) encoded as a single byte. |\n| `Buffer` | `Uint8Array` | 1\u003csup\u003e†\u003c/sup\u003e\u0026nbsp;+\u0026nbsp;n | An `ArrayBuffer` or `ArrayBufferLike`. |\n| `String` | `string` | 1\u003csup\u003e†\u003c/sup\u003e\u0026nbsp;+\u0026nbsp;n | A string (UTF-8 encoded). |\n| `JSON` | `any` | 1\u003csup\u003e†\u003c/sup\u003e\u0026nbsp;+\u0026nbsp;n | Any JSON encodable value (encoded as a string). |\n| `RegExp` | `RegExp` | 2\u003csup\u003e†\u003c/sup\u003e\u0026nbsp;+\u0026nbsp;n | JavaScript `RegExp` object. |\n| `Date` | `Date` | 8 | JavaScript `Date` object. |\n\n## 📘 Documentation\n| | |\n| --- | :--- |\n| 🏁 **Quick start:** | [Quick start guide](https://github.com/reececomo/tinybuf/blob/main/docs/get_started.md),\u003cbr/\u003e[Types](https://github.com/reececomo/tinybuf/blob/main/docs/types.md) |\n| 📑 **Advanced:** | [Async safety mode](https://github.com/reececomo/tinybuf/blob/main/docs/safe_encode.md),\u003cbr/\u003e[Format header collisions](https://github.com/reececomo/tinybuf/blob/main/docs/format_headers.md),\u003cbr/\u003e[Compression tips](https://github.com/reececomo/tinybuf/blob/main/docs/compression_tips.md),\u003cbr/\u003e[Validation/transforms](https://github.com/reececomo/tinybuf/blob/main/docs/validation_and_transforms.md) |\n\n## Credits\n\n_**tinybuf** is based on Guilherme Souza's [js-binary](https://github.com/sitegui/js-binary)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freececomo%2Ftinybuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freececomo%2Ftinybuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freececomo%2Ftinybuf/lists"}