From 0bb57f01eb4b5e8ab064de80cbdfa177086ab6d1 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 04:42:17 +0100 Subject: [PATCH 01/18] Remove the last type parameter of Stream It should be possible to read and write both String and Buffer at any time; the Node API offers Strings for convenience only, so there is no need for the last type parameter of Stream. --- src/Node/Stream.js | 2 +- src/Node/Stream.purs | 60 ++++++++++++++++++++++++++------------------ test/Main.purs | 6 ++--- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/Node/Stream.js b/src/Node/Stream.js index 2e47321..05e1716 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -10,7 +10,7 @@ exports.setEncodingImpl = function(s) { }; }; -exports.onData = function(s) { +exports.onDataImpl = function(s) { return function(f) { return function() { s.on('data', function(chunk) { diff --git a/src/Node/Stream.purs b/src/Node/Stream.purs index bdc5fc3..8023db8 100644 --- a/src/Node/Stream.purs +++ b/src/Node/Stream.purs @@ -27,8 +27,11 @@ module Node.Stream import Prelude import Node.Encoding +import Node.Buffer (Buffer()) +import Node.Buffer as Buffer import Control.Monad.Eff +import Control.Monad.Eff.Unsafe (unsafeInterleaveEff) -- | A stream. -- | @@ -36,8 +39,7 @@ import Control.Monad.Eff -- | -- | - Whether reading and/or writing from/to the stream are allowed. -- | - Effects associated with reading/writing from/to this stream. --- | - The type of chunks which will be read from/written to this stream (`String` or `Buffer`). -foreign import data Stream :: # * -> # ! -> * -> * +foreign import data Stream :: # * -> # ! -> * -- | A phantom type associated with _readable streams_. data Read @@ -54,56 +56,66 @@ type Writable r = Stream (write :: Write | r) -- | A duplex (readable _and_ writable stream) type Duplex = Stream (read :: Read, write :: Write) -foreign import setEncodingImpl :: forall w eff. Readable w eff String -> String -> Eff eff Unit +foreign import setEncodingImpl :: forall w eff. Readable w eff -> String -> Eff eff Unit --- | Set the encoding used to read chunks from the stream. -setEncoding :: forall w eff. Readable w eff String -> Encoding -> Eff eff Unit +-- | Set the encoding used to read chunks as strings from the stream. +setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit setEncoding r enc = setEncodingImpl r (show enc) --- | Listen for `data` events. -foreign import onData :: forall w eff a. Readable w eff a -> (a -> Eff eff Unit) -> Eff eff Unit +foreign import onDataImpl :: forall w eff a. Readable w eff -> (a -> Eff eff Unit) -> Eff eff Unit + +-- | Listen for `data` events, returning data in a Buffer. +onData :: forall w eff. Readable w eff -> (Buffer -> Eff eff Unit) -> Eff eff Unit +onData = onDataImpl + +-- | Listen for `data` events, returning data in a String, decoded with the +-- | given encoding. +onDataString :: forall w eff. Readable w eff -> Encoding -> (String -> Eff eff Unit) -> Eff eff Unit +onDataString r enc cb = onData r $ \buf -> do + str <- unsafeInterleaveEff (Buffer.toString enc buf) + cb str -- | Listen for `end` events. -foreign import onEnd :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit +foreign import onEnd :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit -- | Listen for `close` events. -foreign import onClose :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit +foreign import onClose :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit -- | Listen for `error` events. -foreign import onError :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit +foreign import onError :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit -- | Resume reading from the stream. -foreign import resume :: forall w eff a. Readable w eff a -> Eff eff Unit +foreign import resume :: forall w eff. Readable w eff -> Eff eff Unit -- | Pause reading from the stream. -foreign import pause :: forall w eff a. Readable w eff a -> Eff eff Unit +foreign import pause :: forall w eff. Readable w eff -> Eff eff Unit -- | Check whether or not a stream is paused for reading. -foreign import isPaused :: forall w eff a. Readable w eff a -> Eff eff Boolean +foreign import isPaused :: forall w eff. Readable w eff -> Eff eff Boolean -- | Read chunks from a readable stream and write them to a writable stream. -foreign import pipe :: forall r w eff a. Readable w eff a -> Writable r eff a -> Eff eff (Writable r eff a) +foreign import pipe :: forall r w eff. Readable w eff -> Writable r eff -> Eff eff (Writable r eff) --- | Write a chunk to a writable stream. -foreign import write :: forall r eff a. Writable r eff String -> a -> Eff eff Unit -> Eff eff Boolean +-- | Write a Buffer to a writable stream. +foreign import write :: forall r eff. Writable r eff -> Buffer -> Eff eff Unit -> Eff eff Boolean -foreign import writeStringImpl :: forall r eff. Writable r eff String -> String -> String -> Eff eff Unit -> Eff eff Boolean +foreign import writeStringImpl :: forall r eff. Writable r eff -> String -> String -> Eff eff Unit -> Eff eff Boolean -- | Write a string in the specified encoding to a writable stream. -writeString :: forall r eff. Writable r eff String -> Encoding -> String -> Eff eff Unit -> Eff eff Boolean +writeString :: forall r eff. Writable r eff -> Encoding -> String -> Eff eff Unit -> Eff eff Boolean writeString w enc = writeStringImpl w (show enc) -- | Force buffering of writes. -foreign import cork :: forall r eff a. Writable r eff a -> Eff eff Unit +foreign import cork :: forall r eff. Writable r eff -> Eff eff Unit -- | Flush buffered data. -foreign import uncork :: forall r eff a. Writable r eff a -> Eff eff Unit +foreign import uncork :: forall r eff. Writable r eff -> Eff eff Unit -foreign import setDefaultEncodingImpl :: forall r eff. Writable r eff String -> String -> Eff eff Unit +foreign import setDefaultEncodingImpl :: forall r eff. Writable r eff -> String -> Eff eff Unit --- | Set the default encoding used to write chunks to the stream. -setDefaultEncoding :: forall r eff. Writable r eff String -> Encoding -> Eff eff Unit +-- | Set the default encoding used to write chunks to the stream. This +setDefaultEncoding :: forall r eff. Writable r eff -> Encoding -> Eff eff Unit setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc) -- | End writing data to the stream. -foreign import end :: forall r eff a. Writable r eff a -> Eff eff Unit -> Eff eff Unit +foreign import end :: forall r eff. Writable r eff -> Eff eff Unit -> Eff eff Unit diff --git a/test/Main.purs b/test/Main.purs index 1bd59ee..10cf1ca 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -9,11 +9,11 @@ import Control.Monad.Eff.Console foreign import data GZIP :: ! -foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) String +foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) -foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) String +foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) -foreign import gzip :: forall eff a. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff) a) +foreign import gzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) main = do z <- gzip From d73fa50e47a56bd5b16cd9530b8d2274469f4418 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 04:52:56 +0100 Subject: [PATCH 02/18] Improve docs --- src/Node/Stream.purs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Node/Stream.purs b/src/Node/Stream.purs index 8023db8..e71a9e4 100644 --- a/src/Node/Stream.purs +++ b/src/Node/Stream.purs @@ -58,7 +58,11 @@ type Duplex = Stream (read :: Read, write :: Write) foreign import setEncodingImpl :: forall w eff. Readable w eff -> String -> Eff eff Unit --- | Set the encoding used to read chunks as strings from the stream. +-- | Set the encoding used to read chunks as strings from the stream. This +-- | function is useful when you are passing a readable stream to some other +-- | JavaScript library, which already expects an encoding to be set. It +-- | has no effect on the behaviour of the `onDataString` function (because +-- | that function ensures that the encoding is always supplied explicitly). setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit setEncoding r enc = setEncodingImpl r (show enc) @@ -68,8 +72,8 @@ foreign import onDataImpl :: forall w eff a. Readable w eff -> (a -> Eff eff Uni onData :: forall w eff. Readable w eff -> (Buffer -> Eff eff Unit) -> Eff eff Unit onData = onDataImpl --- | Listen for `data` events, returning data in a String, decoded with the --- | given encoding. +-- | Listen for `data` events, returning data in a String, which will be +-- | decoded using the given encoding. onDataString :: forall w eff. Readable w eff -> Encoding -> (String -> Eff eff Unit) -> Eff eff Unit onDataString r enc cb = onData r $ \buf -> do str <- unsafeInterleaveEff (Buffer.toString enc buf) @@ -113,7 +117,11 @@ foreign import uncork :: forall r eff. Writable r eff -> Eff eff Unit foreign import setDefaultEncodingImpl :: forall r eff. Writable r eff -> String -> Eff eff Unit --- | Set the default encoding used to write chunks to the stream. This +-- | Set the default encoding used to write chunks to the stream. This function +-- | is useful when you are passing a writable stream to some other JavaScript +-- | library, which already expects a default encoding to be set. It has no +-- | effect on the behaviour of the `writeString` function (because that +-- | function ensures that the encoding is always supplied explicitly). setDefaultEncoding :: forall r eff. Writable r eff -> Encoding -> Eff eff Unit setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc) From 2e9432fe1fd040ed16dc081595dc8d5f5c2023f6 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 04:54:13 +0100 Subject: [PATCH 03/18] Another doc fix --- src/Node/Stream.purs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Node/Stream.purs b/src/Node/Stream.purs index e71a9e4..e0decec 100644 --- a/src/Node/Stream.purs +++ b/src/Node/Stream.purs @@ -9,6 +9,7 @@ module Node.Stream , Duplex() , setEncoding , onData + , onDataString , onEnd , onClose , onError @@ -117,7 +118,7 @@ foreign import uncork :: forall r eff. Writable r eff -> Eff eff Unit foreign import setDefaultEncodingImpl :: forall r eff. Writable r eff -> String -> Eff eff Unit --- | Set the default encoding used to write chunks to the stream. This function +-- | Set the default encoding used to write strings to the stream. This function -- | is useful when you are passing a writable stream to some other JavaScript -- | library, which already expects a default encoding to be set. It has no -- | effect on the behaviour of the `writeString` function (because that From cf6e8512a1ae72287b2c0c46a56704260f120c3d Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 04:56:43 +0100 Subject: [PATCH 04/18] Add project boilerplate --- .travis.yml | 15 +++++++++++++++ package.json | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .travis.yml create mode 100644 package.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..15f5237 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: node_js +sudo: false +node_js: + - 4.2 + - 5.2 +env: + - PATH=$HOME/purescript:$PATH +install: + - TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p') + - wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz + - tar -xvf $HOME/purescript.tar.gz -C $HOME/ + - chmod a+x $HOME/purescript + - npm install +script: + - npm run build diff --git a/package.json b/package.json new file mode 100644 index 0000000..3679e2c --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "private": true, + "scripts": { + "postinstall": "pulp dep install", + "build": "jshint src && jscs src && pulp build && rimraf docs && pulp docs" + }, + "devDependencies": { + "jscs": "^1.13.1", + "jshint": "^2.8.0", + "pulp": "^4.0.2", + "rimraf": "^2.4.1", + "stream-buffers": "^3.0.0" + } +} From d639a953d25616aa5b9b68b30c76250195306e0c Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 04:59:07 +0100 Subject: [PATCH 05/18] Add standard IO streams --- src/Node/Stream/StdIO.purs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/Node/Stream/StdIO.purs diff --git a/src/Node/Stream/StdIO.purs b/src/Node/Stream/StdIO.purs new file mode 100644 index 0000000..069baa8 --- /dev/null +++ b/src/Node/Stream/StdIO.purs @@ -0,0 +1,6 @@ +-- | The standard IO streams for the current process. +module Node.Stream.StdIO where + +foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) +foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) +foreign import stderr :: forall eff. Writable () (console :: CONSOLE | eff) From e2227eeddc9c53f0136773bf3c8d11254e7ad0a6 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 05:04:03 +0100 Subject: [PATCH 06/18] Update docs --- docs/Node/Stream.md | 58 +++++++++++++++++++++++++-------------- docs/Node/Stream/StdIO.md | 23 ++++++++++++++++ 2 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 docs/Node/Stream/StdIO.md diff --git a/docs/Node/Stream.md b/docs/Node/Stream.md index 5c040d4..b0edc91 100644 --- a/docs/Node/Stream.md +++ b/docs/Node/Stream.md @@ -5,7 +5,7 @@ This module provides a low-level wrapper for the Node Stream API. #### `Stream` ``` purescript -data Stream :: # * -> # ! -> * -> * +data Stream :: # * -> # ! -> * ``` A stream. @@ -14,7 +14,6 @@ The type arguments track, in order: - Whether reading and/or writing from/to the stream are allowed. - Effects associated with reading/writing from/to this stream. -- The type of chunks which will be read from/written to this stream (`String` or `Buffer`). #### `Read` @@ -59,23 +58,36 @@ A duplex (readable _and_ writable stream) #### `setEncoding` ``` purescript -setEncoding :: forall w eff. Readable w eff String -> Encoding -> Eff eff Unit +setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit ``` -Set the encoding used to read chunks from the stream. +Set the encoding used to read chunks as strings from the stream. This +function is useful when you are passing a readable stream to some other +JavaScript library, which already expects an encoding to be set. It +has no effect on the behaviour of the `onDataString` function (because +that function ensures that the encoding is always supplied explicitly). #### `onData` ``` purescript -onData :: forall w eff a. Readable w eff a -> (a -> Eff eff Unit) -> Eff eff Unit +onData :: forall w eff. Readable w eff -> (Buffer -> Eff eff Unit) -> Eff eff Unit ``` -Listen for `data` events. +Listen for `data` events, returning data in a Buffer. + +#### `onDataString` + +``` purescript +onDataString :: forall w eff. Readable w eff -> Encoding -> (String -> Eff eff Unit) -> Eff eff Unit +``` + +Listen for `data` events, returning data in a String, which will be +decoded using the given encoding. #### `onEnd` ``` purescript -onEnd :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit +onEnd :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit ``` Listen for `end` events. @@ -83,7 +95,7 @@ Listen for `end` events. #### `onClose` ``` purescript -onClose :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit +onClose :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit ``` Listen for `close` events. @@ -91,7 +103,7 @@ Listen for `close` events. #### `onError` ``` purescript -onError :: forall w eff a. Readable w eff a -> Eff eff Unit -> Eff eff Unit +onError :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit ``` Listen for `error` events. @@ -99,7 +111,7 @@ Listen for `error` events. #### `resume` ``` purescript -resume :: forall w eff a. Readable w eff a -> Eff eff Unit +resume :: forall w eff. Readable w eff -> Eff eff Unit ``` Resume reading from the stream. @@ -107,7 +119,7 @@ Resume reading from the stream. #### `pause` ``` purescript -pause :: forall w eff a. Readable w eff a -> Eff eff Unit +pause :: forall w eff. Readable w eff -> Eff eff Unit ``` Pause reading from the stream. @@ -115,7 +127,7 @@ Pause reading from the stream. #### `isPaused` ``` purescript -isPaused :: forall w eff a. Readable w eff a -> Eff eff Boolean +isPaused :: forall w eff. Readable w eff -> Eff eff Boolean ``` Check whether or not a stream is paused for reading. @@ -123,7 +135,7 @@ Check whether or not a stream is paused for reading. #### `pipe` ``` purescript -pipe :: forall r w eff a. Readable w eff a -> Writable r eff a -> Eff eff (Writable r eff a) +pipe :: forall r w eff. Readable w eff -> Writable r eff -> Eff eff (Writable r eff) ``` Read chunks from a readable stream and write them to a writable stream. @@ -131,15 +143,15 @@ Read chunks from a readable stream and write them to a writable stream. #### `write` ``` purescript -write :: forall r eff a. Writable r eff String -> a -> Eff eff Unit -> Eff eff Boolean +write :: forall r eff. Writable r eff -> Buffer -> Eff eff Unit -> Eff eff Boolean ``` -Write a chunk to a writable stream. +Write a Buffer to a writable stream. #### `writeString` ``` purescript -writeString :: forall r eff. Writable r eff String -> Encoding -> String -> Eff eff Unit -> Eff eff Boolean +writeString :: forall r eff. Writable r eff -> Encoding -> String -> Eff eff Unit -> Eff eff Boolean ``` Write a string in the specified encoding to a writable stream. @@ -147,7 +159,7 @@ Write a string in the specified encoding to a writable stream. #### `cork` ``` purescript -cork :: forall r eff a. Writable r eff a -> Eff eff Unit +cork :: forall r eff. Writable r eff -> Eff eff Unit ``` Force buffering of writes. @@ -155,7 +167,7 @@ Force buffering of writes. #### `uncork` ``` purescript -uncork :: forall r eff a. Writable r eff a -> Eff eff Unit +uncork :: forall r eff. Writable r eff -> Eff eff Unit ``` Flush buffered data. @@ -163,15 +175,19 @@ Flush buffered data. #### `setDefaultEncoding` ``` purescript -setDefaultEncoding :: forall r eff. Writable r eff String -> Encoding -> Eff eff Unit +setDefaultEncoding :: forall r eff. Writable r eff -> Encoding -> Eff eff Unit ``` -Set the default encoding used to write chunks to the stream. +Set the default encoding used to write strings to the stream. This function +is useful when you are passing a writable stream to some other JavaScript +library, which already expects a default encoding to be set. It has no +effect on the behaviour of the `writeString` function (because that +function ensures that the encoding is always supplied explicitly). #### `end` ``` purescript -end :: forall r eff a. Writable r eff a -> Eff eff Unit -> Eff eff Unit +end :: forall r eff. Writable r eff -> Eff eff Unit -> Eff eff Unit ``` End writing data to the stream. diff --git a/docs/Node/Stream/StdIO.md b/docs/Node/Stream/StdIO.md new file mode 100644 index 0000000..44d0b5f --- /dev/null +++ b/docs/Node/Stream/StdIO.md @@ -0,0 +1,23 @@ +## Module Node.Stream.StdIO + +The standard IO streams for the current process. + +#### `stdin` + +``` purescript +stdin :: forall eff. Readable () (console :: CONSOLE | eff) +``` + +#### `stdout` + +``` purescript +stdout :: forall eff. Writable () (console :: CONSOLE | eff) +``` + +#### `stderr` + +``` purescript +stderr :: forall eff. Writable () (console :: CONSOLE | eff) +``` + + From 06c5defc0b8abf93ecbd23bf5f195ba8564cf7b1 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 05:04:17 +0100 Subject: [PATCH 07/18] StdIO streams --- .jshintrc | 20 ++++++++++++++++++++ package.json | 3 +-- src/Node/Stream.js | 1 + src/Node/Stream/StdIO.js | 10 ++++++++++ src/Node/Stream/StdIO.purs | 5 +++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .jshintrc create mode 100644 src/Node/Stream/StdIO.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..7374779 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,20 @@ +{ + "bitwise": true, + "eqeqeq": true, + "forin": true, + "freeze": true, + "funcscope": true, + "futurehostile": true, + "globalstrict": true, + "latedef": true, + "maxparams": 1, + "noarg": true, + "nocomma": true, + "nonew": true, + "notypeof": true, + "singleGroups": true, + "undef": true, + "unused": true, + "eqnull": true +} + diff --git a/package.json b/package.json index 3679e2c..ef6976b 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,9 @@ "private": true, "scripts": { "postinstall": "pulp dep install", - "build": "jshint src && jscs src && pulp build && rimraf docs && pulp docs" + "build": "jshint src && pulp build && rimraf docs && pulp docs" }, "devDependencies": { - "jscs": "^1.13.1", "jshint": "^2.8.0", "pulp": "^4.0.2", "rimraf": "^2.4.1", diff --git a/src/Node/Stream.js b/src/Node/Stream.js index 05e1716..d6a000e 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -1,3 +1,4 @@ +/* global exports */ "use strict"; // module Node.Stream diff --git a/src/Node/Stream/StdIO.js b/src/Node/Stream/StdIO.js new file mode 100644 index 0000000..42cbc93 --- /dev/null +++ b/src/Node/Stream/StdIO.js @@ -0,0 +1,10 @@ +/* global exports */ +/* global process */ +"use strict"; + +// module Node.Stream.StdIO + + +exports.stdin = process.stdin; +exports.stdout = process.stdout; +exports.stderr = process.stderr; diff --git a/src/Node/Stream/StdIO.purs b/src/Node/Stream/StdIO.purs index 069baa8..857756d 100644 --- a/src/Node/Stream/StdIO.purs +++ b/src/Node/Stream/StdIO.purs @@ -1,6 +1,11 @@ -- | The standard IO streams for the current process. module Node.Stream.StdIO where +import Prelude +import Control.Monad.Eff.Console + +import Node.Stream + foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) foreign import stderr :: forall eff. Writable () (console :: CONSOLE | eff) From 873d7dcffb0cb0a67573470cf1a89d1afa8cd8b4 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 05:11:03 +0100 Subject: [PATCH 08/18] Move Gzip test to an example --- example/Gzip.js | 7 +++++++ example/Gzip.purs | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 example/Gzip.js create mode 100644 example/Gzip.purs diff --git a/example/Gzip.js b/example/Gzip.js new file mode 100644 index 0000000..c916751 --- /dev/null +++ b/example/Gzip.js @@ -0,0 +1,7 @@ +/* global exports */ +/* global require */ +"use strict"; + +// module Gzip + +exports.gzip = require('zlib').createGzip; diff --git a/example/Gzip.purs b/example/Gzip.purs new file mode 100644 index 0000000..224a9ef --- /dev/null +++ b/example/Gzip.purs @@ -0,0 +1,20 @@ +module Gzip where + +import Prelude + +import Node.Stream +import Node.Stream.StdIO + +import Control.Monad.Eff +import Control.Monad.Eff.Console + +foreign import data GZIP :: ! + +foreign import gzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) + +foreign import + +main = do + z <- gzip + stdin `pipe` z + z `pipe` stdout From c9a379ec66244870d202a393d08d3815fe33a4db Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 05:11:31 +0100 Subject: [PATCH 09/18] Remove unneeded FFI declarations --- test/Main.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/Main.js b/test/Main.js index 6e98398..06f5010 100644 --- a/test/Main.js +++ b/test/Main.js @@ -2,8 +2,4 @@ // module Test.Main -exports.stdin = process.stdin; - -exports.stdout = process.stdout; - -exports.gzip = require('zlib').createGzip; \ No newline at end of file +exports.gzip = require('zlib').createGzip; From c6597001c479e85211574ff092e1bc71adb087b4 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Thu, 10 Dec 2015 08:38:06 +0100 Subject: [PATCH 10/18] tests --- bower.json | 3 +- src/Node/Stream.js | 3 ++ test/Main.js | 27 ++++++++++++++++- test/Main.purs | 74 +++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 98 insertions(+), 9 deletions(-) diff --git a/bower.json b/bower.json index 4bdf5c9..ea22489 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,8 @@ "url": "git://github.com/purescript-node/purescript-node-streams.git" }, "devDependencies": { - "purescript-console": "^0.1.0" + "purescript-console": "^0.1.0", + "purescript-assert": "~0.1.1" }, "dependencies": { "purescript-eff": "~0.1.1", diff --git a/src/Node/Stream.js b/src/Node/Stream.js index d6a000e..3403dfd 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -15,6 +15,9 @@ exports.onDataImpl = function(s) { return function(f) { return function() { s.on('data', function(chunk) { + if (!(chunk instanceof Buffer)) { + throw new Error("Node.Stream.onDataImpl: stream encoding should not be set"); + } f(chunk)(); }); }; diff --git a/test/Main.js b/test/Main.js index 06f5010..1419e59 100644 --- a/test/Main.js +++ b/test/Main.js @@ -2,4 +2,29 @@ // module Test.Main -exports.gzip = require('zlib').createGzip; + +exports.writableStreamBuffer = function() { + var W = require('stream-buffers').WritableStreamBuffer; + return new W; +}; + +exports.getContentsAsString = function(w) { + return function() { + return w.getContentsAsString('utf8'); + }; +}; + +exports.readableStreamBuffer = function() { + var R = require('stream-buffers').ReadableStreamBuffer; + return new R; +}; + +exports.putImpl = function(str) { + return function(enc) { + return function(r) { + return function() { + r.put(str, enc); + }; + }; + }; +}; diff --git a/test/Main.purs b/test/Main.purs index 10cf1ca..a1824a0 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,20 +2,80 @@ module Test.Main where import Prelude +import Node.Buffer as Buffer +import Node.Encoding import Node.Stream +import Node.Stream.StdIO import Control.Monad.Eff import Control.Monad.Eff.Console -foreign import data GZIP :: ! +import Test.Assert -foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) +assertEqual :: forall e a. (Show a, Eq a) => a -> a -> Eff (assert :: ASSERT | e) Unit +assertEqual x y = + assert' (show x <> " did not equal " <> show y) (x == y) -foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) +foreign import data STREAM_BUFFER :: ! -foreign import gzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) +foreign import writableStreamBuffer :: forall eff. Eff (sb :: STREAM_BUFFER | eff) (Writable () (sb :: STREAM_BUFFER | eff)) + +foreign import getContentsAsString :: forall r eff. Writable r (sb :: STREAM_BUFFER | eff) -> Eff (sb :: STREAM_BUFFER | eff) String + +foreign import readableStreamBuffer :: forall eff. Eff (sb :: STREAM_BUFFER | eff) (Readable () (sb :: STREAM_BUFFER | eff)) + +foreign import putImpl :: forall r eff. String -> String -> Readable r (sb :: STREAM_BUFFER | eff) -> Eff (sb :: STREAM_BUFFER | eff) Unit + +put :: forall r eff. String -> Encoding -> Readable r (sb :: STREAM_BUFFER | eff) -> Eff (sb :: STREAM_BUFFER | eff) Unit +put str enc = putImpl str (show enc) main = do - z <- gzip - stdin `pipe` z - z `pipe` stdout + log "setDefaultEncoding should not affect writing" + testSetDefaultEncoding + + log "setEncoding should not affect reading" + testSetEncoding + +testString :: String +testString = "Liebe Grüße\nBergentrückung\n💡" + +testSetDefaultEncoding = do + w1 <- writableStreamBuffer + check w1 + + w2 <- writableStreamBuffer + setDefaultEncoding w2 UCS2 + check w2 + + where + check w = do + writeString w UTF8 testString do + c <- getContentsAsString w + assertEqual testString c + +testSetEncoding = do + check readableStreamBuffer + + check do + r2 <- readableStreamBuffer + setEncoding r2 UTF8 + pure r2 + + check do + r3 <- readableStreamBuffer + setEncoding r3 UCS2 + pure r3 + + where + check makeR = do + r1 <- makeR + put testString UTF8 r1 + + r2 <- makeR + put testString UTF8 r2 + + onData r1 \buf -> do + onDataString r2 UTF8 \str -> do + assertEqual <$> Buffer.toString UTF8 buf <*> pure testString + assertEqual str testString + log "ok." From c81554aee22ea0c814889557a0def0b8b735d50f Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Sun, 13 Dec 2015 12:43:56 +0100 Subject: [PATCH 11/18] Add onDataEither Useful in the case where `setEncoding` has been called, although this is a bad idea in most cases. --- bower.json | 4 +++- docs/Node/Stream.md | 41 ++++++++++++++++++++----------- src/Node/Stream.js | 31 +++++++++++++++++------- src/Node/Stream.purs | 57 ++++++++++++++++++++++++++++++-------------- 4 files changed, 91 insertions(+), 42 deletions(-) diff --git a/bower.json b/bower.json index ea22489..9f30525 100644 --- a/bower.json +++ b/bower.json @@ -20,6 +20,8 @@ "dependencies": { "purescript-eff": "~0.1.1", "purescript-node-buffer": "~0.2.0", - "purescript-prelude": "~0.1.2" + "purescript-prelude": "~0.1.2", + "purescript-either": "~0.2.3", + "purescript-exceptions": "~0.3.3" } } diff --git a/docs/Node/Stream.md b/docs/Node/Stream.md index b0edc91..d153d61 100644 --- a/docs/Node/Stream.md +++ b/docs/Node/Stream.md @@ -55,34 +55,47 @@ type Duplex = Stream (read :: Read, write :: Write) A duplex (readable _and_ writable stream) -#### `setEncoding` +#### `onData` ``` purescript -setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit +onData :: forall w eff. Readable w (err :: EXCEPTION | eff) -> (Buffer -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: EXCEPTION | eff) Unit ``` -Set the encoding used to read chunks as strings from the stream. This -function is useful when you are passing a readable stream to some other -JavaScript library, which already expects an encoding to be set. It -has no effect on the behaviour of the `onDataString` function (because -that function ensures that the encoding is always supplied explicitly). +Listen for `data` events, returning data in a Buffer. Note that this will fail +if `setEncoding` has been called on the stream. -#### `onData` +#### `onDataString` ``` purescript -onData :: forall w eff. Readable w eff -> (Buffer -> Eff eff Unit) -> Eff eff Unit +onDataString :: forall w eff. Readable w (err :: EXCEPTION | eff) -> Encoding -> (String -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: EXCEPTION | eff) Unit ``` -Listen for `data` events, returning data in a Buffer. +Listen for `data` events, returning data in a String, which will be +decoded using the given encoding. Note that this will fail if `setEncoding` +has been called on the stream. -#### `onDataString` +#### `onDataEither` ``` purescript -onDataString :: forall w eff. Readable w eff -> Encoding -> (String -> Eff eff Unit) -> Eff eff Unit +onDataEither :: forall w eff. Readable w eff -> (Either String Buffer -> Eff eff Unit) -> Eff eff Unit ``` -Listen for `data` events, returning data in a String, which will be -decoded using the given encoding. +Listen for `data` events, returning data in an `Either String Buffer`. This +function is provided for the (hopefully rare) case that `setEncoding` has +been called on the stream. + +#### `setEncoding` + +``` purescript +setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit +``` + +Set the encoding used to read chunks as strings from the stream. This +function may be useful when you are passing a readable stream to some other +JavaScript library, which already expects an encoding to be set. + +Where possible, you should try to use `onDataString` instead of this +function. #### `onEnd` diff --git a/src/Node/Stream.js b/src/Node/Stream.js index 3403dfd..fae9386 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -1,4 +1,5 @@ /* global exports */ +/* global Buffer */ "use strict"; // module Node.Stream @@ -11,15 +12,27 @@ exports.setEncodingImpl = function(s) { }; }; -exports.onDataImpl = function(s) { - return function(f) { - return function() { - s.on('data', function(chunk) { - if (!(chunk instanceof Buffer)) { - throw new Error("Node.Stream.onDataImpl: stream encoding should not be set"); - } - f(chunk)(); - }); +exports.onDataEitherImpl = function(left){ + return function(right){ + return function(s) { + return function(f) { + return function() { + s.on('data', function(chunk) { + if (chunk instanceof Buffer) { + f(right(chunk))(); + } + else if (chunk instanceof String) { + f(left(chunk))(); + } + else { + throw new Error( + "Node.Stream.onDataEitherImpl: Unrecognised" + + "chunk type; expected String or Buffer, got:" + + chunk); + } + }); + }; + }; }; }; }; diff --git a/src/Node/Stream.purs b/src/Node/Stream.purs index e0decec..44a9981 100644 --- a/src/Node/Stream.purs +++ b/src/Node/Stream.purs @@ -7,9 +7,10 @@ module Node.Stream , Write() , Writable() , Duplex() - , setEncoding , onData , onDataString + , onDataEither + , setEncoding , onEnd , onClose , onError @@ -27,11 +28,14 @@ module Node.Stream import Prelude +import Control.Bind ((<=<)) +import Data.Either (Either(..)) import Node.Encoding import Node.Buffer (Buffer()) import Node.Buffer as Buffer import Control.Monad.Eff +import Control.Monad.Eff.Exception (throw, EXCEPTION()) import Control.Monad.Eff.Unsafe (unsafeInterleaveEff) -- | A stream. @@ -57,29 +61,46 @@ type Writable r = Stream (write :: Write | r) -- | A duplex (readable _and_ writable stream) type Duplex = Stream (read :: Read, write :: Write) -foreign import setEncodingImpl :: forall w eff. Readable w eff -> String -> Eff eff Unit - --- | Set the encoding used to read chunks as strings from the stream. This --- | function is useful when you are passing a readable stream to some other --- | JavaScript library, which already expects an encoding to be set. It --- | has no effect on the behaviour of the `onDataString` function (because --- | that function ensures that the encoding is always supplied explicitly). -setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit -setEncoding r enc = setEncodingImpl r (show enc) - -foreign import onDataImpl :: forall w eff a. Readable w eff -> (a -> Eff eff Unit) -> Eff eff Unit - --- | Listen for `data` events, returning data in a Buffer. -onData :: forall w eff. Readable w eff -> (Buffer -> Eff eff Unit) -> Eff eff Unit -onData = onDataImpl +-- | Listen for `data` events, returning data in a Buffer. Note that this will fail +-- | if `setEncoding` has been called on the stream. +onData :: forall w eff. Readable w (err :: EXCEPTION | eff) -> (Buffer -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: EXCEPTION | eff) Unit +onData r cb = + onDataEither r (cb <=< fromEither) + where + fromEither x = + case x of + Left _ -> + throw "Node.Stream.onData: Stream encoding should not be set" + Right buf -> + pure buf -- | Listen for `data` events, returning data in a String, which will be --- | decoded using the given encoding. -onDataString :: forall w eff. Readable w eff -> Encoding -> (String -> Eff eff Unit) -> Eff eff Unit +-- | 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 +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 + +-- | Listen for `data` events, returning data in an `Either String Buffer`. This +-- | function is provided for the (hopefully rare) case that `setEncoding` has +-- | been called on the stream. +onDataEither :: forall w eff. Readable w eff -> (Either String Buffer -> Eff eff Unit) -> Eff eff Unit +onDataEither = onDataEitherImpl Left Right + +foreign import setEncodingImpl :: forall w eff. Readable w eff -> String -> Eff eff Unit + +-- | Set the encoding used to read chunks as strings from the stream. This +-- | function may be useful when you are passing a readable stream to some other +-- | JavaScript library, which already expects an encoding to be set. +-- | +-- | Where possible, you should try to use `onDataString` instead of this +-- | function. +setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit +setEncoding r enc = setEncodingImpl r (show enc) + -- | Listen for `end` events. foreign import onEnd :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit From 540acfceba67076c8be033d19abd7caab8730117 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Sun, 13 Dec 2015 12:57:29 +0100 Subject: [PATCH 12/18] Fix String check --- src/Node/Stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Node/Stream.js b/src/Node/Stream.js index fae9386..55de1a1 100644 --- a/src/Node/Stream.js +++ b/src/Node/Stream.js @@ -21,7 +21,7 @@ exports.onDataEitherImpl = function(left){ if (chunk instanceof Buffer) { f(right(chunk))(); } - else if (chunk instanceof String) { + else if (typeof chunk === "string") { f(left(chunk))(); } else { From 23f82352a15d06d1797e0437ef457679e8838e9d Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Sun, 13 Dec 2015 12:57:35 +0100 Subject: [PATCH 13/18] Update tests --- test/Main.purs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index a1824a0..5a9ad19 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,6 +2,7 @@ module Test.Main where import Prelude +import Data.Either (Either(..)) import Node.Buffer as Buffer import Node.Encoding import Node.Stream @@ -37,7 +38,7 @@ main = do testSetEncoding testString :: String -testString = "Liebe Grüße\nBergentrückung\n💡" +testString = "üöß💡" testSetDefaultEncoding = do w1 <- writableStreamBuffer @@ -54,28 +55,19 @@ testSetDefaultEncoding = do assertEqual testString c testSetEncoding = do - check readableStreamBuffer - - check do - r2 <- readableStreamBuffer - setEncoding r2 UTF8 - pure r2 - - check do - r3 <- readableStreamBuffer - setEncoding r3 UCS2 - pure r3 - + check UTF8 + check UTF16LE + check UCS2 where - check makeR = do - r1 <- makeR - put testString UTF8 r1 + check enc = do + r1 <- readableStreamBuffer + put testString enc r1 - r2 <- makeR - put testString UTF8 r2 + r2 <- readableStreamBuffer + put testString enc r2 + setEncoding r2 enc onData r1 \buf -> do - onDataString r2 UTF8 \str -> do + onDataEither r2 \(Left str) -> do assertEqual <$> Buffer.toString UTF8 buf <*> pure testString assertEqual str testString - log "ok." From 0b7be623b91611c29fbfcd42f2a2d1ef78408d4e Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Sun, 13 Dec 2015 12:59:55 +0100 Subject: [PATCH 14/18] Fix test --- test/Main.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Main.purs b/test/Main.purs index 5a9ad19..ce7938c 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -69,5 +69,5 @@ testSetEncoding = do onData r1 \buf -> do onDataEither r2 \(Left str) -> do - assertEqual <$> Buffer.toString UTF8 buf <*> pure testString + assertEqual <$> Buffer.toString enc buf <*> pure testString assertEqual str testString From e4fc67ecd16e4cda4e14f57a5f1159513bdccf98 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Sun, 13 Dec 2015 13:45:09 +0100 Subject: [PATCH 15/18] Add a piping test --- src/Node/Stream.purs | 5 ++--- test/Main.js | 8 ++++++++ test/Main.purs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Node/Stream.purs b/src/Node/Stream.purs index 44a9981..0c37173 100644 --- a/src/Node/Stream.purs +++ b/src/Node/Stream.purs @@ -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 @@ -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 + diff --git a/test/Main.js b/test/Main.js index 1419e59..9a94009 100644 --- a/test/Main.js +++ b/test/Main.js @@ -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(); +}; diff --git a/test/Main.purs b/test/Main.purs index ce7938c..9b3c95e 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -37,6 +37,9 @@ main = do log "setEncoding should not affect reading" testSetEncoding + log "test pipe" + testPipe + testString :: String testString = "üöß💡" @@ -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)) From a93824876d09978903f3904b45f60d36936b9808 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Mon, 14 Dec 2015 17:00:13 +0100 Subject: [PATCH 16/18] Remove standard IO streams --- docs/Node/Stream/StdIO.md | 23 ----------------------- src/Node/Stream/StdIO.js | 10 ---------- src/Node/Stream/StdIO.purs | 11 ----------- 3 files changed, 44 deletions(-) delete mode 100644 docs/Node/Stream/StdIO.md delete mode 100644 src/Node/Stream/StdIO.js delete mode 100644 src/Node/Stream/StdIO.purs diff --git a/docs/Node/Stream/StdIO.md b/docs/Node/Stream/StdIO.md deleted file mode 100644 index 44d0b5f..0000000 --- a/docs/Node/Stream/StdIO.md +++ /dev/null @@ -1,23 +0,0 @@ -## Module Node.Stream.StdIO - -The standard IO streams for the current process. - -#### `stdin` - -``` purescript -stdin :: forall eff. Readable () (console :: CONSOLE | eff) -``` - -#### `stdout` - -``` purescript -stdout :: forall eff. Writable () (console :: CONSOLE | eff) -``` - -#### `stderr` - -``` purescript -stderr :: forall eff. Writable () (console :: CONSOLE | eff) -``` - - diff --git a/src/Node/Stream/StdIO.js b/src/Node/Stream/StdIO.js deleted file mode 100644 index 42cbc93..0000000 --- a/src/Node/Stream/StdIO.js +++ /dev/null @@ -1,10 +0,0 @@ -/* global exports */ -/* global process */ -"use strict"; - -// module Node.Stream.StdIO - - -exports.stdin = process.stdin; -exports.stdout = process.stdout; -exports.stderr = process.stderr; diff --git a/src/Node/Stream/StdIO.purs b/src/Node/Stream/StdIO.purs deleted file mode 100644 index 857756d..0000000 --- a/src/Node/Stream/StdIO.purs +++ /dev/null @@ -1,11 +0,0 @@ --- | The standard IO streams for the current process. -module Node.Stream.StdIO where - -import Prelude -import Control.Monad.Eff.Console - -import Node.Stream - -foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) -foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) -foreign import stderr :: forall eff. Writable () (console :: CONSOLE | eff) From d8bef0c2894b9b22d96228eb47a2404cf512c50b Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Mon, 14 Dec 2015 17:13:17 +0100 Subject: [PATCH 17/18] Fix Gzip example --- example/Gzip.js | 2 ++ example/Gzip.purs | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/example/Gzip.js b/example/Gzip.js index c916751..150d693 100644 --- a/example/Gzip.js +++ b/example/Gzip.js @@ -5,3 +5,5 @@ // module Gzip exports.gzip = require('zlib').createGzip; +exports.stdout = process.stdout; +exports.stdin = process.stdin; diff --git a/example/Gzip.purs b/example/Gzip.purs index 224a9ef..d521e47 100644 --- a/example/Gzip.purs +++ b/example/Gzip.purs @@ -3,7 +3,6 @@ module Gzip where import Prelude import Node.Stream -import Node.Stream.StdIO import Control.Monad.Eff import Control.Monad.Eff.Console @@ -11,8 +10,8 @@ import Control.Monad.Eff.Console foreign import data GZIP :: ! foreign import gzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) - -foreign import +foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) +foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) main = do z <- gzip From ca16b935aa8876131f1858be9763c29f9b6d91c3 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Mon, 14 Dec 2015 17:20:41 +0100 Subject: [PATCH 18/18] Update readme example link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f283f22..fb598b4 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ A wrapper for Node's Stream API - [Module Documentation](docs/) -- [Example](test/Main.purs) +- [Example](example/Gzip.purs)