@@ -5,7 +5,7 @@ This module provides a low-level wrapper for the Node Stream API.
55#### ` Stream `
66
77``` purescript
8- data Stream :: # * -> # ! -> * -> *
8+ data Stream :: # * -> # ! -> *
99```
1010
1111A stream.
@@ -14,7 +14,6 @@ The type arguments track, in order:
1414
1515- Whether reading and/or writing from/to the stream are allowed.
1616- Effects associated with reading/writing from/to this stream.
17- - The type of chunks which will be read from/written to this stream (` String ` or ` Buffer ` ).
1817
1918#### ` Read `
2019
@@ -56,122 +55,152 @@ type Duplex = Stream (read :: Read, write :: Write)
5655
5756A duplex (readable _ and_ writable stream)
5857
59- #### ` setEncoding `
58+ #### ` onData `
6059
6160``` purescript
62- setEncoding :: forall w eff. Readable w eff String -> Encoding -> Eff eff Unit
61+ onData :: forall w eff. Readable w (err :: EXCEPTION | eff) -> (Buffer -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: EXCEPTION | eff) Unit
6362```
6463
65- Set the encoding used to read chunks from the stream.
64+ Listen for ` data ` events, returning data in a Buffer. Note that this will fail
65+ if ` setEncoding ` has been called on the stream.
6666
67- #### ` onData `
67+ #### ` onDataString `
68+
69+ ``` purescript
70+ onDataString :: forall w eff. Readable w (err :: EXCEPTION | eff) -> Encoding -> (String -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: EXCEPTION | eff) Unit
71+ ```
72+
73+ Listen for ` data ` events, returning data in a String, which will be
74+ decoded using the given encoding. Note that this will fail if ` setEncoding `
75+ has been called on the stream.
76+
77+ #### ` onDataEither `
6878
6979``` purescript
70- onData :: forall w eff a . Readable w eff a -> (a -> Eff eff Unit) -> Eff eff Unit
80+ onDataEither :: forall w eff. Readable w eff -> (Either String Buffer -> Eff eff Unit) -> Eff eff Unit
7181```
7282
73- Listen for ` data ` events.
83+ Listen for ` data ` events, returning data in an ` Either String Buffer ` . This
84+ function is provided for the (hopefully rare) case that ` setEncoding ` has
85+ been called on the stream.
86+
87+ #### ` setEncoding `
88+
89+ ``` purescript
90+ setEncoding :: forall w eff. Readable w eff -> Encoding -> Eff eff Unit
91+ ```
92+
93+ Set the encoding used to read chunks as strings from the stream. This
94+ function may be useful when you are passing a readable stream to some other
95+ JavaScript library, which already expects an encoding to be set.
96+
97+ Where possible, you should try to use ` onDataString ` instead of this
98+ function.
7499
75100#### ` onEnd `
76101
77102``` purescript
78- onEnd :: forall w eff a . Readable w eff a -> Eff eff Unit -> Eff eff Unit
103+ onEnd :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit
79104```
80105
81106Listen for ` end ` events.
82107
83108#### ` onClose `
84109
85110``` purescript
86- onClose :: forall w eff a . Readable w eff a -> Eff eff Unit -> Eff eff Unit
111+ onClose :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit
87112```
88113
89114Listen for ` close ` events.
90115
91116#### ` onError `
92117
93118``` purescript
94- onError :: forall w eff a . Readable w eff a -> Eff eff Unit -> Eff eff Unit
119+ onError :: forall w eff. Readable w eff -> Eff eff Unit -> Eff eff Unit
95120```
96121
97122Listen for ` error ` events.
98123
99124#### ` resume `
100125
101126``` purescript
102- resume :: forall w eff a . Readable w eff a -> Eff eff Unit
127+ resume :: forall w eff. Readable w eff -> Eff eff Unit
103128```
104129
105130Resume reading from the stream.
106131
107132#### ` pause `
108133
109134``` purescript
110- pause :: forall w eff a . Readable w eff a -> Eff eff Unit
135+ pause :: forall w eff. Readable w eff -> Eff eff Unit
111136```
112137
113138Pause reading from the stream.
114139
115140#### ` isPaused `
116141
117142``` purescript
118- isPaused :: forall w eff a . Readable w eff a -> Eff eff Boolean
143+ isPaused :: forall w eff. Readable w eff -> Eff eff Boolean
119144```
120145
121146Check whether or not a stream is paused for reading.
122147
123148#### ` pipe `
124149
125150``` purescript
126- pipe :: forall r w eff a . Readable w eff a -> Writable r eff a -> Eff eff (Writable r eff a )
151+ pipe :: forall r w eff. Readable w eff -> Writable r eff -> Eff eff (Writable r eff)
127152```
128153
129154Read chunks from a readable stream and write them to a writable stream.
130155
131156#### ` write `
132157
133158``` purescript
134- write :: forall r eff a . Writable r eff String -> a -> Eff eff Unit -> Eff eff Boolean
159+ write :: forall r eff. Writable r eff -> Buffer -> Eff eff Unit -> Eff eff Boolean
135160```
136161
137- Write a chunk to a writable stream.
162+ Write a Buffer to a writable stream.
138163
139164#### ` writeString `
140165
141166``` purescript
142- writeString :: forall r eff. Writable r eff String -> Encoding -> String -> Eff eff Unit -> Eff eff Boolean
167+ writeString :: forall r eff. Writable r eff -> Encoding -> String -> Eff eff Unit -> Eff eff Boolean
143168```
144169
145170Write a string in the specified encoding to a writable stream.
146171
147172#### ` cork `
148173
149174``` purescript
150- cork :: forall r eff a . Writable r eff a -> Eff eff Unit
175+ cork :: forall r eff. Writable r eff -> Eff eff Unit
151176```
152177
153178Force buffering of writes.
154179
155180#### ` uncork `
156181
157182``` purescript
158- uncork :: forall r eff a . Writable r eff a -> Eff eff Unit
183+ uncork :: forall r eff. Writable r eff -> Eff eff Unit
159184```
160185
161186Flush buffered data.
162187
163188#### ` setDefaultEncoding `
164189
165190``` purescript
166- setDefaultEncoding :: forall r eff. Writable r eff String -> Encoding -> Eff eff Unit
191+ setDefaultEncoding :: forall r eff. Writable r eff -> Encoding -> Eff eff Unit
167192```
168193
169- Set the default encoding used to write chunks to the stream.
194+ Set the default encoding used to write strings to the stream. This function
195+ is useful when you are passing a writable stream to some other JavaScript
196+ library, which already expects a default encoding to be set. It has no
197+ effect on the behaviour of the ` writeString ` function (because that
198+ function ensures that the encoding is always supplied explicitly).
170199
171200#### ` end `
172201
173202``` purescript
174- end :: forall r eff a . Writable r eff a -> Eff eff Unit -> Eff eff Unit
203+ end :: forall r eff. Writable r eff -> Eff eff Unit -> Eff eff Unit
175204```
176205
177206End writing data to the stream.
0 commit comments