@@ -5,7 +5,7 @@ This module provides a low-level wrapper for the Node Stream API.
5
5
#### ` Stream `
6
6
7
7
``` purescript
8
- data Stream :: # * -> # ! -> * -> *
8
+ data Stream :: # * -> # ! -> *
9
9
```
10
10
11
11
A stream.
@@ -14,7 +14,6 @@ The type arguments track, in order:
14
14
15
15
- Whether reading and/or writing from/to the stream are allowed.
16
16
- 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 ` ).
18
17
19
18
#### ` Read `
20
19
@@ -56,122 +55,152 @@ type Duplex = Stream (read :: Read, write :: Write)
56
55
57
56
A duplex (readable _ and_ writable stream)
58
57
59
- #### ` setEncoding `
58
+ #### ` onData `
60
59
61
60
``` 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
63
62
```
64
63
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.
66
66
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 `
68
78
69
79
``` 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
71
81
```
72
82
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.
74
99
75
100
#### ` onEnd `
76
101
77
102
``` 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
79
104
```
80
105
81
106
Listen for ` end ` events.
82
107
83
108
#### ` onClose `
84
109
85
110
``` 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
87
112
```
88
113
89
114
Listen for ` close ` events.
90
115
91
116
#### ` onError `
92
117
93
118
``` 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
95
120
```
96
121
97
122
Listen for ` error ` events.
98
123
99
124
#### ` resume `
100
125
101
126
``` 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
103
128
```
104
129
105
130
Resume reading from the stream.
106
131
107
132
#### ` pause `
108
133
109
134
``` 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
111
136
```
112
137
113
138
Pause reading from the stream.
114
139
115
140
#### ` isPaused `
116
141
117
142
``` 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
119
144
```
120
145
121
146
Check whether or not a stream is paused for reading.
122
147
123
148
#### ` pipe `
124
149
125
150
``` 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)
127
152
```
128
153
129
154
Read chunks from a readable stream and write them to a writable stream.
130
155
131
156
#### ` write `
132
157
133
158
``` 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
135
160
```
136
161
137
- Write a chunk to a writable stream.
162
+ Write a Buffer to a writable stream.
138
163
139
164
#### ` writeString `
140
165
141
166
``` 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
143
168
```
144
169
145
170
Write a string in the specified encoding to a writable stream.
146
171
147
172
#### ` cork `
148
173
149
174
``` 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
151
176
```
152
177
153
178
Force buffering of writes.
154
179
155
180
#### ` uncork `
156
181
157
182
``` 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
159
184
```
160
185
161
186
Flush buffered data.
162
187
163
188
#### ` setDefaultEncoding `
164
189
165
190
``` 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
167
192
```
168
193
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).
170
199
171
200
#### ` end `
172
201
173
202
``` 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
175
204
```
176
205
177
206
End writing data to the stream.
0 commit comments