{"id":15594064,"url":"https://github.com/freeeve/bufr","last_synced_at":"2026-01-08T07:14:13.693Z","repository":{"id":44844094,"uuid":"165521885","full_name":"freeeve/bufr","owner":"freeeve","description":"a compressed/cached Buffer() wrapper for javascript","archived":false,"fork":false,"pushed_at":"2023-01-04T21:36:55.000Z","size":1753,"stargazers_count":1,"open_issues_count":17,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T07:22:40.891Z","etag":null,"topics":["buffer","cache","compress","compressed","javascript","typescript"],"latest_commit_sha":null,"homepage":"","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/freeeve.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":null}},"created_at":"2019-01-13T15:31:49.000Z","updated_at":"2025-02-23T15:58:22.000Z","dependencies_parsed_at":"2023-02-02T20:46:13.647Z","dependency_job_id":null,"html_url":"https://github.com/freeeve/bufr","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeeve%2Fbufr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeeve%2Fbufr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeeve%2Fbufr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freeeve%2Fbufr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freeeve","download_url":"https://codeload.github.com/freeeve/bufr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246174498,"owners_count":20735412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["buffer","cache","compress","compressed","javascript","typescript"],"created_at":"2024-10-03T00:22:54.879Z","updated_at":"2026-01-08T07:14:13.649Z","avatar_url":"https://github.com/freeeve.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bufr\n[![Travis](https://api.travis-ci.com/freeeve/bufr.svg?branch=master)](https://travis-ci.com/freeeve/bufr)\n[![Coveralls](https://img.shields.io/coveralls/freeeve/bufr.svg)](https://coveralls.io/github/freeeve/bufr)\n\nBufr is a wrapper for Buffer, adding features like\nauto-extend, compression, and a concept of an LRU cache--the\namount of memory designated to stay uncompressed for use.\n\nIt is not meant to improve performance, but it is meant to save memory, \nfor use when you can sacrifice a little performance for memory.\n\nIn testing, I found there is a balance between block size and \nhow random your access is. Smaller block size decompresses faster,\nso it ends up being faster for small random reads. Larger block size\nhas less overhead, so if you're just appending and reading large chunks,\nit is a fair bit faster.\n\n## Usage\n\n```typescript\nconst bufr = new Bufr();\nconst data = Buffer.from('hello');\nbufr.writeBuffer(data, 0);\nconsole.log(bufr.subBuffer(0, 0 + data.length).toString()); // hello\nconsole.log(bufr.length); // 5\n// append a 32-bit int\nbufr.writeUInt32LE(123123, bufr.length);\nconsole.log(bufr.length); // 9\n```\n\n### Specifying allocation size and cache size\nCache size should be a multiple of allocation size, because it will\nend up being one, anyway (rounded down). \n\nCache size can be 0, but only in extreme cases. \nEvery read/write will decompress/compress the block.\n\n```typescript\n// default is 4 and 64 for allocSizeKb and cacheSizeKb, respectively\n// this bufr will have at most 4MB uncompressed blocks at once,\n// feel free to write as much as you want...\nconst bufr = new Bufr({allocSizeKb:128, cacheSizeKb:1024 * 4});\nfor(let i = 0; i \u003c 1000000; i++) {\n  bufr.writeBuffer(Buffer.from('hello'.repeat(20)), bufr.length);\n}\nconsole.log(bufr.uncompressedSize); // 4194304\n```\n\n### Auto-extending\n```typescript\n// default is 4 and 64 for allocSizeKb and cacheSizeKb, respectively\n// this bufr will have at most 4MB uncompressed blocks at once,\n// feel free to write as much as you want...\n// or start in the middle!\nconst bufr = new Bufr();\nbufr.writeUInt32LE(123, 100000);\nconsole.log(bufr.length); // 100004\nconsole.log(bufr.uncompressedSize); // 65536 (64KB default cache size)\nconsole.log(bufr.memoryUsage().compressed); // 633 (those 0 bytes compress well!)\n```\n\n## TODO \n* Read/write to file\n* Offer an API for inserting data (extending in the middle of a buffer without overwriting)\n* Improve LRU caching performance\n* Decrease memory used by metadata (block management)\n* Offer more compression algorithms, namely I think snappy would be a good addition (currently using pako `inflateRaw`/`deflateRaw`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeeve%2Fbufr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreeeve%2Fbufr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeeve%2Fbufr/lists"}