https://github.com/scalajs-io/combined-stream
A stream that emits multiple other streams one after another.
https://github.com/scalajs-io/combined-stream
node nodejs npm npm-module npm-package scalajs stream
Last synced: 9 months ago
JSON representation
A stream that emits multiple other streams one after another.
- Host: GitHub
- URL: https://github.com/scalajs-io/combined-stream
- Owner: scalajs-io
- License: apache-2.0
- Created: 2017-04-22T21:43:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:07:49.000Z (over 6 years ago)
- Last Synced: 2025-01-17T22:42:42.051Z (11 months ago)
- Topics: node, nodejs, npm, npm-module, npm-package, scalajs, stream
- Language: Scala
- Size: 10.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
combined-stream API for Scala.js
================================
[combined-stream](https://www.npmjs.com/package/combined-stream) - A stream that emits multiple other streams one after another.
### Description
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](https://github.com/scalajs-io/combined-stream2): A drop-in streams2-compatible replacement for the combined-stream module.
[multistream](https://github.com/scalajs-io/multistream): A stream that emits multiple other streams one after another.
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally
```bash
$ sbt clean publish-local
```
### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```
Then you can run the tests:
```bash
$ sbt test
```
### Examples
Here is a simple example that shows how you can use combined-stream to combine two files into one:
```scala
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:
```scala
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:
```scala
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"))
```
### Artifacts and Resolvers
To add the `combined-stream` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "combined-stream" % "0.5.0"
```
Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```