{"id":22343043,"url":"https://github.com/wiiseguy/node-streambuf","last_synced_at":"2025-07-25T01:07:18.572Z","repository":{"id":54456844,"uuid":"115533607","full_name":"Wiiseguy/node-streambuf","owner":"Wiiseguy","description":"Streamed Buffers - .NET's BinaryReader facsimile","archived":false,"fork":false,"pushed_at":"2024-07-04T16:43:45.000Z","size":3193,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-06T07:16:06.510Z","etag":null,"topics":["binary-reader","buffered-reader","buffers","node","streams"],"latest_commit_sha":null,"homepage":null,"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/Wiiseguy.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":null,"support":null}},"created_at":"2017-12-27T15:23:44.000Z","updated_at":"2024-07-04T16:43:47.000Z","dependencies_parsed_at":"2023-02-17T14:45:24.306Z","dependency_job_id":null,"html_url":"https://github.com/Wiiseguy/node-streambuf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wiiseguy%2Fnode-streambuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wiiseguy%2Fnode-streambuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wiiseguy%2Fnode-streambuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wiiseguy%2Fnode-streambuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wiiseguy","download_url":"https://codeload.github.com/Wiiseguy/node-streambuf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228070595,"owners_count":17864664,"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-reader","buffered-reader","buffers","node","streams"],"created_at":"2024-12-04T08:14:37.714Z","updated_at":"2024-12-04T08:14:38.203Z","avatar_url":"https://github.com/Wiiseguy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# streambuf - Stream Buffers ![Node.js CI](https://github.com/Wiiseguy/node-streambuf/actions/workflows/node.js.yml/badge.svg)  [![codecov](https://codecov.io/gh/Wiiseguy/node-streambuf/branch/master/graph/badge.svg?token=GEQAA2HHGY)](https://codecov.io/gh/Wiiseguy/node-streambuf) ![npm](https://img.shields.io/npm/v/streambuf)\n\u003e Stream Buffers - .NET's BinaryReader facsimile for Node.js\n\nThis library wraps most of [Buffer](https://nodejs.org/api/buffer.html)'s methods. The difference with Buffer is that with streambuf you don't have to specify an offset each read/write operation, it uses an internal cursor. \n\n`streambuf` offers a low-level API that similar to C++'s [fstream/iostream/etc.](https://www.cplusplus.com/reference/iolibrary/) or .NET's [BinaryReader/BinaryWriter](https://docs.microsoft.com/en-us/dotnet/api/system.io).\n\nIf you're looking for a library that is more high-level and built on top of `streambuf`, check out [node-structor](https://github.com/Wiiseguy/node-structor).\n\n## Install\n\n```\n$ npm install streambuf\n```\n\n\n## Usage\n\n```js\nconst fs = require('fs');\nconst { StreamBuffer } = require('streambuf');\n\nlet buffer = StreamBuffer.from(fs.readFileSync('hiscore.dat'));\n\nlet nameLength = buffer.readUInt32LE();\nlet name = buffer.readString(nameLength);\n\nbuffer.skip(-nameLength); // go back to the beginning of the name\nbuffer.writeString(name.toUpperCase()); // overwrite the name in the buffer with something else\n\n```\n\nRefer to [Buffer](https://nodejs.org/api/buffer.html) for a list of available read and write methods supported by StreamBuffer (omit the offset param).\n\n## API\n\nStreamBuffer(Buffer)\n---\nConstructor: initialize with a Buffer object.\n\nStreamBuffer(StreamBuffer)\n--- \nConstructor: initialize with another StreamBuffer object's underlying Buffer.\n\nStreamBuffer numeric methods\n---\nreadInt8, readInt16LE, readInt16BE, readInt32LE, readInt32BE, readIntLE, readIntBE,\nreadUInt8, readUInt16LE, readUInt16BE, readUInt32LE, readUInt32BE, readUIntLE, readUIntBE,\nreadFloatLE, readFloatBE, readDoubleLE, readDoubleBE\nwriteInt8, writeInt16LE, writeInt16BE, writeInt32LE, writeInt32BE, writeIntLE, writeIntBE,\nwriteUInt8, writeUInt16LE, writeUInt16BE, writeUInt32LE, writeUInt32BE, \nwriteFloatLE, writeFloatBE, writeDoubleLE, writeDoubleBE\n\nStreamBuffer BigInt methods\n---\nreadBigInt64LE, readBigInt64BE, readBigUInt64LE, readBigUInt64BE,\nwriteBigInt64LE, writeBigInt64BE, writeBigUInt64LE, writeBigUInt64BE\n\n.buffer\n---\nProvides raw access to the underlying Buffer object (read-only)\n\n.read(numBytes)\n---\nReturns a new StreamBuffer that references the same Buffer as the original, but cropped by offset and offset + numBytes.\n\n.write(buffer: Buffer)\n---\nWrites the contents of another Buffer.\n\n.readByte()\n---\nAlias for .readUInt8()\n\n.readSByte()\n---\nAlias for .readInt8()\n\n.writeByte()\n---\nAlias for .writeUInt8()\n\n.writeSByte()\n---\nAlias for .writeInt8()\n\n.read7BitInt()\n---\nReads a 7 bit encoded integer, like those used by [.NET](https://msdn.microsoft.com/en-us/library/system.io.binarywriter.write7bitencodedint(v=vs.110).aspx)\n\n.write7BitInt()\n---\nWrites a 7 bit encoded integer, like those used by [.NET](https://msdn.microsoft.com/en-us/library/system.io.binarywriter.write7bitencodedint(v=vs.110).aspx)\n\n.readChar([encoding])\n---\nReads a single character from the buffer according to the specified character encoding. Multi-byte characters are not read - use `readString` for that instead.\n'encoding' defaults to utf8.\n\n.writeChar([encoding])\n---\nWrites a single character to the buffer according to the specified character encoding. Multi-byte characters are not written - use `writeString` for that instead.\n'encoding' defaults to utf8.\n\n.readString([length, [encoding]])\n---\nDecodes to a string according to the specified character encoding in encoding and length.\n'encoding' defaults to utf8.\n'length' is optional. If left undefined, it will use the first occurrence of a zero (0) byte as the end of the string.\n\n.writeString(str, [encoding])\n---\nWrites a string to the underlying buffer with the specified encoding.\n'encoding' defaults to utf8.\n\n.peekString([length, [encoding]])\n---\nFunctions the same way as .readString(), but does not update the offset.\n\n.readString0([encoding])\n---\nReads a string from the buffer according to the specified character encoding, stopping at the first zero (0) byte. Similar to calling .readString() without a length parameter, but more implicit.\n'encoding' defaults to utf8.\n\n.writeString0(str, [encoding])\n---\nWrites a string to the underlying buffer with the specified encoding, followed by a zero (0) byte.\n'encoding' defaults to utf8.\n\n.readString7([encoding])\n---\nA specialized version of readString(), it first reads a 7 bit encoded integer and uses that as the length of the to be read string. Can be used to read strings written by .NET's BinaryWriter.\n\n.writeString7([encoding])\n---\nA specialized version of writeString(), it first writes a 7 bit encoded integer representing the length of the string, followed by the string. \n\n.skip(numBytes)\n---\nSkips the specified number of bytes. A negative number can be used to rewind.\n\n.setPos(pos) / .seek(pos)\n---\nMoves the offset to the specified pos.\n\n.getPos() / .tell()\n---\nReturns the current offset.\n\n.rewind()\n---\nMoves the offset back to 0.\n\n.isEOF()\n---\nReturns true if the end of the buffer is reached. (offset \u003e= buffer.length)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiiseguy%2Fnode-streambuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiiseguy%2Fnode-streambuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiiseguy%2Fnode-streambuf/lists"}