File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -78,9 +78,7 @@ onData r cb =
78
78
-- | decoded using the given encoding. Note that this will fail if `setEncoding`
79
79
-- | has been called on the stream.
80
80
onDataString :: forall w eff . Readable w (err :: EXCEPTION | eff ) -> Encoding -> (String -> Eff (err :: EXCEPTION | eff ) Unit ) -> Eff (err :: EXCEPTION | eff ) Unit
81
- onDataString r enc cb = onData r $ \buf -> do
82
- str <- unsafeInterleaveEff (Buffer .toString enc buf)
83
- cb str
81
+ onDataString r enc cb = onData r (cb <=< unsafeInterleaveEff <<< Buffer .toString enc)
84
82
85
83
foreign import onDataEitherImpl :: forall w eff . (forall l r . l -> Either l r ) -> (forall l r . r -> Either l r ) -> Readable w eff -> (Either String Buffer -> Eff eff Unit ) -> Eff eff Unit
86
84
@@ -149,3 +147,4 @@ setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc)
149
147
150
148
-- | End writing data to the stream.
151
149
foreign import end :: forall r eff . Writable r eff -> Eff eff Unit -> Eff eff Unit
150
+
Original file line number Diff line number Diff line change @@ -28,3 +28,11 @@ exports.putImpl = function(str) {
28
28
} ;
29
29
} ;
30
30
} ;
31
+
32
+ exports . createGzip = require ( 'zlib' ) . createGzip ;
33
+ exports . createGunzip = require ( 'zlib' ) . createGunzip ;
34
+
35
+ exports . passThrough = function ( ) {
36
+ var s = require ( 'stream' ) ;
37
+ return new s . PassThrough ( ) ;
38
+ } ;
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ main = do
37
37
log " setEncoding should not affect reading"
38
38
testSetEncoding
39
39
40
+ log " test pipe"
41
+ testPipe
42
+
40
43
testString :: String
41
44
testString = " üöß💡"
42
45
@@ -71,3 +74,31 @@ testSetEncoding = do
71
74
onDataEither r2 \(Left str) -> do
72
75
assertEqual <$> Buffer .toString enc buf <*> pure testString
73
76
assertEqual str testString
77
+
78
+ testPipe = do
79
+ sIn <- passThrough
80
+ sOut <- passThrough
81
+ zip <- createGzip
82
+ unzip <- createGunzip
83
+
84
+ log " pipe 1"
85
+ sIn `pipe` zip
86
+ log " pipe 2"
87
+ zip `pipe` unzip
88
+ log " pipe 3"
89
+ unzip `pipe` sOut
90
+
91
+ writeString sIn UTF8 testString do
92
+ end sIn do
93
+ onDataString sOut UTF8 \str -> do
94
+ assertEqual str testString
95
+
96
+ foreign import data GZIP :: !
97
+
98
+ foreign import createGzip :: forall eff . Eff (gzip :: GZIP | eff ) (Duplex (gzip :: GZIP | eff ))
99
+ foreign import createGunzip :: forall eff . Eff (gzip :: GZIP | eff ) (Duplex (gzip :: GZIP | eff ))
100
+
101
+ foreign import data PASS_THROUGH :: !
102
+
103
+ -- | Create a PassThrough stream, which simply writes its input to its output.
104
+ foreign import passThrough :: forall eff . Eff (stream :: PASS_THROUGH | eff ) (Duplex (stream :: PASS_THROUGH | eff ))
You can’t perform that action at this time.
0 commit comments