Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tree-stream

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-stream - npm Package Compare versions

Comparing version 1.0.14 to 1.0.15

2

package.json
{
"name": "tree-stream",
"version": "1.0.14",
"version": "1.0.15",
"repository": "git://github.com/wholenews/tree-stream",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -9,13 +9,55 @@ # tree-stream

This package is forked from `pump` and aims to be a superset of `pump`. When the pipe() topology is a linked list they're functionally equivalent.
This package is forked from [mafintosh](https://www.npmjs.com/~mafintosh)'s [pump](https://www.npmjs.com/package/pump) and aims to be a superset of `pump`. When the provided pipe() topology is a linked-list, they're functionally equivalent.
[![build status](http://img.shields.io/travis/wholenews/tree-stream.svg?style=flat)](http://travis-ci.org/wholenews/tree-stream)
## What problem does it solve?
When using standard `source.pipe(dest)` source will _not_ be destroyed if dest emits close or an error.
- The original problems pump solved: When using standard `source.pipe(dest)` source will _not_ be destroyed if dest emits close or an error.
You are also not able to provide a callback to tell when then pipe has finished.
tree-stream does these two things for you
- The object model (of `ReadableStreamTree` and `WritableStreamTree`) is expressive.
A representation for a sequence (or DAG) of stream transforms turns out to be really useful.
Sometimes you want to "pipeFrom" (a `WritableStreamTree`) e.g. (from [@wholebuzz/fs/src/local.ts](https://github.com/wholebuzz/fs/blob/master/src/local.ts)):
```typescript
import StreamTree, { ReadableStreamTree, WritableStreamTree } from 'tree-stream'
async function openWritableFile(url: string, _options?: OpenWritableFileOptions) {
let stream = StreamTree.writable(fs.createWriteStream(url))
if (url.endsWith('.gz')) stream = stream.pipeFrom(zlib.createGzip())
return stream
}
```
And sometimes you want the typical "pipe" case (for a `ReadableStreamTree`):
```typescript
async function openReadableFile(url: string, options?: OpenReadableFileOptions) {
let stream = StreamTree.readable(fs.createReadStream(url))
if (url.endsWith('.gz')) stream = stream.pipe(zlib.createGunzip())
return stream
}
```
You can equivalently apply a transform then, with either:
```typescript
const tf = new Transform({ objectMode: true, transform(x, _, cb) { this.push(x); cb(); } })
readable.pipe(tf)
```
or
```typescript
writable.pipeFrom(tf)
```
Provided that the `ReadableStreamTree` and `WritableStreamTree` are connected later:
```typescript
const returnValue = await pumpWritable(writable, 'any return value', readable.finish())
```
These APIs form the basis of [@wholebuzz/fs](https://www.npmjs.com/package/@wholebuzz/fs),
which together, power [dbcp](https://www.npmjs.com/package/dbcp).
## Usage

@@ -22,0 +64,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc