combined-stream - A stream that emits multiple other streams one after another.
A stream that emits multiple other streams one after another.
NB Currently combined-stream works with streams vesrion 1 only. There is ongoing effort to switch this library to streams version 2. Any help is welcome. :) Meanwhile you can explore other libraries that provide streams2 support with more or less compatability with combined-stream.
combined-stream2: A drop-in streams2-compatible replacement for the combined-stream module.
multistream: A stream that emits multiple other streams one after another.
$ sbt clean publish-local
Before running the tests the first time, you must ensure the npm packages are installed:
$ npm install
Then you can run the tests:
$ sbt test
Here is a simple example that shows how you can use combined-stream to combine two files into one:
import io.scalajs.nodejs.fs._
import io.scalajs.npm.combinedstream._
val combinedStream = CombinedStream.create()
combinedStream.append(Fs.createReadStream("file1.txt"))
combinedStream.append(Fs.createReadStream("file2.txt"))
combinedStream.pipe(Fs.createWriteStream("combined.txt"))
While the example above works great, it will pause all source streams until they are needed. If you don't want that to happen, you can set pauseStreams to false:
import io.scalajs.nodejs.fs._
import io.scalajs.npm.combinedstream._
val combinedStream = CombinedStream.create(CombineStreamOptions(pauseStreams = false))
combinedStream.append(Fs.createReadStream("file1.txt"))
combinedStream.append(Fs.createReadStream("file2.txt"))
combinedStream.pipe(Fs.createWriteStream("combined.txt"))
However, what if you don't have all the source streams yet, or you don't want to allocate the resources (file descriptors, memory, etc.) for them right away? Well, in that case you can simply provide a callback that supplies the stream by calling a next() function:
import io.scalajs.nodejs.fs._
import io.scalajs.npm.combinedstream._
val combinedStream = CombinedStream.create()
combinedStream.append(next => next(Fs.createReadStream("file1.txt")))
combinedStream.append(next => next(Fs.createReadStream("file2.txt")))
combinedStream.pipe(Fs.createWriteStream("combined.txt"))
To add the combined-stream
binding to your project, add the following to your build.sbt:
libraryDependencies += "io.scalajs.npm" %%% "combined-stream" % "0.5.0"
Optionally, you may add the Sonatype Repository resolver:
resolvers += Resolver.sonatypeRepo("releases")