{"id":50002799,"url":"https://github.com/panates/flexy-buffer","last_synced_at":"2026-05-19T13:39:14.283Z","repository":{"id":321602559,"uuid":"1084824153","full_name":"panates/flexy-buffer","owner":"panates","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-30T13:25:24.000Z","size":85,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-28T12:32:19.150Z","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/panates.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/package.cjs.json","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-10-28T08:00:52.000Z","updated_at":"2025-10-30T13:25:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"053bacea-545b-4208-82e6-e4b54b3c325a","html_url":"https://github.com/panates/flexy-buffer","commit_stats":null,"previous_names":["panates/flexy-buffer"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/panates/flexy-buffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fflexy-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fflexy-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fflexy-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fflexy-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panates","download_url":"https://codeload.github.com/panates/flexy-buffer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fflexy-buffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33219014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-19T07:54:09.561Z","status":"ssl_error","status_checked_at":"2026-05-19T07:54:08.508Z","response_time":58,"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":"2026-05-19T13:39:11.780Z","updated_at":"2026-05-19T13:39:14.269Z","avatar_url":"https://github.com/panates.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flexy-buffer\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![CI Tests][ci-test-image]][ci-test-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nFast runtime type validator, converter and io (encoding/decoding) library.\n\n## Installation\n\n`$ npm install flexy-buffer --save`\n\n\n# BufferReader API Documentation\n\n## API\n\n### BufferReader\n\nA sequential buffer reader class that provides methods for reading various data types from a Node.js Buffer. Maintains an internal position cursor that automatically advances as data is read.\n\n#### Constructor\n\nconstructor(buffer: Buffer)\n\nCreates a new BufferReader instance.\n\nParameters:\n- buffer: Buffer - The Node.js Buffer to read from\n\n#### Properties\n\n- buffer: Buffer - The underlying Node.js Buffer being read from\n- size: number (readonly) - The total size of the buffer in bytes\n- position: number (readonly) - Current read position in the buffer\n\n#### Methods\n\n##### Integer Reading Methods\n\nreadInt8(): number\nReads a signed 8-bit integer (1 byte).\nAdvances position by 1 byte.\n\nreadUInt8(): number\nReads an unsigned 8-bit integer (1 byte).\nAdvances position by 1 byte.\n\nreadInt16BE(): number\nReads a signed, big-endian 16-bit integer (2 bytes).\nAdvances position by 2 bytes.\n\nreadUInt16BE(): number\nReads an unsigned, big-endian 16-bit integer (2 bytes).\nAdvances position by 2 bytes.\n\nreadInt16LE(): number\nReads a signed, little-endian 16-bit integer (2 bytes).\nAdvances position by 2 bytes.\n\nreadUInt16LE(): number\nReads an unsigned, little-endian 16-bit integer (2 bytes).\nAdvances position by 2 bytes.\n\nreadInt32BE(): number\nReads a signed, big-endian 32-bit integer (4 bytes).\nAdvances position by 4 bytes.\n\nreadUInt32BE(): number\nReads an unsigned, big-endian 32-bit integer (4 bytes).\nAdvances position by 4 bytes.\n\nreadInt32LE(): number\nReads a signed, little-endian 32-bit integer (4 bytes).\nAdvances position by 4 bytes.\n\nreadUInt32LE(): number\nReads an unsigned, little-endian 32-bit integer (4 bytes).\nAdvances position by 4 bytes.\n\n##### BigInt Reading Methods\n\nreadBigInt64BE(): BigInt\nReads a signed, big-endian 64-bit integer (8 bytes).\nAdvances position by 8 bytes.\n\nreadBigUInt64BE(): BigInt\nReads an unsigned, big-endian 64-bit integer (8 bytes).\nAdvances position by 8 bytes.\n\nreadBigInt64LE(): BigInt\nReads a signed, little-endian 64-bit integer (8 bytes).\nAdvances position by 8 bytes.\n\nreadBigUInt64LE(): BigInt\nReads an unsigned, little-endian 64-bit integer (8 bytes).\nAdvances position by 8 bytes.\n\n##### Float Reading Methods\n\nreadFloatBE(): number\nReads a 32-bit, big-endian float (4 bytes).\nAdvances position by 4 bytes.\n\nreadFloatLE(): number\nReads a 32-bit, little-endian float (4 bytes).\nAdvances position by 4 bytes.\n\nreadDoubleBE(): number\nReads a 64-bit, big-endian double (8 bytes).\nAdvances position by 8 bytes.\n\nreadDoubleLE(): number\nReads a 64-bit, little-endian double (8 bytes).\nAdvances position by 8 bytes.\n\n##### Buffer and String Reading Methods\n\nreadBytes(len?: number): Buffer\nReads bytes from the current position.\n- If len is specified, reads exactly len bytes\n- If len is not specified, reads from current position to end of buffer\n- Advances position by the number of bytes read\n- Returns a new Buffer containing the read bytes\n\nreadString(len: number, encoding?: BufferEncoding): string\nReads a string of specified length from the current position.\n- len: number of bytes to read\n- encoding: optional buffer encoding (default: 'utf8')\n- Advances position by len bytes\n- Returns empty string if len \u003c 0\n\n##### Position Control Methods\n\nmoveBy(n: number): this\nMoves the current position by n bytes (can be positive or negative).\n- Automatically clamps position to valid range [0, size]\n- Returns this for method chaining\n\nmoveTo(pos: number): this\nMoves the current position to the specified absolute position.\n- Automatically clamps position to valid range [0, size]\n- Returns this for method chaining\n\n#### Usage Examples\n\nimport { BufferReader } from 'flexy-buffer';\n\n// Create a buffer with some data\nconst buffer = Buffer.from([\n0x12, 0x34, 0x56, 0x78,           // 4-byte integer\n0x48, 0x65, 0x6c, 0x6c, 0x6f,    // \"Hello\" string\n0x40, 0x49, 0x0f, 0xdb           // 4-byte float\n]);\n\n// Create reader\nconst reader = new BufferReader(buffer);\n\n// Read different data types\nconst intValue = reader.readUInt32BE();        // 0x12345678\nconst text = reader.readString(5, 'utf8');     // \"Hello\"\nconst floatValue = reader.readFloatBE();       // some float value\n\n// Check position\nconsole.log(reader.position);  // 13 (4 + 5 + 4 bytes)\nconsole.log(reader.size);      // 13 (total buffer size)\n\n// Move position manually\nreader.moveTo(0);              // Go back to start\nreader.moveBy(4);              // Skip first 4 bytes\n\n// Read remaining bytes\nconst remaining = reader.readBytes();  // Gets all remaining bytes\n\n#### Position Management\n\n// Reset to beginning\nreader.moveTo(0);\n\n// Skip bytes\nreader.moveBy(10);\n\n// Go to specific position\nreader.moveTo(5);\n\n// Read from current position to end\nconst restOfBuffer = reader.readBytes();\n\n#### Error Handling\n\nThe BufferReader throws an error when attempting to read beyond buffer boundaries:\n\ntry {\nreader.readUInt32BE(); // If not enough bytes available\n} catch (err) {\nif (err.code === 'ERR_BUFFER_OUT_OF_BOUNDS') {\nconsole.log('Attempted to read beyond buffer end');\n}\n}\n\n#### Data Type Reference\n\n8-bit integers (1 byte):\n- readInt8(): -128 to 127\n- readUInt8(): 0 to 255\n\n16-bit integers (2 bytes):\n- readInt16BE/LE(): -32,768 to 32,767\n- readUInt16BE/LE(): 0 to 65,535\n\n32-bit integers (4 bytes):\n- readInt32BE/LE(): -2,147,483,648 to 2,147,483,647\n- readUInt32BE/LE(): 0 to 4,294,967,295\n\n64-bit integers (8 bytes):\n- readBigInt64BE/LE(): BigInt values\n- readBigUInt64BE/LE(): BigInt values (unsigned)\n\nFloating point:\n- readFloatBE/LE(): 32-bit IEEE 754 float\n- readDoubleBE/LE(): 64-bit IEEE 754 double\n\nEndianness:\n- BE: Big-endian (most significant byte first)\n- LE: Little-endian (least significant byte first)\n\n#### Notes\n\n- All read operations automatically advance the internal position\n- Position is automatically clamped to valid range [0, size]\n- Reading beyond buffer end throws ERR_BUFFER_OUT_OF_BOUNDS error\n- The class provides a foundation for building more complex buffer reading functionality\n- Can be extended (as done by FlexyBuffer) to add writing capabilities\n\n\n# FlexyBuffer API Documentation\n\n## API\n\n### FlexyBuffer\n\nA flexible, auto-growing buffer implementation that extends BufferReader with writing capabilities. The buffer automatically manages memory allocation using a page-based system and includes housekeeping functionality for memory optimization.\n\n#### Constructor\n\nconstructor(cfg?: FlexBufferConfig)\n\nCreates a new FlexyBuffer instance.\n\nParameters:\n- cfg (optional): Configuration object\n    - minPages?: number - Minimum number of pages to allocate (default: 1)\n    - pageSize?: number - Size of each page in bytes (default: 4096)\n    - maxLength?: number - Maximum buffer size in bytes (default: 10MB)\n    - houseKeepMs?: number - Housekeeping timer interval in milliseconds (default: 5000)\n\n#### Properties\n\n##### Static Properties\n\n- DEFAULT_PAGE_SIZE: number - Default page size (4096 bytes)\n- DEFAULT_HOUSE_KEEP_MS: number - Default housekeeping interval (5000ms)\n- DEFAULT_MAX_SIZE: number - Default maximum size (10MB)\n\n##### Instance Properties\n\n- capacity: number (readonly) - Current buffer capacity in bytes\n- size: number (readonly) - Current data size in bytes\n- eof: boolean (readonly) - Whether the current position is at end of data\n- position: number (inherited) - Current read/write position\n- houseKeepMs: number - Housekeeping timer interval (get/set)\n- minPages: number (readonly) - Minimum number of pages\n- pageSize: number (readonly) - Page size in bytes\n- maxSize: number (readonly) - Maximum buffer size\n\n#### Methods\n\n##### Buffer Management\n\nsetSize(len: number): this\nSets the buffer size, automatically growing capacity if needed.\n- Throws error with code 'EBUFFLIMIT' if exceeds maxSize\n\ngrowSize(len: number): this\nGrows the buffer size by the specified amount.\n\ntoBuffer(): Buffer\nReturns a new Buffer containing only the valid data (0 to size).\n\nreset(shrinkCapacity?: boolean): void\nResets the buffer to empty state.\n- shrinkCapacity - If true, also shrinks capacity to minimum\n\n##### Data Writing Methods\n\nInteger Writing:\n- writeInt8(n: number): this\n- writeUInt8(n: number): number\n- writeInt16BE(n: number): number\n- writeUInt16BE(n: number): number\n- writeInt16LE(n: number): number\n- writeUInt16LE(n: number): number\n- writeInt32BE(n: number): number\n- writeUInt32BE(n: number): number\n- writeInt32LE(n: number): number\n- writeUInt32LE(n: number): number\n\nBigInt Writing:\n- writeBigInt64BE(n: bigint | number): number\n- writeBigUInt64BE(n: bigint | number): number\n- writeBigInt64LE(n: bigint | number): number\n- writeBigUInt64LE(n: bigint | number): number\n\nFloat Writing:\n- writeFloatBE(n: number): number\n- writeFloatLE(n: number): number\n- writeDoubleBE(n: number): number\n- writeDoubleLE(n: number): number\n\nBuffer and String Writing:\n- writeBytes(buffer: Buffer | number[]): number - Writes buffer or array of bytes\n- writeString(str: string, encoding?: BufferEncoding): number - Writes string with optional encoding\n\n##### Data Manipulation\n\nfill(value = 0, len = 1): this\nFills the buffer with the specified value for the given length at current position.\n\ninsertBytes(buffer: Buffer | number[]): number\nInserts bytes at the current position, shifting existing data forward.\nReturns the actual number of bytes inserted.\n\ndelete(deleteCount: number): number\nDeletes bytes from the current position, shifting remaining data backward.\nReturns the actual number of bytes deleted.\n\n##### Reading Methods (Inherited from BufferReader)\n\nThe FlexyBuffer inherits all reading methods from BufferReader:\n\n- readInt8(): number\n- readUInt8(): number\n- readInt16BE(): number, readInt16LE(): number\n- readUInt16BE(): number, readUInt16LE(): number\n- readInt32BE(): number, readInt32LE(): number\n- readUInt32BE(): number, readUInt32LE(): number\n- readBigInt64BE(): bigint, readBigInt64LE(): bigint\n- readBigUInt64BE(): bigint, readBigUInt64LE(): bigint\n- readFloatBE(): number, readFloatLE(): number\n- readDoubleBE(): number, readDoubleLE(): number\n- readBytes(len: number): Buffer\n- readString(len: number, encoding?: BufferEncoding): string\n\n#### Usage Examples\n\nimport { FlexyBuffer } from 'flexy-buffer';\n\n// Create a buffer with custom configuration\nconst buffer = new FlexyBuffer({\npageSize: 8192,\nminPages: 2,\nmaxLength: 1024 * 1024, // 1MB max\nhouseKeepMs: 10000\n});\n\n// Write different types of data\nbuffer.writeUInt32LE(42);\nbuffer.writeString('Hello, World!', 'utf8');\nbuffer.writeBytes(Buffer.from([1, 2, 3, 4]));\n\n// Read data by repositioning\nbuffer.position = 0;\nconst number = buffer.readUInt32LE();\nconst text = buffer.readString(13, 'utf8');\n\n// Insert data in the middle\nbuffer.position = 4;\nbuffer.insertBytes(Buffer.from([255, 254]));\n\n// Convert to regular Buffer\nconst result = buffer.toBuffer();\n\n// Reset for reuse\nbuffer.reset(true); // Also shrink capacity\n\n#### Error Handling\n\nThe buffer throws an error with code 'EBUFFLIMIT' when attempting to grow beyond the configured maximum size:\n\ntry {\nbuffer.growSize(tooMuchSize);\n} catch (err) {\nif (err.code === 'EBUFFLIMIT') {\nconsole.log('Buffer size limit exceeded');\n}\n}\n\n#### Memory Management\n\nThe FlexyBuffer uses automatic memory management:\n- Grows in page-sized chunks for efficiency\n- Automatically schedules housekeeping to reclaim unused memory\n- Housekeeping can be configured or triggered manually via reset(true)\n- Uses Buffer.allocUnsafe() for performance (initialize data before reading)\n\n\n## Node Compatibility\n\n- node `\u003e= 16.0`;\n\n### License\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/flexy-buffer.svg\n[npm-url]: https://npmjs.org/package/flexy-buffer\n[ci-test-image]: https://github.com/panates/flexy-buffer/actions/workflows/test.yml/badge.svg\n[ci-test-url]: https://github.com/panates/flexy-buffer/actions/workflows/test.yml\n[coveralls-image]: https://img.shields.io/coveralls/panates/flexy-buffer/master.svg\n[coveralls-url]: https://coveralls.io/r/panates/flexy-buffer\n[downloads-image]: https://img.shields.io/npm/dm/flexy-buffer.svg\n[downloads-url]: https://npmjs.org/package/flexy-buffer\n[gitter-image]: https://badges.gitter.im/panates/flexy-buffer.svg\n[gitter-url]: https://gitter.im/panates/flexy-buffer?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n[dependencies-image]: https://david-dm.org/panates/flexy-buffer/status.svg\n[dependencies-url]:https://david-dm.org/panates/flexy-buffer\n[devdependencies-image]: https://david-dm.org/panates/flexy-buffer/dev-status.svg\n[devdependencies-url]:https://david-dm.org/panates/flexy-buffer?type=dev\n[quality-image]: http://npm.packagequality.com/shield/flexy-buffer.png\n[quality-url]: http://packagequality.com/#?package=flexy-buffer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanates%2Fflexy-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanates%2Fflexy-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanates%2Fflexy-buffer/lists"}