{"id":30143037,"url":"https://github.com/jsonjoy-com/buffers","last_synced_at":"2026-03-12T04:32:47.197Z","repository":{"id":307681917,"uuid":"1030404949","full_name":"jsonjoy-com/buffers","owner":"jsonjoy-com","description":"Essential Node.js and browser byte array manipulation tools","archived":false,"fork":false,"pushed_at":"2025-10-16T17:46:37.000Z","size":281,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-02T11:58:00.371Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsonjoy-com.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","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},"funding":{"github":"streamich"}},"created_at":"2025-08-01T15:25:00.000Z","updated_at":"2025-10-16T17:45:58.000Z","dependencies_parsed_at":"2025-08-01T16:05:14.338Z","dependency_job_id":"eb7be4e2-aab0-4407-9f2e-f49752e5f3a0","html_url":"https://github.com/jsonjoy-com/buffers","commit_stats":null,"previous_names":["jsonjoy-com/buffers"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/jsonjoy-com/buffers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonjoy-com%2Fbuffers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonjoy-com%2Fbuffers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonjoy-com%2Fbuffers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonjoy-com%2Fbuffers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsonjoy-com","download_url":"https://codeload.github.com/jsonjoy-com/buffers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonjoy-com%2Fbuffers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30415542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T04:25:42.844Z","status":"ssl_error","status_checked_at":"2026-03-12T04:25:34.624Z","response_time":114,"last_error":"SSL_read: 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-08-11T06:27:37.017Z","updated_at":"2026-03-12T04:32:47.181Z","avatar_url":"https://github.com/jsonjoy-com.png","language":"TypeScript","funding_links":["https://github.com/sponsors/streamich"],"categories":[],"sub_categories":[],"readme":"# buffers\n\nVarious helper utilities for working with buffers and binary data in TypeScript.\n\n## Installation\n\n```bash\nnpm install @jsonjoy.com/buffers\n```\n\n## Features\n\nThis package provides high-performance utilities for working with binary data, buffers, and UTF-8 text encoding/decoding. It includes optimized implementations for both Node.js and browser environments.\n\n## Core Classes\n\n### Writer\n\nA growable binary data writer with automatic buffer expansion.\n\n```typescript\nimport {Writer} from '@jsonjoy.com/buffers/lib/Writer';\n\nconst writer = new Writer();\nwriter.u8(0x42);          // Write unsigned 8-bit integer\nwriter.u16(0x1234);       // Write unsigned 16-bit integer\nwriter.u32(0x12345678);   // Write unsigned 32-bit integer\nwriter.u64(0x123456789abcdefn); // Write unsigned 64-bit integer\nwriter.f32(3.14);         // Write 32-bit float\nwriter.f64(3.141592653589793); // Write 64-bit float\nwriter.utf8('Hello 🌍');  // Write UTF-8 string\nwriter.ascii('Hello');    // Write ASCII string\n\nconst data = writer.flush(); // Get written data as Uint8Array\n```\n\n### Reader\n\nA binary data reader for parsing binary buffers.\n\n```typescript\nimport {Reader} from '@jsonjoy.com/buffers/lib/Reader';\n\nconst reader = new Reader();\nreader.reset(someUint8Array);\n\nconst byte = reader.u8();     // Read unsigned 8-bit integer\nconst word = reader.u16();    // Read unsigned 16-bit integer\nconst dword = reader.u32();   // Read unsigned 32-bit integer\nconst qword = reader.u64();   // Read unsigned 64-bit integer\nconst float = reader.f32();   // Read 32-bit float\nconst double = reader.f64();  // Read 64-bit float\nconst text = reader.utf8(5);  // Read UTF-8 string of 5 bytes\nconst ascii = reader.ascii(5); // Read ASCII string of 5 characters\n```\n\n### StreamingReader\n\nA streaming binary reader that can handle data arriving in chunks.\n\n```typescript\nimport {StreamingReader} from '@jsonjoy.com/buffers/lib/StreamingReader';\n\nconst reader = new StreamingReader();\nreader.push(chunk1);\nreader.push(chunk2);\n\n// Read data as it becomes available\nconst value = reader.u32();\nreader.consume(); // Mark consumed data for cleanup\n```\n\n### StreamingOctetReader\n\nA specialized streaming reader for byte-oriented protocols with optional XOR masking.\n\n```typescript\nimport {StreamingOctetReader} from '@jsonjoy.com/buffers/lib/StreamingOctetReader';\n\nconst reader = new StreamingOctetReader();\nreader.push(dataChunk);\n\nconst byte = reader.u8();\nconst masked = reader.bufXor(length, [0x12, 0x34, 0x56, 0x78], 0);\n```\n\n## Utility Functions\n\n### Buffer Operations\n\n```typescript\n// Array creation and manipulation\nimport {b} from '@jsonjoy.com/buffers/lib/b';\nimport {concat, concatList} from '@jsonjoy.com/buffers/lib/concat';\nimport {copy} from '@jsonjoy.com/buffers/lib/copy';\n\nconst buffer = b(0x48, 0x65, 0x6c, 0x6c, 0x6f); // Create from bytes\nconst combined = concat(buffer1, buffer2);         // Concatenate two buffers\nconst list = concatList([buf1, buf2, buf3]);      // Concatenate array of buffers\nconst duplicate = copy(originalBuffer);           // Copy buffer\n```\n\n### Comparison Functions\n\n```typescript\nimport {cmpUint8Array} from '@jsonjoy.com/buffers/lib/cmpUint8Array';\nimport {cmpUint8Array2} from '@jsonjoy.com/buffers/lib/cmpUint8Array2';\nimport {cmpUint8Array3} from '@jsonjoy.com/buffers/lib/cmpUint8Array3';\n\nconst isEqual = cmpUint8Array(buf1, buf2);        // Returns boolean\nconst comparison = cmpUint8Array2(buf1, buf2);    // Returns -1, 0, or 1 (byte-first)\nconst comparison2 = cmpUint8Array3(buf1, buf2);   // Returns -1, 0, or 1 (length-first)\n```\n\n### Type Checking\n\n```typescript\nimport {isUint8Array} from '@jsonjoy.com/buffers/lib/isUint8Array';\nimport {isArrayBuffer} from '@jsonjoy.com/buffers/lib/isArrayBuffer';\nimport {isFloat32} from '@jsonjoy.com/buffers/lib/isFloat32';\n\nif (isUint8Array(data)) { /* data is Uint8Array or Buffer */ }\nif (isArrayBuffer(data)) { /* data is ArrayBuffer */ }\nif (isFloat32(3.14)) { /* number can fit in float32 */ }\n```\n\n### Conversion Functions\n\n```typescript\nimport {toUint8Array} from '@jsonjoy.com/buffers/lib/toUint8Array';\nimport {bufferToUint8Array} from '@jsonjoy.com/buffers/lib/bufferToUint8Array';\nimport {toBuf} from '@jsonjoy.com/buffers/lib/toBuf';\n\nconst uint8 = toUint8Array(data);           // Convert various types to Uint8Array\nconst converted = bufferToUint8Array(buf);  // Convert Buffer to Uint8Array\nconst encoded = toBuf('Hello 🌍');          // Convert string to UTF-8 bytes\n```\n\n### String Utilities\n\n```typescript\nimport {ascii, utf8} from '@jsonjoy.com/buffers/lib/strings';\n\nconst asciiBytes = ascii`Hello World`;      // ASCII string to bytes\nconst utf8Bytes = utf8`Hello 🌍`;           // UTF-8 string to bytes\n```\n\n## UTF-8 Encoding/Decoding\n\n### High-Performance UTF-8 Decoding\n\n```typescript\nimport {decodeUtf8} from '@jsonjoy.com/buffers/lib/utf8/decodeUtf8';\n\nconst text = decodeUtf8(uint8Array, offset, length);\n```\n\nThe package includes multiple optimized UTF-8 decoding implementations that automatically choose the best strategy based on:\n- Environment (Node.js vs Browser)\n- String length\n- Available APIs\n\n### UTF-8 Encoding\n\n```typescript\nimport {encode} from '@jsonjoy.com/buffers/lib/utf8/encode';\n\nconst bytesWritten = encode(targetArray, 'Hello 🌍', offset, maxLength);\n```\n\n### Advanced UTF-8 Features\n\n```typescript\nimport {CachedUtf8Decoder} from '@jsonjoy.com/buffers/lib/utf8/CachedUtf8Decoder';\nimport {isUtf8} from '@jsonjoy.com/buffers/lib/utf8/isUtf8';\nimport {decodeAscii} from '@jsonjoy.com/buffers/lib/utf8/decodeAscii';\n\nconst decoder = new CachedUtf8Decoder();\nconst text = decoder.decode(uint8Array, start, length);\n\nconst isValidUtf8 = isUtf8(uint8Array);\nconst asciiText = decodeAscii(uint8Array, start, length);\n```\n\n## Special Data Types\n\n### Slice\n\nA lightweight view into a buffer without copying data.\n\n```typescript\nimport {Slice} from '@jsonjoy.com/buffers/lib/Slice';\n\nconst slice = new Slice(uint8Array, dataView, start, end);\nconst subarray = slice.subarray(); // Get the actual data\n```\n\n### Float16 Support\n\n```typescript\nimport {decodeF16} from '@jsonjoy.com/buffers/lib/f16';\n\nconst float32Value = decodeF16(binaryF16Value);\n```\n\n## Debugging Utilities\n\n```typescript\nimport {printOctets} from '@jsonjoy.com/buffers/lib/printOctets';\n\nconsole.log(printOctets(uint8Array, 16)); // Print hex dump of first 16 bytes\n```\n\n## Performance\n\nThis library is designed for high performance with:\n\n- **Optimized UTF-8 handling**: Multiple implementations that choose the fastest method for each environment\n- **Minimal allocations**: Reusable readers and writers with buffer pooling\n- **Zero-copy operations**: Slices and views avoid unnecessary data copying\n- **Environment-specific optimizations**: Leverages Node.js Buffer APIs when available\n\n## Browser Support\n\nWorks in all modern browsers and Node.js environments. The library automatically detects available APIs and chooses the most appropriate implementation.\n\n## TypeScript Support\n\nFull TypeScript support with comprehensive type definitions included.\n\n## License\n\nApache-2.0\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonjoy-com%2Fbuffers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsonjoy-com%2Fbuffers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonjoy-com%2Fbuffers/lists"}