Skip to content

Commit 5544cc8

Browse files
matthewleonpaf31
authored andcommitted
add unpipe and destroy functions (#21)
1 parent ada8866 commit 5544cc8

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Node/Stream.js

+28
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ exports.pipe = function (r) {
107107
};
108108
};
109109

110+
exports.unpipe = function (r) {
111+
return function (w) {
112+
return function () {
113+
return r.unpipe(w);
114+
};
115+
};
116+
};
117+
118+
exports.unpipeAll = function (r) {
119+
return function () {
120+
return r.unpipe();
121+
};
122+
};
123+
110124
exports.readImpl = function (readChunk) {
111125
return function (Nothing) {
112126
return function (Just) {
@@ -177,3 +191,17 @@ exports.end = function (w) {
177191
};
178192
};
179193
};
194+
195+
exports.destroy = function (strm) {
196+
return function () {
197+
strm.destroy(null);
198+
};
199+
};
200+
201+
exports.destroyWithError = function (strm) {
202+
return function (e) {
203+
return function () {
204+
strm.destroy(e);
205+
};
206+
};
207+
};

src/Node/Stream.purs

+33
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module Node.Stream
2020
, pause
2121
, isPaused
2222
, pipe
23+
, unpipe
24+
, unpipeAll
2325
, read
2426
, readString
2527
, readEither
@@ -29,6 +31,7 @@ module Node.Stream
2931
, uncork
3032
, setDefaultEncoding
3133
, end
34+
, destroy
3235
) where
3336

3437
import Prelude
@@ -234,6 +237,19 @@ foreign import pipe
234237
-> Writable r eff
235238
-> Eff eff (Writable r eff)
236239

240+
-- | Detach a Writable stream previously attached using `pipe`.
241+
foreign import unpipe
242+
:: forall r w eff
243+
. Readable w eff
244+
-> Writable r eff
245+
-> Eff eff Unit
246+
247+
-- | Detach all Writable streams previously attached using `pipe`.
248+
foreign import unpipeAll
249+
:: forall w eff
250+
. Readable w eff
251+
-> Eff eff Unit
252+
237253
-- | Write a Buffer to a writable stream.
238254
foreign import write
239255
:: forall r eff
@@ -290,3 +306,20 @@ foreign import end
290306
. Writable r eff
291307
-> Eff eff Unit
292308
-> Eff eff Unit
309+
310+
-- | Destroy the stream. It will release any internal resources.
311+
--
312+
-- Added in node 8.0.
313+
foreign import destroy
314+
:: forall r eff
315+
. Stream r eff
316+
-> Eff eff Unit
317+
318+
-- | Destroy the stream and emit 'error'.
319+
--
320+
-- Added in node 8.0.
321+
foreign import destroyWithError
322+
:: forall r eff
323+
. Stream r eff
324+
-> Error
325+
-> Eff eff Unit

0 commit comments

Comments
 (0)