{"id":15011486,"url":"https://github.com/pocketnode/binarystream","last_synced_at":"2025-04-12T03:31:41.687Z","repository":{"id":191583548,"uuid":"123226483","full_name":"pocketnode/binarystream","owner":"pocketnode","description":"BinaryStream implementation for Bun, Node.js, and Browser","archived":false,"fork":false,"pushed_at":"2024-06-12T02:37:43.000Z","size":67,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T23:34:28.279Z","etag":null,"topics":["binary","binary-stream","buffer","bun","node","typescript","web"],"latest_commit_sha":null,"homepage":"https://pocketnode.github.io/binarystream/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pocketnode.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":"2018-02-28T03:55:45.000Z","updated_at":"2024-06-21T12:20:07.000Z","dependencies_parsed_at":"2024-06-04T07:48:40.383Z","dependency_job_id":"12992d9c-9a0e-4ed6-8b52-8030006a75c3","html_url":"https://github.com/pocketnode/binarystream","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":0.2592592592592593,"last_synced_commit":"501e4780524eb5a6a3da3a887a3b5aba8f9c8c00"},"previous_names":["pocketnode/pocketnode-binarystream","pocketnode/binarystream"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketnode%2Fbinarystream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketnode%2Fbinarystream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketnode%2Fbinarystream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketnode%2Fbinarystream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pocketnode","download_url":"https://codeload.github.com/pocketnode/binarystream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328169,"owners_count":21085262,"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","binary-stream","buffer","bun","node","typescript","web"],"created_at":"2024-09-24T19:41:09.169Z","updated_at":"2025-04-12T03:31:41.431Z","avatar_url":"https://github.com/pocketnode.png","language":"TypeScript","readme":"# BinaryStream\n\n`BinaryStream` is an Typescript module designed to facilitate the reading and writing of binary data. This package uses the [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) and [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) interfaces, both of which are native to Javascript making it compatible with Node.js and browser environments.\n\n## Features\n\n-   Supports both Node.js and browser environments.\n-   Provides an easy-to-use API for handling binary data.\n-   Methods for reading and writing various data types (integers, floats, strings, etc.).\n-   Allows for dynamic buffer creation without worrying about sizing.\n\n## Installation\n\nYou can install the `BinaryStream` package via npm.\n\n```bash\nnpm install @pocketnode/binarystream\n```\n\nor\n\n```bash\nbun install @pocketnode/binarystream\n```\n\n## Usage\n\n### Importing the Module\n\n```typescript\n// Node.js, Bun, etc.\nimport BinaryStream from \"@pocketnode/binarystream\";\n\n// Browser from CDN\nimport BinaryStream from \"https://esm.run/@pocketnode/binarystream@latest/dist/BinaryStream.js\";\n```\n\n### Creating an Instance\n\nTo create a new instance of `BinaryStream`, you can either provide an existing `ArrayBuffer` or specify the size of a new buffer:\n\n```typescript\n// Create an empty BinaryStream\nconst stream = new BinaryStream();\n\n// Create a BinaryStream from an array of bytes\nconst bytes = BinaryStream.from([0xde, 0xad, 0xbe, 0xef]);\nbytes.toString(\"hex\"); // deadbeef\n\n// Create a BinaryStream from a string\nconst str = BinaryStream.from(\"\\xde\\xad\\xbe\\xef\", \"binary\");\nstr.toString(\"hex\"); // deadbeef\n\n// Create a BinaryStream from an existing ArrayBuffer\nconst blob = new Blob(..., {type: \"application/octet-stream\"});\nconst streamFromBuffer = BinaryStream.from(await blob.arrayBuffer());\n```\n\n### Example\n\nHere is an example demonstrating how to write and read data using `BinaryStream`:\n\n```typescript\nconst stream = new BinaryStream();\n\n// Write data to the stream\nstream.writeUInt8(255);\nstream.writeInt16(-32768);\nstream.writeFloat32(3.14);\nstream.writeString(\"Hello, BinaryStream!\");\n\n// Reset the position to the beginning of the stream for reading\nstream.flip();\n\n// Read data from the stream\nconst uint8 = stream.readUInt8();\nconst int16 = stream.readInt16();\nconst float32 = stream.readFloat32();\nconst str = stream.readString();\n\nconsole.log(uint8); // 255\nconsole.log(int16); // -32768\nconsole.log(float32); // 3.14\nconsole.log(str); // Hello, BinaryStream!\nconsole.log(stream.buffer); // Uint8Array (31) [255, 128, 0, 64, 72, 245, 195, 0, 0, 0, 20, 72, 101, 108, 108, 111, 44, 32, 66, 105, 110, 97, 114, 121, 83, 116, 114, 101, 97, 109, 33]\n```\n\n## License\n\nThis project is licensed under the GNU GPLv3 License. See the [LICENSE](LICENSE) file for details.\n\n## Contact\n\nFor questions or feedback, please open an issue on [GitHub](https://github.com/pocketnode/binarystream).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocketnode%2Fbinarystream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpocketnode%2Fbinarystream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocketnode%2Fbinarystream/lists"}