{"id":16926042,"url":"https://github.com/codedread/bitjs","last_synced_at":"2025-10-14T10:04:01.544Z","repository":{"id":43360559,"uuid":"56640946","full_name":"codedread/bitjs","owner":"codedread","description":"Binary Tools for JavaScript","archived":false,"fork":false,"pushed_at":"2025-02-23T19:11:21.000Z","size":881,"stargazers_count":84,"open_issues_count":12,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T20:40:56.098Z","etag":null,"topics":["binary","gif","javascript","jpeg","png","rar","tar","unrar","unzip","zip"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/codedread.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":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-20T00:02:21.000Z","updated_at":"2025-02-23T19:11:18.000Z","dependencies_parsed_at":"2024-02-03T22:22:39.764Z","dependency_job_id":"102d5fa8-0dd3-4d76-a339-7f1d57ce28fc","html_url":"https://github.com/codedread/bitjs","commit_stats":{"total_commits":180,"total_committers":8,"mean_commits":22.5,"dds":0.4722222222222222,"last_synced_commit":"fc0381b4d268bbc132ece1d9a4427ed37b302b18"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedread%2Fbitjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedread%2Fbitjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedread%2Fbitjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedread%2Fbitjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codedread","download_url":"https://codeload.github.com/codedread/bitjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584468,"owners_count":21771969,"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":["binary","gif","javascript","jpeg","png","rar","tar","unrar","unzip","zip"],"created_at":"2024-10-13T20:28:52.991Z","updated_at":"2025-10-14T10:03:56.524Z","avatar_url":"https://github.com/codedread.png","language":"JavaScript","readme":"[![Node.js CI](https://github.com/codedread/bitjs/actions/workflows/node.js.yml/badge.svg)](https://github.com/codedread/bitjs/actions/workflows/node.js.yml)\n\n# bitjs: Binary Tools for JavaScript\n\n## Introduction\n\nA set of dependency-free JavaScript modules to work with binary data in JS (using\n[Typed Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)).\nIncludes:\n\n  * bitjs/archive: Decompressing files (unzip, unrar, untar, gunzip) in JavaScript, implemented as\n    Web Workers where supported, and allowing progressive unarchiving while streaming.\n  * bitjs/codecs: Get the codec info of media containers in a ISO RFC6381 MIME type string.\n  * bitjs/file: Detect the type of file from its binary signature.\n  * bitjs/image: Parsing GIF, JPEG, PNG. Conversion of WebP to PNG or JPEG.\n  * bitjs/io: Low-level classes for interpreting binary data (BitStream, ByteStream). For example,\n    reading or peeking at N bits at a time.\n\n## Installation\n\nInstall it using your favourite package manager, the package is registered under `@codedread/bitjs`.\n```bash\nnpm install @codedread/bitjs\n```\nor\n```bash\nyarn add @codedread/bitjs\n```\n\n### CommonJS/ESM in Node\n\nThis module is an ES Module. If your project uses CommonJS modules, it's a little trickier to use.\nOne example of this is if a TypeScript project compiles to CommonJS, it will try to turn imports\ninto require() statements, which will break. The fix for this (unfortunately) is to update your\ntsconfig.json:\n\n```json\n \"moduleResolution\": \"Node16\",\n```\n\nand use a Dynamic Import:\n\n```javascript\nconst { getFullMIMEString } = await import('@codedread/bitjs');\n```\n\n## Packages\n\n### bitjs.archive\n\nThis package includes objects for decompressing and compressing binary data in popular archive\nformats (zip, rar, tar, gzip). Here is a simple example of unrar:\n\n#### Decompressing\n\n```javascript\nimport { Unrarrer } from './bitjs/archive/decompress.js';\nconst unrar = new Unrarrer(rarFileArrayBuffer);\nunrar.addEventListener('extract', (e) =\u003e {\n  const {filename, fileData} = e.unarchivedFile;\n  console.log(`Extracted ${filename} (${fileData.byteLength} bytes)`);\n  // Do something with fileData...\n});\nunrar.addEventListener('finish', () =\u003e console.log('Done'));\nunrar.start();\n```\n\nMore details and examples are located on [the API page](./docs/bitjs.archive.md).\n\n### bitjs.codecs\n\nThis package includes code for dealing with media files (audio/video). It is useful for deriving\nISO RFC6381 MIME type strings, including the codec information. Currently supports a limited subset\nof MP4 and WEBM.\n\nHow to use:\n  * First, install ffprobe (ffmpeg) on your system.\n  * Then:\n```javascript\n\nimport { getFullMIMEString } from 'bitjs/codecs/codecs.js';\n/**\n * @typedef {import('bitjs/codecs/codecs.js').ProbeInfo} ProbeInfo\n */\n\nconst cmd = 'ffprobe -show_format -show_streams -print_format json -v quiet foo.mp4';\nexec(cmd, (error, stdout) =\u003e {\n  /** @type {ProbeInfo} */\n  const info = JSON.parse(stdout);\n  // 'video/mp4; codecs=\"avc1.4D4028, mp4a.40.2\"'\n  const contentType = getFullMIMEString(info);\n  ...\n});\n```\n\n### bitjs.file\n\nThis package includes code for dealing with files.  It includes a sniffer which detects the type of\nfile, given an ArrayBuffer.\n\n```javascript\nimport { findMimeType } from './bitjs/file/sniffer.js';\nconst mimeType = findMimeType(someArrayBuffer);\n```\n\n### bitjs.image\n\nThis package includes code for dealing with image files.  It includes low-level, event-based\nparsers for GIF, JPEG, and PNG images.\n\nIt also includes a module for converting WebP images into\nalternative raster graphics formats (PNG/JPG), though this latter module is deprecated, now that\nWebP images are well-supported in all browsers.\n\n#### GIF Parser\n```javascript\nimport { GifParser } from './bitjs/image/parsers/gif.js'\n\nconst parser = new GifParser(someArrayBuffer);\nparser.onApplicationExtension(evt =\u003e {\n  const appId = evt.detail.applicationIdentifier;\n  const appAuthCode = new TextDecoder().decode(evt.detail.applicationAuthenticationCode);\n  if (appId === 'XMP Data' \u0026\u0026 appAuthCode === 'XMP') {\n    /** @type {Uint8Array} */\n    const appData = evt.detail.applicationData;\n    // Do something with appData (parse the XMP).\n  }\n});\nparser.start();\n```\n\n#### JPEG Parser\n```javascript\nimport { JpegParser } from './bitjs/image/parsers/jpeg.js'\nimport { ExifTagNumber } from './bitjs/image/parsers/exif.js';\n\nconst parser = new JpegParser(someArrayBuffer)\n    .onApp1Exif(evt =\u003e console.log(evt.detail.get(ExifTagNumber.IMAGE_DESCRIPTION).stringValue));\nawait parser.start();\n```\n\n#### PNG Parser\n```javascript\nimport { PngParser } from './bitjs/image/parsers/png.js'\nimport { ExifTagNumber } from './bitjs/image/parsers/exif.js';\n\nconst parser = new PngParser(someArrayBuffer);\n    .onExifProfile(evt =\u003e console.log(evt.detail.get(ExifTagNumber.IMAGE_DESCRIPTION).stringValue))\n    .onTextualData(evt =\u003e console.dir(evt.detail));\nawait parser.start();\n```\n\n#### WebP Converter\n```javascript\nimport { convertWebPtoPNG, convertWebPtoJPG } from './bitjs/image/webp-shim/webp-shim.js';\n// convertWebPtoPNG() takes in an ArrayBuffer containing the bytes of a WebP\n// image and returns a Promise that resolves with an ArrayBuffer containing the\n// bytes of an equivalent PNG image.\nconvertWebPtoPNG(webpBuffer).then(pngBuf =\u003e {\n  const pngUrl = URL.createObjectURL(new Blob([pngBuf], {type: 'image/png'}));\n  someImgElement.setAttribute(src, pngUrl);\n});\n```\n\n### bitjs.io\n\nThis package includes stream objects for reading and writing binary data at the bit and byte level:\nBitStream, ByteStream.\n\n```javascript\nimport { BitStream } from './bitjs/io/bitstream.js';\nconst bstream = new BitStream(someArrayBuffer, true /** most-significant-bit-to-least */ );\nconst crc = bstream.readBits(12); // Read in 12 bits as CRC. Advance pointer.\nconst flagbits = bstream.peekBits(6); // Look ahead at next 6 bits. Do not advance pointer.\n```\n\nMore details and examples are located on [the API page](./docs/bitjs.io.md).\n\n## Reference\n\n* [UnRar](http://codedread.github.io/bitjs/docs/unrar.html): A work-in-progress description of the\nRAR file format.\n\n## History\n\nThis project grew out of another project of mine, [kthoom](https://github.com/codedread/kthoom) (a\ncomic book reader implemented in the browser). This repository was automatically exported from\n[my original repository on GoogleCode](https://code.google.com/p/bitjs) and has undergone\nconsiderable changes and improvements since then.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodedread%2Fbitjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodedread%2Fbitjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodedread%2Fbitjs/lists"}