How lhns/fs2-compress works
Main Components
• Core Abstractions:
– A “core” module (found in the core/ directory) housing the central definitions and traits such as Compressor, Decompressor, ArchiveEntry, Archiver, and Unarchiver.
• Algorithm Plugins:
– Individual modules (directories such as gzip, brotli, bzip2, lz4, snappy, tar, zip, zip4j, zstd, and brotli4j) that implement the core typeclasses. Each of these folders contains their own source (src/main/scala/…) and test code.
• Integration with Fs2 and the Functional Ecosystem:
– The project is designed to work with the fs2 streaming library and Cats Effect (as seen in usage examples), so show dependencies on fs2, Cats Effect, and even external libraries such as zip4j when applicable.
Relationships and Interactions
• The Core module provides the contractual interfaces (e.g., Compressor.compress, Decompressor.decompress).
• Each algorithm module implements these interfaces – indicate “implements” or “adopts” relationships between the core abstractions and the concrete algorithm modules.
• How a typical pipeline would work: an input stream (from fs2's IO or Files API) flows into a Compressor’s pipe, then the processed (compressed) byte stream is passed downstream for storage or further handling.
• Similarly, for archiving: an entry flow is created by pairing ArchiveEntry objects with their corresponding file streams, then passing them through the Archiver pipe toward file writing.
Architectural Patterns and Design Principles
• Abstraction and Inversion of Control: The project uses typeclasses to abstract compression/archiving behavior so that the client’s code can be decoupled from concrete implementations.
• Modular and Extensible Design: Each algorithm is contained in its own module/directory, making it easy to add new implementations or swap out algorithms.
• Functional Composition: The library is designed to produce composable FS2 pipes that can be integrated seamlessly into larger streaming pipelines.
• Separation of Concerns: There’s a clear delineation between core common abstractions and specific algorithm functionalities.