{"name":"@jsonjoy.com/buffers","publishConfig":{"access":"public"},"version":"18.28.0","description":"Various helper utilities for working with buffers and binary data","author":{"name":"streamich","url":"https://github.com/streamich"},"homepage":"https://github.com/streamich/json-joy/packages/buffers","repository":{"type":"git","url":"git+https://github.com/streamich/json-joy.git"},"license":"Apache-2.0","funding":{"type":"github","url":"https://github.com/sponsors/streamich"},"keywords":["buffer","buffers","uint8array","binary","utf8","string","encoding","decoding","reader","writer","streaming"],"engines":{"node":">=10.0"},"main":"lib/index.js","types":"lib/index.d.ts","typings":"lib/index.d.ts","scripts":{"clean":"npx rimraf lib typedocs coverage gh-pages yarn-error.log","build":"tsc -b tsconfig.build.json","typedoc":"typedoc","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","typecheck":"tsc -b --noEmit"},"peerDependencies":{"tslib":"2"},"devDependencies":{"json-pack-napi":"^0.0.2"},"jest":{"preset":"ts-jest","testEnvironment":"node","moduleFileExtensions":["ts","js","tsx"],"transform":{"^.+\\.tsx?$":"ts-jest"},"transformIgnorePatterns":[".*/node_modules/.*"],"testRegex":".*/(__tests__|__jest__|demo)/.*(?<!\\.vi)\\.(test|spec)\\.tsx?$","rootDir":".","testPathIgnorePatterns":["node_modules","\\.vi\\.(test|spec)\\.tsx?$"]},"_id":"@jsonjoy.com/buffers@18.28.0","bugs":{"url":"https://github.com/streamich/json-joy/issues"},"_integrity":"sha512-lr9DbrCLHHeBhrYDtEbEL6rsvobp6E+WDRRbjjb1sDih4/d6bTT+E3PuXWetIXaV9yZZvKbosTbq4bgbqSuFXQ==","_resolved":"/Users/m1book/Developer/streamich/global-monorepo/public/json-joy/packages/buffers/package.tgz","_from":"file:package.tgz","_nodeVersion":"25.1.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-lr9DbrCLHHeBhrYDtEbEL6rsvobp6E+WDRRbjjb1sDih4/d6bTT+E3PuXWetIXaV9yZZvKbosTbq4bgbqSuFXQ==","shasum":"690ab445a32e9fe9868b846e8cb76ff912bfb029","tarball":"http://registry-npm.ywwl.com/@jsonjoy.com/buffers/download/@jsonjoy.com/buffers-18.28.0.tgz","fileCount":148,"unpackedSize":237241,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFJRS2VFmd6AMnYyOBsgl1k4LWaZKj18d2jV/TJntHvfAiEAp7i6qqNrjxfeFMvQ1AUIYdoXTBhMsaBBahI43ze+y2o="}],"size":60662,"noattachment":false,"key":"/@jsonjoy.com/buffers/-/@jsonjoy.com/buffers-18.28.0.tgz"},"_npmUser":{"name":"streamich","email":"vadimsdaleckis@gmail.com"},"directories":{},"maintainers":[{"name":"json-joy-team","email":"team@jsonjoy.com"},{"name":"streamich","email":"vadimsdaleckis@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/buffers_18.28.0_1780421906476_0.574217498722815"},"_hasShrinkwrap":false,"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":1780421906626,"_cnpm_publish_time":1780421906626,"dist-tags":{"latest":"18.30.0"}}