{"id":28200989,"url":"https://github.com/cmdruid/buffy","last_synced_at":"2026-02-07T09:32:07.888Z","repository":{"id":270944412,"uuid":"911944567","full_name":"cmdruid/buffy","owner":"cmdruid","description":"A compact byte manipulation tool.","archived":false,"fork":false,"pushed_at":"2025-09-18T06:34:46.000Z","size":154,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-23T17:11:46.805Z","etag":null,"topics":[],"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/cmdruid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-04T09:09:11.000Z","updated_at":"2025-09-18T06:34:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"6a738801-c05e-464d-a69e-194957df7bef","html_url":"https://github.com/cmdruid/buffy","commit_stats":null,"previous_names":["cmdruid/buffy"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cmdruid/buffy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fbuffy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fbuffy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fbuffy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fbuffy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmdruid","download_url":"https://codeload.github.com/cmdruid/buffy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdruid%2Fbuffy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29191403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T07:37:03.739Z","status":"ssl_error","status_checked_at":"2026-02-07T07:37:03.029Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2025-05-16T22:15:08.758Z","updated_at":"2026-02-07T09:32:07.883Z","avatar_url":"https://github.com/cmdruid.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @vbyte/buff\n\nA compact swiss-army-knife for byte manipulation.\n\nFeatures:\n * Move between data formats with ease!\n * `Buff` objects are instance of `Uint8Array`.\n * Prepend, append, sort, split, chunk, join, and more!\n * Convert blobs of data into consumable streams.\n * Uses `DataView.setUint8` for ultra-fast performance.\n * Supports endianness for all the things!\n\n## How to Import\n\nThis library is designed to support classic and modern ESM imports, both in nodejs and a browser environment.\n\nExample install via package manager:\n\n```bash\nnpm  install @vbyte/buff\nbun  install @vbyte/buff\nyarn add     @vbyte/buff\n```\n\nClassic import into a nodejs project:\n\n```ts\nconst { Buff, Stream } = require('@vbyte/buff')\n```\n\nModern import into an nodejs project:\n\n```ts\nimport { Buff, Stream } from '@vbyte/buff'\n```\n\nClassic import into a browser-based project:\n\n```html\n\u003cscript src=\"https://unpkg.com/@vbyte/buff/dist/script.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const { Buff, Stream } = window.buff\n\u003c/script\u003e\n```\n\nModern import into a browser-based project:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { Buff, Stream } from \"https://unpkg.com/@vbyte/buff/dist/module.mjs\"\n\u003c/script\u003e\n```\n\n## How to Use\n\nThe `Buff` class is an extension of the base `Uint8Array` class. It provides the same default functionality of a Uint8Array, and can be used as a drop-in replacement for Uint8Array. Typescript will treat Buff as a Uint8Array object.\n\n```ts\nimport { Buff, Stream } from '@vbyte/buff'\n\n// Buffable covers value types that are convertable to Uint8Array.\ntype Buffable = Bytes | number | bigint\n// Bytes covers hex strings, byte arrays, Buff, and Stream objects.\ntype Bytes  = string | Uint8Array | Buff | Stream\n// You can optionally specify the endianness of data.\ntype Endian = 'le' | 'be'\n\nconst buffer = new Buff (\n  data    : Buffable | ArrayBuffer,\n  size   ?: number, // Specify the size of the array (for padding)\n  endian ?: Endian  // Specify the endianness of the array.\n)\n\n```\nYou can convert from many different types and formats into a `Buff` object.\n\n```ts\nBuff\n  .big   (data : bigint,     size ?: number, endian ?: Endian) =\u003e Buff\n  .bin   (data : string,     size ?: number, endian ?: Endian) =\u003e Buff\n  .bytes (data : Bytes,      size ?: number, endian ?: Endian) =\u003e Buff\n  .hex   (data : string,     size ?: number, endian ?: Endian) =\u003e Buff\n  .json  (data : T,          replacer ?: Replacer)             =\u003e Buff\n  .num   (data : number,     size ?: number, endian ?: Endian) =\u003e Buff\n  .str   (data : string,     size ?: number, endian ?: Endian) =\u003e Buff\n  .u8a   (data : Uint8Array, size ?: number, endian ?: Endian) =\u003e Buff\n```\n\nWith `Buff`, you have access to an extensive API for converting between formats.\n\n```ts\nconst buffer = new Buff(data)\n\n/* Quickly convert into many formats using getters. */\n\nbuffer\n  .arr     =\u003e number[]    // Convert to a number array.\n  .big     =\u003e bigint      // Convert to a BigInt.\n  .bin     =\u003e string      // Convert to a binary string.\n  .hex     =\u003e string      // Convert to a hex string.\n  .num     =\u003e number      // Convert to a Number.\n  .str     =\u003e string      // Convert to a UTF8 string.\n  .u8a     =\u003e Uint8Array  // Convert to a plain Uint8Array.\n\n/* There are a few export methods that support extra params. */\n\nbuffer\n  .to_arr  : ()                   =\u003e number[]\n  .to_big  : (endian ?: Endian)   =\u003e bigint\n  .to_bin  : ()                   =\u003e string\n  .to_hex  : (endian ?: Endian)   =\u003e string\n  .to_json : (reviver ?: Reviver) =\u003e T\n  .to_num  : (endian ?: Endian)   =\u003e number\n  .to_str  : ()                   =\u003e string\n  .to_u8a  : ()                   =\u003e Uint8Array\n```\n\nIn addition to format conversion, you can perform many other convenient tasks.\n\n```ts\nBuff\n  // Same as Uint8Array.from(), but returns a Buff object.\n  .from     (data : Uint8Array | number[]) =\u003e Buff\n  // Same as Uint8Array.of(), but returns a Buff object.\n  .of       (...data : number[]) =\u003e Buff\n  // Join together multiple arrays of bytes.\n  .join     (array : Buffable[]) =\u003e Buff\n  // Sort multiple arrays of bytes in lexicographic order.\n  .sort     (arr : Buffable[], size ?: number) =\u003e Buff[]\n  // Split bytes into equal-sized chunks.\n  .chunk    (payload : Bytes, chunk_size : number, total_size : number) =\u003e Buff[]\n  // Return a buffer object with random data (uses webcrypto).\n  .random   (size ?: number) =\u003e Buff\n  // Return a buffer containing the current Unix timestamp (4 bytes).\n  .now      () =\u003e Buff\n  // Converts a number into a 'varint' for byte streams.\n  .create_varint (num : number, endian ?: Endian) =\u003e Buff\n  // Check if two Buffable values are equal.\n  .is_equal (a : Buffable, b : Buffable) =\u003e boolean\n  // Check if a value is valid bytes (hex string or Uint8Array).\n  .is_bytes (value : unknown) =\u003e boolean\n  // Check if a string is valid hexadecimal.\n  .is_hex   (value : unknown) =\u003e boolean\n\nconst buffer = new Buff(data)\n\nbuffer\n  // Append data to your buffer object.\n  .append        (data : Buffable) =\u003e Buff\n  // Prepend data to your buffer object.\n  .prepend       (data : Buffable) =\u003e Buff\n  // Check if this buffer equals another.\n  .equals        (data : Buffable) =\u003e boolean\n  // Prepend a varint-encoded length prefix to this buffer.\n  .prefix_varint (endian ?: Endian) =\u003e Buff\n  // Same as Uint8Array.reverse(), but returns this Buff (chainable).\n  .reverse       () =\u003e this\n  // Identical to Uint8Array.set() method.\n  .set           (array : ArrayLike\u003cnumber\u003e, offset ?: number) =\u003e void\n  // Same as Uint8Array.slice(), but returns a Buff object.\n  .slice         (start ?: number, end ?: number) =\u003e Buff\n  // Same as Uint8Array.subarray(), but returns a Buff object.\n  .subarray      (begin ?: number, end ?: number) =\u003e Buff\n  // Returns the hex representation (used by JSON.stringify).\n  .toJSON        () =\u003e string\n  // Returns the hex representation as a string.\n  .toString      () =\u003e string\n```\n\nThe `Stream` class will take a blob of data and allow you to consume it byte-per-byte.\n\n```ts\nimport { Stream } from '@vbyte/buff'\n\n// Convert data into a stream object.\nconst stream = new Stream(data)\n\nstream\n  .size   =\u003e number  // Current number of bytes remaining in the stream.\n  .data   =\u003e Uint8Array  // Current stream data.\n\nstream\n  // Reads x number of bytes, does not consume the stream.\n  .peek   (size : number) =\u003e Buff\n  // Reads x number of bytes, consumes the stream.\n  .read   (size : number) =\u003e Buff\n  // Reads the next bytes(s) as a varint, returns the number value.\n  .read_varint (endian ?: Endian) =\u003e number\n```\n\n## Migration Guide\n\nIf upgrading from an earlier version, note the following API changes:\n\n- `Buff.blob()` renamed to `Buff.chunk()` - splits bytes into equal-sized chunks\n- `Buff.varint()` renamed to `Buff.create_varint()` - creates varint-encoded buffer\n\n## Security Considerations\n\n- **Cryptographic Random:** `Buff.random()` uses the Web Crypto API (`crypto.getRandomValues`) for cryptographically secure random bytes, with fallback to Node.js `crypto.randomBytes` in legacy environments\n- **Input Validation:** All public methods validate inputs. Hex strings are checked for valid characters and even length. Byte arrays are validated to contain integers in the 0-255 range\n- **Integer Safety:** Number conversions check against `Number.MAX_SAFE_INTEGER` and `Number.MIN_SAFE_INTEGER` to prevent precision loss\n- **Custom Error Types:** The library exports typed error classes (`ValidationError`, `HexValidationError`, `ByteRangeError`, `IntegerBoundsError`, `SizeError`) for precise error handling\n- **No Dependencies:** Zero production dependencies minimizes supply chain risk\n\n## Bugs / Issues\n\nPlease feel free to post any questions or bug reports on the issues page!\n\n## Development / Testing\n\nThis project uses `typescript` for development, `tape` for testing, and `rollup` for release bundles.\n\n```bash\nnpm test\nnpm run release\n```\n\n## Contributions\n\nAll contributions are welcome!\n\n## License\n\nUse this code however you like! No warranty!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmdruid%2Fbuffy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmdruid%2Fbuffy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmdruid%2Fbuffy/lists"}