https://github.com/dylex/iteratees
Tools built on play's iteratees, including ZipFile and other Enumeratee filters
https://github.com/dylex/iteratees
Last synced: over 1 year ago
JSON representation
Tools built on play's iteratees, including ZipFile and other Enumeratee filters
- Host: GitHub
- URL: https://github.com/dylex/iteratees
- Owner: dylex
- License: other
- Created: 2014-08-02T05:38:48.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2018-01-12T15:00:36.000Z (over 8 years ago)
- Last Synced: 2025-01-23T19:14:35.126Z (over 1 year ago)
- Language: Scala
- Size: 9.77 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Iteratee utilities
## Installation
Add the dependency:
> "org.databrary" %% "iteratees" % "0.1"
You can see examples of usage in the test cases.
## ZipFile
These functions provide an interface to java.util.zip.ZipOutputStream in the form of an Enumeratee.
There are two main functions providing a higher-level and lower-level interface.
Both follow proper reactive semantics, never blocking (except possibly on IO).
However, errors may still be delivered by thrown exceptions.
Also provided are some classes that provide more convenient ways of creating ZipEntries: `DirEntry`, `StoredEntry` and `DeflatedEntry`.
### zip
The lower-level interface, `org.databrary.ZipFile.zip`, provides an `Enumeratee[Either[ZipEntry, Array[Byte]], Array[Byte]]` that converts an incoming sequence of `Left(ZipEntry)`, each followed by any number of `Right(data)` blocks, into a zip file.
This is equivalent to calling this sequence of `ZipOutputStream.setNextEntry` and `ZipOutputStream.write` on each item, so all the restrictions of those interfaces still apply.
### flatZip
The higher-level interface, `org.databrary.ZipFile.flatZip`, provides a more convenient interface for creating zip streams out of different files or data sources.
It provides an `Enumeratee[ZipFile.StreamEntry, Array[Byte]]`, where a `StreamEntry` is a `ZipEntry` amended with an `Enumerator[Array[Byte]]`.
Two easy ways of creating StreamEntries are provided: `ZipFile.DirEntry` (which simply has no data content), and `ZipFile.fileEntry` which generates a StreamEntry from a file on disk.
You can also use `ZipFile.DeflatedStreamEntry` or define your own.
## Enumeratee utilities
### Range
Similar to a composition Enumeratee.take and Enumeratee.drop, `org.databrary.Enumeratee.range` is designed to work on Array[Byte] streams and counts individual bytes, allowing you to select an interior range of a byte stream.
### FilterOutputStream
Used in the construction of zip files, `org.databrary.Enumeratee.filterOutputStream` allows you to wrap a `java.io.FilterOutputStream` in an Enumartee efficiently.
Unlike Enumerator.outputStream, this follows correct Enumeratee semantics, so will push back and only accept input when more is needed.