Skip to content

Commit

Permalink
add unpipe and destroy functions (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewleon authored and paf31 committed Nov 29, 2017
1 parent ada8866 commit 5544cc8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Node/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ exports.pipe = function (r) {
};
};

exports.unpipe = function (r) {
return function (w) {
return function () {
return r.unpipe(w);
};
};
};

exports.unpipeAll = function (r) {
return function () {
return r.unpipe();
};
};

exports.readImpl = function (readChunk) {
return function (Nothing) {
return function (Just) {
Expand Down Expand Up @@ -177,3 +191,17 @@ exports.end = function (w) {
};
};
};

exports.destroy = function (strm) {
return function () {
strm.destroy(null);
};
};

exports.destroyWithError = function (strm) {
return function (e) {
return function () {
strm.destroy(e);
};
};
};
33 changes: 33 additions & 0 deletions src/Node/Stream.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Node.Stream
, pause
, isPaused
, pipe
, unpipe
, unpipeAll
, read
, readString
, readEither
Expand All @@ -29,6 +31,7 @@ module Node.Stream
, uncork
, setDefaultEncoding
, end
, destroy
) where

import Prelude
Expand Down Expand Up @@ -234,6 +237,19 @@ foreign import pipe
-> Writable r eff
-> Eff eff (Writable r eff)

-- | Detach a Writable stream previously attached using `pipe`.
foreign import unpipe
:: forall r w eff
. Readable w eff
-> Writable r eff
-> Eff eff Unit

-- | Detach all Writable streams previously attached using `pipe`.
foreign import unpipeAll
:: forall w eff
. Readable w eff
-> Eff eff Unit

-- | Write a Buffer to a writable stream.
foreign import write
:: forall r eff
Expand Down Expand Up @@ -290,3 +306,20 @@ foreign import end
. Writable r eff
-> Eff eff Unit
-> Eff eff Unit

-- | Destroy the stream. It will release any internal resources.
--
-- Added in node 8.0.
foreign import destroy
:: forall r eff
. Stream r eff
-> Eff eff Unit

-- | Destroy the stream and emit 'error'.
--
-- Added in node 8.0.
foreign import destroyWithError
:: forall r eff
. Stream r eff
-> Error
-> Eff eff Unit

0 comments on commit 5544cc8

Please sign in to comment.