Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabianmurariu/reactivefs
Asynchrnonous IO on disk
https://github.com/fabianmurariu/reactivefs
Last synced: about 17 hours ago
JSON representation
Asynchrnonous IO on disk
- Host: GitHub
- URL: https://github.com/fabianmurariu/reactivefs
- Owner: fabianmurariu
- Created: 2014-11-03T07:58:55.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-29T19:16:50.000Z (about 10 years ago)
- Last Synced: 2023-03-30T03:11:22.465Z (almost 2 years ago)
- Language: Scala
- Size: 188 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**Proper Functional IO with Play Iteratees**
The current IO implementation in Play Iteratees is not functional enough, it is using mutable state over OutputStream
or InputStream see [EnumeratorsSpec](https://github.com/playframework/playframework/blob/master/framework/src/iteratees/src/test/scala/play/api/libs/iteratee/EnumeratorsSpec.scala)The suggested approach in this repo uses [AsynchronousFileChannel](https://docs.oracle.com/javase/8/docs/api/java/nio/channels/AsynchronousFileChannel.html)
to handle asynchronous read/writes over a file and wraps them functional structures Reader/Writer that always return
a new object on every apply, they also wrap scala.concurrent.Future making them very easy to integrate with Play Iteratees
Reader is an enumerator over a file
```scala
...
val enumerator: Enumerator[Array[Byte]] = Readers.toEnumerator("file", 5)
val eventualArray = enumerator |>>> Iteratee.fold(Array[Byte]())((chunk, result) => chunk ++ result)
result(eventualArray, 5 seconds) //file content should be here
...
```Writer is an Iteratee over that writes to a file the byte arrays pushed by an Enumerator
```scala
...
val iterateeWriter = Writers.toIteratee("file")
val eventualWriter = input |>>> iterateeWriter
result(eventualWriter, 5 seconds) // the number of bytes written
```For more detail see ReaderSpec and WriterSpec