PackBits implementation in JavaScript.
npm install @fiahfy/packbits
import { encode } from '@fiahfy/packbits'
console.log(buf) // <Buffer aa bb bb cc cc cc dd dd dd dd>
const encoded = encode(buf)
console.log(encoded) // <Buffer 00 aa ff bb fe cc fd dd>
import { decode } from '@fiahfy/packbits'
console.log(buf) // <Buffer 00 aa ff bb fe cc fd dd>
const decoded = decode(buf)
console.log(decoded) // <Buffer aa bb bb cc cc cc dd dd dd dd>
In Apple Icon Image format, pixel data are often compressed (per channel) with a format similar to PackBits.
import { encode } from '@fiahfy/packbits'
console.log(buf) // <Buffer aa bb bb cc cc cc dd dd dd dd>
const encoded = encode(buf, { format: 'icns' })
console.log(encoded) // <Buffer 02 aa bb bb 80 cc 81 dd>
import { decode } from '@fiahfy/packbits'
console.log(buf) // <Buffer 02 aa bb bb 80 cc 81 dd>
const decoded = decode(buf, { format: 'icns' })
console.log(decoded) // <Buffer aa bb bb cc cc cc dd dd dd dd>