Advanced options, allowing for full control of the initial dictionary/decoding state.
import { Lzw } from '@4bitlabs/codecs';const dictionary = [ Lzw.EOF_MARKER, 0x41, // A 0x42, // B 0x43, // C 0x44, // D];const bytes = Lzw.unpack(encodedBytes, { dictionary }); Copy
import { Lzw } from '@4bitlabs/codecs';const dictionary = [ Lzw.EOF_MARKER, 0x41, // A 0x42, // B 0x43, // C 0x44, // D];const bytes = Lzw.unpack(encodedBytes, { dictionary });
Longer codings can be encoded in the dictionary by using either an array of numbers of with a Uint8Array:
Uint8Array
import { Lzw, EOF_MARKER } from '@4bitlabs/codecs';const dictionary = [ Lzw.EOF_MARKER, Uint8Array.of(0x47, 0x41, 0x54, 0x41), // GATA Uint8Array.of(0x41, 0x54, 0x54, 0x41), // ATTA Uint8Array.of(0x43, 0x47, 0x41, 0x54), // CGAT Uint8Array.of(0x41, 0x43, 0x41, 0x47), // ACAG];const bytes = Lzw.unpack(encodedBytes, { dictionary }); Copy
import { Lzw, EOF_MARKER } from '@4bitlabs/codecs';const dictionary = [ Lzw.EOF_MARKER, Uint8Array.of(0x47, 0x41, 0x54, 0x41), // GATA Uint8Array.of(0x41, 0x54, 0x54, 0x41), // ATTA Uint8Array.of(0x43, 0x47, 0x41, 0x54), // CGAT Uint8Array.of(0x41, 0x43, 0x41, 0x47), // ACAG];const bytes = Lzw.unpack(encodedBytes, { dictionary });
Initialize the LZW dictionary.
Optional
Select the packing bit-ordering.
'lsb' Copy
'lsb'
Advanced options, allowing for full control of the initial dictionary/decoding state.
Example: Using a custom LZW dictionary for decoding.
Example: Decoding with extended codes in LZW dictionary.
Longer codings can be encoded in the dictionary by using either an array of numbers of with a
Uint8Array
: