{"id":22425553,"url":"https://github.com/danprince/tiny-binary-format","last_synced_at":"2025-07-09T18:33:49.012Z","repository":{"id":35430546,"uuid":"39696346","full_name":"danprince/tiny-binary-format","owner":"danprince","description":"Memory efficient binary formats instead of objects.","archived":false,"fork":false,"pushed_at":"2016-04-07T09:23:41.000Z","size":18,"stargazers_count":142,"open_issues_count":2,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-06-22T03:07:39.007Z","etag":null,"topics":["binary","bitwise-operators"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/danprince.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}},"created_at":"2015-07-25T17:46:43.000Z","updated_at":"2024-12-03T15:01:08.000Z","dependencies_parsed_at":"2022-08-31T09:20:19.167Z","dependency_job_id":null,"html_url":"https://github.com/danprince/tiny-binary-format","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/danprince/tiny-binary-format","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danprince%2Ftiny-binary-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danprince%2Ftiny-binary-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danprince%2Ftiny-binary-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danprince%2Ftiny-binary-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danprince","download_url":"https://codeload.github.com/danprince/tiny-binary-format/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danprince%2Ftiny-binary-format/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263645556,"owners_count":23494005,"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","bitwise-operators"],"created_at":"2024-12-05T19:14:32.724Z","updated_at":"2025-07-09T18:33:48.969Z","avatar_url":"https://github.com/danprince.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Travis Status](https://travis-ci.org/danprince/tiny-binary-format.svg)\n\n# tiny-binary-format\nMemory efficient JS using binary formats instead of objects.\n\n```js\nvar BinaryFormat = require('tiny-binary-format');\n\nvar Tile = new BinaryFormat([\n  { length: 8, name: 'type' },\n  { length: 8, name: 'height' },\n  { length: 1, name: 'vegetation' }\n]);\n\nTile.pack(4, 48, 1);\n// 000000100001100001 (2145)\n\nTile.unpack(2145);\n// { type: 4, height: 48, vegetation: 1 }\n\nTile.unpackArray(2145);\n// [4, 48, 1]\n```\n\nThis library is designed to be used as a very thin wrapper around dealing with binary data yourself.\n\nDefine a format by creating an instance of `BinaryFormat` and passing in your field specifications. Then call the resulting object, passing instance data as arguments in order to create a binary representation.\n\nWhen you need to read the values back, pass the number to either `.unpack` which returns the values in an object, or `.unpackArray` which returns them in an array.\n\n## Install\n\n```bash\nnpm install tiny-binary-format\n# or\nbower install tiny-binary-format\n```\n\n## Gotchas\nThe module was designed for storing lightweight tile representations for games, however it could be used for a lot of other things too. Just remember that once the data has been serialized, __it will always be read back out as numbers__.\n\nThis module should be used for removing the _neccessity_ of working with bitwise operators when dealing with binary formats. It's not a framework and it won't hold your hand.\n\nThis module __does no error handling whatsoever__. If you care enough about performance to be using a binary format in the first place, then you'll appreciate the transparency of the pack and unpack methods.\n\nHowever, this does mean that if you pass in a 9 bit number into an 8 bit field, you'll lose precision silently. Use it carefully.\n\nAs pointed out by [@dioxmat](https://twitter.com/dioxmat), you're still bound by the restrictions of [MAX_SAFE_INTEGER](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER). If you're dealing with integers greater than `2 ^ 53`, then expect things to break.\n\n## FAQ\n#### What if I need to store strings or objects too?\nIf you arrived here looking for a Javascript library for parsing binary format files that include lots of data types, you've come to the wrong place. Go and check out [binary-format](https://www.npmjs.com/package/binary-format)\n#### It doesn't seem to work for 64 bit floating numbers?\nThat's because the Javascript bitwise operators don't either. For a quick workaround, use the [`64-bit-support` branch](https://github.com/danprince/tiny-binary-format/tree/64-bit-support).\n#### What would be a good use case for this library?\nThis code was born from a game engine, read more about where it might be useful in the [accompanying blog blost](http://danthedev.com/2015/07/25/binary-in-javascript).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanprince%2Ftiny-binary-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanprince%2Ftiny-binary-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanprince%2Ftiny-binary-format/lists"}