Replace pako with fflate for smaller bundle size and faster compression#2
Merged
Conversation
…compression fflate's zlibSync produces the same zlib-wrapped (RFC 1950) output that TIFF compression code 8 requires, but ships ~9x smaller (5 kB vs 45 kB minified) and includes built-in TypeScript types — removing the need for the separate @types/pako dev dependency.
…son`, which I left out since this project uses bun and didn't previously track a lockfile.
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.
Summary
Replace the
pakodependency withfflatefor zlib-wrapped deflate compression used in TIFF tile encoding. This yields a significantly smaller bundle footprint and improved compression performance with no change in output format or compatibility.Changes
package.json— Swappedpako(^2.1.0) forfflate(^0.8.2) in dependencies; removed@types/pakofrom devDependencies (fflate ships built-in TypeScript types)src/tiff-writer.ts— Replacedimport { deflate } from "pako"withimport { zlibSync } from "fflate"and updated the synchronous fallback call site (deflate(data, { level })→zlibSync(data, { level }))src/write.ts— Updated JSDoc comment referencing the fallback pathtest/tiff-writer.test.ts— Replacedimport("pako").inflatewithimport("fflate").unzlibSyncin round-trip decompression testsWhy
@types/pakoBoth libraries produce standards-compliant zlib-wrapped deflate (RFC 1950), which is what TIFF compression code 8 requires. Data compressed by fflate is fully decompressible by pako, zlib, and geotiff.js — and vice versa.
Implementation Details
compressDeflate()atsrc/tiff-writer.ts:325. The primary async path uses the nativeCompressionStreamAPI and is unchanged.deflate()produces zlib-wrapped output by default → maps directly to fflate'szlibSync().{ level }, which fflate supports with the same semantics.