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 =
7878-- | decoded using the given encoding. Note that this will fail if `setEncoding`
7979-- | has been called on the stream.
8080onDataString :: 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)
8482
8583foreign 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
8684
@@ -149,3 +147,4 @@ setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc)
149147
150148-- | End writing data to the stream.
151149foreign 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) {
2828 } ;
2929 } ;
3030} ;
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
3737 log " setEncoding should not affect reading"
3838 testSetEncoding
3939
40+ log " test pipe"
41+ testPipe
42+
4043testString :: String
4144testString = " üöß💡"
4245
@@ -71,3 +74,31 @@ testSetEncoding = do
7174 onDataEither r2 \(Left str) -> do
7275 assertEqual <$> Buffer .toString enc buf <*> pure testString
7376 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