{"name":"@jsonjoy.com/buffers","version":"18.22.0","keywords":["buffer","buffers","uint8array","binary","utf8","string","encoding","decoding","reader","writer","streaming"],"author":{"url":"https://github.com/streamich","name":"streamich"},"license":"Apache-2.0","_id":"@jsonjoy.com/buffers@18.22.0","maintainers":[{"name":"json-joy-team","email":"team@jsonjoy.com"},{"name":"streamich","email":"vadimsdaleckis@gmail.com"}],"homepage":"https://github.com/streamich/json-joy/packages/buffers","bugs":{"url":"https://github.com/streamich/json-joy/issues"},"dist":{"shasum":"2b02a384e786bbc603678765f5659c5fe00cb2eb","tarball":"http://registry-npm.ywwl.com/@jsonjoy.com/buffers/download/@jsonjoy.com/buffers-18.22.0.tgz","fileCount":148,"integrity":"sha512-EcU2xV7MLAEOutKVX3VkzabJSMQp3TJnNM7CESqvHFluxd79r7T4ySUiyDGxLTIzhXmeGKOzOUSnKTq5KELLig==","signatures":[{"sig":"MEYCIQCHgcQLgcQZ4CVwrGjqFCZV71xX60fj8a9BnGN45Rm9HgIhAL18dZQVZdE1BYjOUbxHWmuE3GdYBc0iNcUiFDnDZpAy","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@jsonjoy.com%2fbuffers@18.22.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":233173,"size":60704,"noattachment":false,"key":"/@jsonjoy.com/buffers/-/@jsonjoy.com/buffers-18.22.0.tgz"},"jest":{"preset":"ts-jest","rootDir":".","testRegex":".*/(__tests__|__jest__|demo)/.*(?<!\\.vi)\\.(test|spec)\\.tsx?$","transform":{"^.+\\.tsx?$":"ts-jest"},"testEnvironment":"node","moduleFileExtensions":["ts","js","tsx"],"testPathIgnorePatterns":["node_modules","\\.vi\\.(test|spec)\\.tsx?$"],"transformIgnorePatterns":[".*/node_modules/.*"]},"main":"lib/index.js","_from":"file:package.tgz","types":"lib/index.d.ts","engines":{"node":">=10.0"},"funding":{"url":"https://github.com/sponsors/streamich","type":"github"},"scripts":{"build":"tsc -b tsconfig.build.json","clean":"npx rimraf lib typedocs coverage gh-pages yarn-error.log","typedoc":"typedoc","typecheck":"tsc -b --noEmit","build:pages":"npx rimraf gh-pages && mkdir -p gh-pages && cp -r typedocs/* gh-pages && cp -r coverage gh-pages/coverage","deploy:pages":"gh-pages -d gh-pages","publish-coverage-and-typedocs":"yarn typedoc && yarn coverage && yarn build:pages && yarn deploy:pages"},"typings":"lib/index.d.ts","_npmUser":{"name":"streamich","email":"vadimsdaleckis@gmail.com"},"_resolved":"/home/runner/work/json-joy/json-joy/packages/buffers/package.tgz","_integrity":"sha512-EcU2xV7MLAEOutKVX3VkzabJSMQp3TJnNM7CESqvHFluxd79r7T4ySUiyDGxLTIzhXmeGKOzOUSnKTq5KELLig==","repository":{"url":"git+https://github.com/streamich/json-joy.git","type":"git"},"_npmVersion":"11.12.1","description":"Various helper utilities for working with buffers and binary data","directories":{},"_nodeVersion":"24.15.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"json-pack-napi":"^0.0.2"},"peerDependencies":{"tslib":"2"},"_npmOperationalInternal":{"tmp":"tmp/buffers_18.22.0_1778788767876_0.17749512280964885","host":"s3://npm-registry-packages-npm-production"},"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","publish_time":1778788768028,"_cnpm_publish_time":1778788768028,"dist-tags":{"latest":"18.30.0"}}