Skip to content

fix(bgcode): DEFLATE is zlib-wrapped, not raw — real-file confirmed (#188) - #236

Merged
sobechestnut-dev merged 1 commit into
devfrom
feat/188-bgcode-phase4-deflate-fix
Jul 27, 2026
Merged

fix(bgcode): DEFLATE is zlib-wrapped, not raw — real-file confirmed (#188)#236
sobechestnut-dev merged 1 commit into
devfrom
feat/188-bgcode-phase4-deflate-fix

Conversation

@sobechestnut-dev

Copy link
Copy Markdown

The first fruit of validating the decoder against a real Prusa XL ColorMix .bgcode (thanks for the file!). Part of #188 phase 4.

The bug the real file caught

Phase 1 assumed raw DEFLATE ('deflate-raw'). Prusa actually uses zlib-wrapped DEFLATE — the real file's Slicer/Print metadata blocks decode only with the zlib header (zlib.decompress(data)); raw fails with invalid stored block lengths. It was invisible until now because GCode blocks use heatshrink, not DEFLATE — so the DEFLATE path was never exercised on real data until a real file's metadata.

Fix: DecompressionStream('deflate') (+ the test assembler), and a flavor-lock test asserting a raw-DEFLATE block is now rejected, so this can't silently regress.

Real-file validation (local, conclusive)

Decoding the 21 MB / 856-block file end-to-end:

  • All 856 CRC32 checksums verified (no CRC error).
  • 848 GCode blocks (heatshrink-12 + MeatPack-comments) → 51.4 MB of valid Prusa G-code, ~3 s.
  • 1,892,006 G1 moves, comments + ;WIPE_START preserved, and the file uses MeatPack no-spaces mode (G1X177.233Y194.747E.02659) — so the phase-2 no-spaces handling and the phase-3 heatshrink are correct on real data.

So the phase-2/3 codec ports are validated against real Prusa output; this PR fixes the one thing that was wrong (the DEFLATE flavor).

Verification

typeCheck ✓, lint ✓ (0 errors), CI-like test:packages ✓ (31 bgcode tests), pack:check ✓ (no snapshot change).

🤖 Generated with Claude Code

…rmed (#188)

Phase-1 assumed raw DEFLATE ('deflate-raw'). Validating the decoder against a real Prusa XL ColorMix
.bgcode (21 MB, 856 blocks) showed its DEFLATE metadata blocks (Slicer/Print) decode ONLY as
zlib-wrapped — raw fails ("invalid stored block lengths"). It went unnoticed because GCode blocks use
heatshrink, not DEFLATE, so the DEFLATE path was never exercised until real metadata.

Switch the decoder + the test assembler to DecompressionStream('deflate') (zlib), and add a flavor-lock
test asserting a raw-DEFLATE block is rejected (E_BGCODE_INFLATE) so the flavor can't silently regress.

Real-file validation (local): all 856 CRC32 verified; 848 heatshrink-12 + MeatPack-comments GCode
blocks → 51.4 MB of valid Prusa G-code (1,892,006 G1 moves, comments + ;WIPE_START preserved,
MeatPack no-spaces mode exercised) in ~3 s — so the phase-2/3 decoders are correct on real data.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sobechestnut-dev
sobechestnut-dev enabled auto-merge (squash) July 27, 2026 21:17
@sobechestnut-dev
sobechestnut-dev merged commit 852db93 into dev Jul 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant