{"id":21667011,"url":"https://github.com/princexz/binary_trees","last_synced_at":"2025-03-20T06:48:13.965Z","repository":{"id":148304759,"uuid":"608383680","full_name":"Princexz/binary_trees","owner":"Princexz","description":"Read and write binary types in files","archived":false,"fork":false,"pushed_at":"2023-03-01T22:57:37.000Z","size":58,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T08:25:53.892Z","etag":null,"topics":["binary","binaryfiles","config","gui","gui-application"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Princexz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-03-01T22:47:04.000Z","updated_at":"2024-11-10T17:33:54.000Z","dependencies_parsed_at":"2023-05-19T17:15:26.943Z","dependency_job_id":null,"html_url":"https://github.com/Princexz/binary_trees","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/Princexz%2Fbinary_trees","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Princexz%2Fbinary_trees/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Princexz%2Fbinary_trees/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Princexz%2Fbinary_trees/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Princexz","download_url":"https://codeload.github.com/Princexz/binary_trees/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244566931,"owners_count":20473451,"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","binaryfiles","config","gui","gui-application"],"created_at":"2024-11-25T11:32:01.504Z","updated_at":"2025-03-20T06:48:13.943Z","avatar_url":"https://github.com/Princexz.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003eC - Binary trees\u003c/h1\u003e\n\nbinary-file\n===========\n\n[![NPM version](https://img.shields.io/npm/v/binary-file.svg)](https://www.npmjs.com/package/binary-file) ![Node version](https://img.shields.io/node/v/binary-file.svg)\n\nRead and write binary types in files.\nThis library allows you to use the functions you would use on a Buffer, like readUInt32, directly on files.\nIt is promises-based.\n\n```\nnpm install --save binary-file\n```\n\n## Use case\n\nSay you want to parse a simple binary file for an UInt32 containing the length of the string that follows. With binary-file, you can simply:\n\n```javascript\n'use strict';\n\nconst BinaryFile = require('binary-file');\n\nconst myBinaryFile = new BinaryFile('./file.bin', 'r');\nmyBinaryFile.open().then(function () {\n  console.log('File opened');\n  return myBinaryFile.readUInt32();\n}).then(function (stringLength) {\n  return myBinaryFile.readString(stringLength);\n}).then(function (string) {\n  console.log(`File read: ${string}`);\n  return myBinaryFile.close();\n}).then(function () {\n  console.log('File closed');\n}).catch(function (err) {\n  console.log(`There was an error: ${err}`);\n});\n```\n\nAnd it looks even better with ES7 async / await:\n\n```javascript\n'use strict';\n\nconst BinaryFile = require('binary-file');\n\nconst myBinaryFile = new BinaryFile('./file.bin', 'r');\n(async function () {\n  try {\n    await myBinaryFile.open();\n    console.log('File opened');\n    const stringLength = await myBinaryFile.readUInt32();\n    const string = await myBinaryFile.readString(stringLength);\n    console.log(`File read: ${string}`);\n    await myBinaryFile.close();\n    console.log('File closed');\n  } catch (err) {\n    console.log(`There was an error: ${err}`);\n  }\n})();\n```\n\nYou don't have to create a Buffer to write the data read from the file, you don't have to remember the position of the cursor: everything is handled by BinaryFile.\n\n## API\n\n### File\n\n#### `new BinaryFile(path, mode, littleEndian = false)`\n\nCreate a new instance of BinaryFile.\n\n* `path`: the path of the file to open\n* `mode`: the mode in which to open the file. See [fs.open](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback)\n* `littleEndian`: endianness of the file\n\n#### `.open()`\n\nOpen the file.\n\nReturn a promise.\n\n**fulfilled** when the file is opened\n\n#### `.size()`\n\nGet the size in bytes of the file.\n\nReturn a promise.\n\n**fulfilled** with the size of the file in bytes\n\n#### `.tell()`\n\nGet the position of the cursor in the file.\n\nReturn the position of the cursor in the file.\n\n#### `.seek(position)`\n\nSet the position of the cursor in the file\n\n* `position`: the position where to place the cursor\n\nReturn the new position.\n\n#### `.close()`\n\nClose the file.\n\nReturn a promise.\n\n**fulfilled** when the file is closed\n\n### Read\n\n#### `.read(length, position = null)`\n\nRead a Buffer in the file.\n\n* `length`: the number of bytes to read\n* `position`: the position where to read the Buffer in the file. If not set, it will use the internal cursor. If set, the internal cursor won't move\n\nReturn a promise.\n\n**fulfilled** with the Buffer when the reading is done\n\n#### `.readInt8(position = null)`,\n#### `.readUInt8(position = null)`,\n#### `.readInt16(position = null)`,\n#### `.readUInt16(position = null)`,\n#### `.readInt32(position = null)`,\n#### `.readUInt32(position = null)`,\n#### `.readInt64(position = null)`,\n#### `.readUInt64(position = null)`,\n#### `.readFloat(position = null)`,\n#### `.readDouble(position = null)`\n\nRead a binary type in the file.\n\n* `position`: the position where to read the binary type in the file. If not set, it will use the internal cursor. If set, the internal cursor won't move\n\nReturn a promise.\n\n**fulfilled** with the value read when the reading is done\n\n#### `.readString(length, position = null)`\n\nRead a string in the file.\n\n* `length`: the number of bytes of the string to read\n* `position`: the position where to read the string in the file. If not set, it will use the internal cursor. If set, the internal cursor won't move\n\nReturn a promise.\n\n**fulfilled** with the string read when the reading is done\n\n### Write\n\n#### `.write(buffer, position = null)`\n\nRead a Buffer in the file.\n\n* `buffer`: the Buffer to write\n* `position`: the position where to write the Buffer in the file. If not set, it will use the internal cursor. If set, the internal cursor won't move\n\nReturn a promise.\n\n**fulfilled** with the number of bytes written when the writing is done\n\n#### `.writeInt8(value, position = null)`,\n#### `.writeUInt8(value, position = null)`,\n#### `.writeInt16(value, position = null)`,\n#### `.writeUInt16(value, position = null)`,\n#### `.writeInt32(value, position = null)`,\n#### `.writeUInt32(value, position = null)`,\n#### `.writeInt64(value, position = null)`,\n#### `.writeUInt64(value, position = null)`,\n#### `.writeFloat(value, position = null)`,\n#### `.writeDouble(value, position = null)`\n\nWrite a binary type in the file.\n\n* `value`: the value to write in the corresponding binary type\n* `position`: the position where to write the binary type in the file. If not set, it will use the internal cursor. If set, the internal cursor won't move\n\nReturn a promise.\n\n**fulfilled** with the number of bytes written when the writing is done\n\n#### `.writeString(string, position = null)`\n\nWrite a string in the file.\n\n* `string`: the string to write\n* `position`: the position where to write the string in the file. If not set, it will use the internal cursor. If set, the internal cursor won't move\n\nReturn a promise.\n\n**fulfilled** with the number of bytes written when the writing is done\n\n## Author :black_nib:\n\n* __Prince Solomon__ [princexz](https://github.com/princexz)\n\n## Acknowledgements :pray:\n\nAll work contained in this project was completed as part of the curriculum for ALX Africa SE. ALX Africa is an online full-stack software engineering program that prepares students for careers in the tech industry using project-based peer learning. For more information, visit [this link](https://www.alxafrica.com/).\n\n\u003cp align=\"center\"\u003e\n  \u003cimg\n   src=\"https://www.alxafrica.com/wp-content/uploads/2022/01/header-logo.png\"\n       alt=\"ALX Africa Logo\"\n  \u003e\n\u003c/p\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincexz%2Fbinary_trees","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprincexz%2Fbinary_trees","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincexz%2Fbinary_trees/lists"}