feat(bgcode): heatshrink decompression (DD-011 phase 3) (#188) - #235
Merged
Conversation
Adds heatshrink (LZSS) decompression — windows 11 & 12, lookahead 4 — to the .bgcode decoder. With this, ALL four spec compression codecs (None/DEFLATE/heatshrink-11/heatshrink-12) and all encodings (None/MeatPack/MeatPack-comments) are decoded; a heatshrink-compressed GCode block now decodes end-to-end to plain G-code. The decoder is a TS port of the LZSS decoder from the ISC atomicobject/heatshrink (© 2013-2015 Scott Vokes), attribution preserved — no AGPL libbgcode (RR-003 §8). Wire format: MSB-first bit stream; tag bit (1=literal 8 bits; 0=backref of windowBits index + lookaheadBits count, each value-1); a backref copies count+1 bytes from index+1 back in a circular window, re-emitting each (self-referential runs supported). Validated against vectors built by an INDEPENDENT MSB-first bit-packer from the spec (literals, single + multi-byte backrefs, offset-2 interleaving, self-referential runs, window 11 & 12, a realistic repeated g-code fragment) + block-level integration through openBgcode. Output bounded (bomb defense). The stale phase-1 "heatshrink unsupported" test → an unknown-compression-id rejection. Real PrusaSlicer heatshrink files = phase-4 golden-equivalence. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sobechestnut-dev
enabled auto-merge (squash)
July 27, 2026 20:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 3 of the #188 bgcode epic (DD-011 §14). Does not close #188 — container-adapter integration + real-file golden-equivalence (phase 4) and the §7.3 review (phase 5) remain.
What
heatshrink (LZSS) decompression — windows 11 & 12, lookahead 4. With this, all four spec compression codecs (None / DEFLATE / heatshrink-11 / heatshrink-12) and all encodings (None / MeatPack / MeatPack-comments) are decoded. A heatshrink-compressed
.bgcodeGCode block now decodes end-to-end to plain G-code.Licensing — clean, attributed
A TypeScript port of the LZSS decoder from the ISC
atomicobject/heatshrink(© 2013–2015 Scott Vokes) — attribution in the source header. ISC is permissive/MIT-compatible; no AGPLlibbgcode(RR-003 §8).Validation — independent oracle
Vectors are built by an independent MSB-first bit-packer from the wire format (a separate code path from the decoder's reader), so
decode(pack(tokens)) === expectedchecks the decoder against the spec, not itself: literals, single- and multi-byte back-references, offset-2 interleaving (ABABAB), self-referential runs (copy length > offset), window 11 & 12, a realistic repeated G-code fragment, the bomb cap, and block-level integration throughopenBgcode. Real PrusaSlicer heatshrink files land in phase 4 for golden-equivalence.Verification
typeCheck✓,lint✓ (0 errors),docs:build✓ (3/3), CI-liketest:packages✓ (30 bgcode tests across 3 files),pack:check✓ (additiveheatshrink.*snapshot).🤖 Generated with Claude Code