Skip to content

Commit

Permalink
Support stream1.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jan 25, 2017
1 parent 36eafbe commit 0e368b6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 45 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ The API is the same of a streams 3 [`Transform`][transform], with some major dif
have `_readableState` nor `_writableState`.
3. it does not have a `read(n)` method, nor it emits the
`'readable'` event, the data is pushed whenever ready.
4. it only works with streams 2 and streams 3 implementations, not with
streams 1 (through, split, etc).

<a name="acknowledgements"></a>
## Acknowledgements
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"standard": "^8.6.0",
"tap-spec": "^4.1.1",
"tape": "^4.6.3",
"through": "^2.3.8",
"through2": "^2.0.3"
},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions syncthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function SyncThrough (transform, flush) {
this._flush = flush || passthrough
this._destination = null
this._inFlight = undefined
this._ended = false
this.writable = true
this._endEmitted = false
this._destinationNeedsEnd = true
this._lastPush = true
Expand All @@ -42,7 +42,7 @@ function deferPiping (that) {
}

that.pipe(new OnData(that))
if (that._ended & !that._endEmitted) {
if (!that.writable & !that._endEmitted) {
that.emit('end')
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ SyncThrough.prototype.unpipe = function (dest) {
}

SyncThrough.prototype.write = function (chunk) {
if (this._ended) {
if (!this.writable) {
this.emit('error', new Error('write after EOF'))
return false
}
Expand Down Expand Up @@ -146,8 +146,8 @@ SyncThrough.prototype.end = function (chunk) {
}

function doEnd (that) {
if (!that._ended) {
that._ended = true
if (that.writable) {
that.writable = false
if (that._destination) {
that._endEmitted = true
that.emit('end')
Expand Down
Loading

0 comments on commit 0e368b6

Please sign in to comment.