Skip to content

Remove the last parameter to Stream #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a piping test
  • Loading branch information
hdgarrood committed Dec 13, 2015
commit e4fc67ecd16e4cda4e14f57a5f1159513bdccf98
5 changes: 2 additions & 3 deletions src/Node/Stream.purs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ onData r cb =
-- | decoded using the given encoding. Note that this will fail if `setEncoding`
-- | has been called on the stream.
onDataString :: forall w eff. Readable w (err :: EXCEPTION | eff) -> Encoding -> (String -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: EXCEPTION | eff) Unit
onDataString r enc cb = onData r $ \buf -> do
str <- unsafeInterleaveEff (Buffer.toString enc buf)
cb str
onDataString r enc cb = onData r (cb <=< unsafeInterleaveEff <<< Buffer.toString enc)

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

Expand Down Expand Up @@ -149,3 +147,4 @@ setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc)

-- | End writing data to the stream.
foreign import end :: forall r eff. Writable r eff -> Eff eff Unit -> Eff eff Unit

8 changes: 8 additions & 0 deletions test/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ exports.putImpl = function(str) {
};
};
};

exports.createGzip = require('zlib').createGzip;
exports.createGunzip = require('zlib').createGunzip;

exports.passThrough = function () {
var s = require('stream');
return new s.PassThrough();
};
31 changes: 31 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ main = do
log "setEncoding should not affect reading"
testSetEncoding

log "test pipe"
testPipe

testString :: String
testString = "üöß💡"

Expand Down Expand Up @@ -71,3 +74,31 @@ testSetEncoding = do
onDataEither r2 \(Left str) -> do
assertEqual <$> Buffer.toString enc buf <*> pure testString
assertEqual str testString

testPipe = do
sIn <- passThrough
sOut <- passThrough
zip <- createGzip
unzip <- createGunzip

log "pipe 1"
sIn `pipe` zip
log "pipe 2"
zip `pipe` unzip
log "pipe 3"
unzip `pipe` sOut

writeString sIn UTF8 testString do
end sIn do
onDataString sOut UTF8 \str -> do
assertEqual str testString

foreign import data GZIP :: !

foreign import createGzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff))
foreign import createGunzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff))

foreign import data PASS_THROUGH :: !

-- | Create a PassThrough stream, which simply writes its input to its output.
foreign import passThrough :: forall eff. Eff (stream :: PASS_THROUGH | eff) (Duplex (stream :: PASS_THROUGH | eff))