https://github.com/zio/zio-streams-compress
Compression algorithms and archive formats for zio-streams
https://github.com/zio/zio-streams-compress
Last synced: 7 months ago
JSON representation
Compression algorithms and archive formats for zio-streams
- Host: GitHub
- URL: https://github.com/zio/zio-streams-compress
- Owner: zio
- License: apache-2.0
- Created: 2024-10-19T07:10:57.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-02-18T07:22:28.000Z (8 months ago)
- Last Synced: 2025-02-18T08:27:35.537Z (8 months ago)
- Language: Scala
- Homepage: https://zio.dev/zio-streams-compress
- Size: 179 KB
- Stars: 1
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[//]: # (This file was autogenerated using `zio-sbt-website` plugin via `sbt generateReadme` command.)
[//]: # (So please do not edit it manually. Instead, change "docs/index.md" file or sbt setting keys)
[//]: # (e.g. "readmeDocumentation" and "readmeSupport".)# ZIO Streams Compress docs
[ZIO Streams Compress](https://github.com/zio/zio-streams-compress) integrates several compression algorithms and
archive formats with [ZIO Streams](https://zio.dev).[](https://github.com/zio/zio/wiki/Project-Stages)  [](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-streams-compress-docs_2.13/) [](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-streams-compress-docs_2.13/) [](https://javadoc.io/doc/dev.zio/zio-streams-compress-docs_2.13) [](https://github.com/zio/zio-streams-compress) [](https://scala-steward.org)
## Installation
In order to use this library, we need to add one of the following line in our `build.sbt` file:
```sbt
libraryDependencies += "dev.zio" %% "zio-streams-compress-brotli" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-brotli4j" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-bzip2" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-gzip" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-lz4" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-tar" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-zip" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-zip4j" % "1.0.0"
libraryDependencies += "dev.zio" %% "zio-streams-compress-zstd" % "1.0.0"
```For Brotli you can choose between the 'brotli' and the 'brotli4j' version. The first is based on the official Java
library but only does decompression. The second is based on [Brotli4J](https://github.com/hyperxpro/Brotli4j) which does
compression and decompression.For ZIP files you can choose between the 'zip' and the 'zip4j' version. The first allows you to tweak the compression
level, while the second allows you work with password-protected ZIP files.Currently only jvm is supported. PRs for scala-js and scala-native are welcome.
### Example
```scala
// Example.sc
// Run with: scala-cli Example.sc
//> using dep dev.zio:zio-streams-compress-gzip:1.0.0
//> using dep dev.zio:zio-streams-compress-tar:1.0.0
//> using dep dev.zio:zio-streams-compress-zip4j:1.0.0import zio._
import zio.compress.{ArchiveEntry, GzipCompressor, GzipDecompressor, TarUnarchiver, Zip4JArchiver}
import zio.stream._import java.nio.charset.StandardCharsets.UTF_8
object ExampleApp extends ZIOAppDefault {
override def run: ZIO[Any, Any, Any] =
for {
// Compress a file with GZIP
_ <- ZStream
.fromFileName("file")
.via(GzipCompressor.compress)
.run(ZSink.fromFileName("file.gz"))// List all items in a gzip tar archive:
_ <- ZStream
.fromFileName("file.tgz")
.via(GzipDecompressor.decompress)
.via(TarUnarchiver.unarchive)
.mapZIO { case (archiveEntry, contentStream) =>
for {
content <- contentStream.runCollect
_ <- Console.printLine(s"${archiveEntry.name} ${content.length}")
} yield ()
}
.runDrain// Create an encrypted ZIP archive
_ <- ZStream(archiveEntry("file1.txt", "Hello world!".getBytes(UTF_8)))
.via(Zip4JArchiver(password = Some("it is a secret")).archive)
.run(ZSink.fromFileName("file.zip"))
} yield ()private def archiveEntry(
name: String,
content: Array[Byte],
): (ArchiveEntry[Some, Any], ZStream[Any, Throwable, Byte]) =
(ArchiveEntry(name, Some(content.length.toLong)), ZStream.fromIterable(content))}
```## Running the tests
```shell
SBT_OPTS="-Xmx4G -XX:+UseG1GC" sbt test
```## Documentation
Learn more on the [ZIO Streams Compress docs homepage](https://zio.dev/zio-streams-compress)!
## Contributing
For the general guidelines, see ZIO [contributor's guide](https://zio.dev/contributor-guidelines).
## Code of Conduct
See the [Code of Conduct](https://zio.dev/code-of-conduct)
## Support
Come chat with us on [![Badge-Discord]][Link-Discord].
[Badge-Discord]: https://img.shields.io/discord/629491597070827530?logo=discord "chat on discord"
[Link-Discord]: https://discord.gg/2ccFBr4 "Discord"## Credits
This library is heavily inspired by [fs2-compress](https://github.com/lhns/fs2-compress).
## License
[License](LICENSE)
Copyright 2024-2025 Erik van Oosten and the zio-streams-compress contributors.