{"id":17196592,"url":"https://github.com/johnnovak/nim-binstreams","last_synced_at":"2026-03-08T16:01:50.089Z","repository":{"id":70773300,"uuid":"245529438","full_name":"johnnovak/nim-binstreams","owner":"johnnovak","description":"Endianness aware binary streams for Nim","archived":false,"fork":false,"pushed_at":"2024-03-06T11:04:35.000Z","size":122,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-26T19:42:10.623Z","etag":null,"topics":["binary-stream","endianness","nim","nim-lang","streams"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnnovak.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"COPYING","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}},"created_at":"2020-03-06T22:39:38.000Z","updated_at":"2025-02-06T20:15:37.000Z","dependencies_parsed_at":"2023-03-17T09:45:35.291Z","dependency_job_id":null,"html_url":"https://github.com/johnnovak/nim-binstreams","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/johnnovak/nim-binstreams","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnnovak%2Fnim-binstreams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnnovak%2Fnim-binstreams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnnovak%2Fnim-binstreams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnnovak%2Fnim-binstreams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnnovak","download_url":"https://codeload.github.com/johnnovak/nim-binstreams/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnnovak%2Fnim-binstreams/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30263672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T14:54:00.943Z","status":"ssl_error","status_checked_at":"2026-03-08T14:53:54.486Z","response_time":56,"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":["binary-stream","endianness","nim","nim-lang","streams"],"created_at":"2024-10-15T01:53:41.489Z","updated_at":"2026-03-08T16:01:50.048Z","avatar_url":"https://github.com/johnnovak.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nim-binstreams\r\n\r\n**nim-binstreams** is a no-dependencies Nim library that provides endianness\r\naware binary streams. It is a wrapper over the standard `io` module, and it\r\nuses [stew/endians2](https://github.com/status-im/nim-stew/blob/master/stew/endians2.nim)\r\nfor endianness conversions (included in the project), so it should be\r\nreasonably fast.\r\n\r\nMain features:\r\n\r\n* Support for file and memory buffer backed streams through a single interface\r\n* Possibility to switch the endianness of a stream on the fly\r\n* Mixed read/write streams are supported\r\n* Generics-friendly API\r\n\r\n\r\n## Installation\r\n\r\n**nim-binstreams** can be installed via Nimble:\r\n\r\n    nimble install binstreams\r\n\r\n\r\n## Usage\r\n\r\nThe below example should give you a fairly good idea of the basic usage.\r\nPlease refer to the API documentation for further details.\r\n\r\n\r\n```nim\r\nimport binstreams\r\n\r\n# Create a new big-endian file stream for writing.\r\n# File modes work exactly like with `open`.\r\nvar fs = newFileStream(\"outfile\", bigEndian, fmWrite)\r\n\r\n# There's just a single generic `write()` proc to write single values.\r\n# The width of the value written is determined by the type of the passed in\r\n# argument. Endianness conversions are handled automatically, if required.\r\nfs.write(3'i8)\r\nfs.write(42'i16)\r\nfs.write(0xcafe'u16)\r\nfs.write('X')\r\nfs.write(true)\r\n\r\n# Writing multiple values from a buffer (openArray) is just as easy.\r\nvar buf = newSeq[float32](100)\r\nfs.write(buf, startIndex=5, numValues=30)\r\n\r\n# It is possible to change the endiannes of the stream on-the-fly.\r\nfs.endian = littleEndian\r\nfs.write(12.34'f32)\r\nfs.write(0xcafebabe'i32)\r\nfs.endian = bigEndian\r\nfs.write(0xffee81'u64)\r\n\r\n# Helper for writing strings\r\nfs.writeStr(\"some UTF-8 string\")\r\n\r\n# The file position can be queried and changed at any time.\r\nlet pos = fs.getPosition()\r\nfs.setPosition(0)\r\nfs.write(88'u8)\r\nfs.setPosition(pos)\r\nfs.write(12'i16)\r\n\r\nfs.close()\r\n\r\n\r\n# It is possible to create a new stream from a valid file handle.\r\nvar f = open(\"infile\")\r\nfs = newFileStream(f, bigEndian)\r\n\r\n# The type of the value needs to be specified when doing single-value reads.\r\necho fs.read(int8)\r\necho fs.read(uint8)\r\n\r\nfs.endian = littleEndian\r\necho fs.read(int16)\r\necho fs.read(float32)\r\necho fs.read(bool)\r\necho fs.read(char)\r\necho fs.readStr(10)\r\n\r\n# Reading multiple values into a buffer\r\nfs.setPosition(5)\r\nvar readBuf = newSeq[int16](30)\r\nfs.read(buf, startIndex=5, numValues=10)\r\n```\r\n\r\n## License\r\n\r\nCopyright © 2020-2024 John Novak \u003c\u003cjohn@johnnovak.net\u003e\u003e\r\n\r\nThis work is free. You can redistribute it and/or modify it under the terms of\r\nthe [Do What The Fuck You Want To Public License, Version 2](http://www.wtfpl.net/), as published\r\nby Sam Hocevar. See the [COPYING](./COPYING) file for more details.\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnnovak%2Fnim-binstreams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnnovak%2Fnim-binstreams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnnovak%2Fnim-binstreams/lists"}