@@ -36,9 +36,8 @@ module Node.Stream
36
36
37
37
import Prelude
38
38
39
- import Control.Monad.Eff (Eff , kind Effect )
40
- import Control.Monad.Eff.Exception (throw , EXCEPTION (), Error ())
41
- import Control.Monad.Eff.Unsafe (unsafeCoerceEff )
39
+ import Effect (Effect )
40
+ import Effect.Exception (throw , Error ())
42
41
import Data.Either (Either (..))
43
42
import Data.Maybe (Maybe (..), fromMaybe )
44
43
import Node.Buffer (Buffer ())
@@ -51,7 +50,7 @@ import Node.Encoding (Encoding)
51
50
-- |
52
51
-- | - Whether reading and/or writing from/to the stream are allowed.
53
52
-- | - Effects associated with reading/writing from/to this stream.
54
- foreign import data Stream :: # Type -> # Effect -> Type
53
+ foreign import data Stream :: # Type -> Type
55
54
56
55
-- | A phantom type associated with _readable streams_.
57
56
data Read
@@ -84,10 +83,10 @@ readChunk = readChunkImpl Left Right
84
83
-- | Listen for `data` events, returning data in a Buffer. Note that this will fail
85
84
-- | if `setEncoding` has been called on the stream.
86
85
onData
87
- :: forall w eff
88
- . Readable w ( exception :: EXCEPTION | eff )
89
- -> (Buffer -> Eff ( exception :: EXCEPTION | eff ) Unit )
90
- -> Eff ( exception :: EXCEPTION | eff ) Unit
86
+ :: forall w
87
+ . Readable w
88
+ -> (Buffer -> Effect Unit )
89
+ -> Effect Unit
91
90
onData r cb =
92
91
onDataEither r (cb <=< fromEither)
93
92
where
@@ -99,10 +98,10 @@ onData r cb =
99
98
pure buf
100
99
101
100
read
102
- :: forall w eff
103
- . Readable w ( exception :: EXCEPTION | eff )
101
+ :: forall w
102
+ . Readable w
104
103
-> Maybe Int
105
- -> Eff ( exception :: EXCEPTION | eff ) (Maybe Buffer )
104
+ -> Effect (Maybe Buffer )
106
105
read r size = do
107
106
v <- readEither r size
108
107
case v of
@@ -111,67 +110,67 @@ read r size = do
111
110
Just (Right b) -> pure (Just b)
112
111
113
112
readString
114
- :: forall w eff
115
- . Readable w ( exception :: EXCEPTION | eff )
113
+ :: forall w
114
+ . Readable w
116
115
-> Maybe Int
117
116
-> Encoding
118
- -> Eff ( exception :: EXCEPTION | eff ) (Maybe String )
117
+ -> Effect (Maybe String )
119
118
readString r size enc = do
120
119
v <- readEither r size
121
120
case v of
122
121
Nothing -> pure Nothing
123
122
Just (Left _) -> throw " Stream encoding should not be set"
124
- Just (Right buf) -> Just <$> (unsafeCoerceEff $ Buffer .toString enc buf)
123
+ Just (Right buf) -> Just <$> Buffer .toString enc buf
125
124
126
125
readEither
127
- :: forall w eff
128
- . Readable w eff
126
+ :: forall w
127
+ . Readable w
129
128
-> Maybe Int
130
- -> Eff eff (Maybe (Either String Buffer ))
129
+ -> Effect (Maybe (Either String Buffer ))
131
130
readEither r size = readImpl readChunk Nothing Just r (fromMaybe undefined size)
132
131
133
132
foreign import readImpl
134
- :: forall r eff
133
+ :: forall r
135
134
. (Chunk -> Either String Buffer )
136
135
-> (forall a . Maybe a )
137
136
-> (forall a . a -> Maybe a )
138
- -> Readable r eff
137
+ -> Readable r
139
138
-> Int
140
- -> Eff eff (Maybe (Either String Buffer ))
139
+ -> Effect (Maybe (Either String Buffer ))
141
140
142
141
-- | Listen for `data` events, returning data in a String, which will be
143
142
-- | decoded using the given encoding. Note that this will fail if `setEncoding`
144
143
-- | has been called on the stream.
145
144
onDataString
146
- :: forall w eff
147
- . Readable w ( exception :: EXCEPTION | eff )
145
+ :: forall w
146
+ . Readable w
148
147
-> Encoding
149
- -> (String -> Eff ( exception :: EXCEPTION | eff ) Unit )
150
- -> Eff ( exception :: EXCEPTION | eff ) Unit
151
- onDataString r enc cb = onData r (cb <=< unsafeCoerceEff <<< Buffer .toString enc)
148
+ -> (String -> Effect Unit )
149
+ -> Effect Unit
150
+ onDataString r enc cb = onData r (cb <=< Buffer .toString enc)
152
151
153
152
-- | Listen for `data` events, returning data in an `Either String Buffer`. This
154
153
-- | function is provided for the (hopefully rare) case that `setEncoding` has
155
154
-- | been called on the stream.
156
155
onDataEither
157
- :: forall r eff
158
- . Readable r ( exception :: EXCEPTION | eff )
159
- -> (Either String Buffer -> Eff ( exception :: EXCEPTION | eff ) Unit )
160
- -> Eff ( exception :: EXCEPTION | eff ) Unit
156
+ :: forall r
157
+ . Readable r
158
+ -> (Either String Buffer -> Effect Unit )
159
+ -> Effect Unit
161
160
onDataEither r cb = onDataEitherImpl readChunk r cb
162
161
163
162
foreign import onDataEitherImpl
164
- :: forall r eff
163
+ :: forall r
165
164
. (Chunk -> Either String Buffer )
166
- -> Readable r eff
167
- -> (Either String Buffer -> Eff eff Unit )
168
- -> Eff eff Unit
165
+ -> Readable r
166
+ -> (Either String Buffer -> Effect Unit )
167
+ -> Effect Unit
169
168
170
169
foreign import setEncodingImpl
171
- :: forall w eff
172
- . Readable w eff
170
+ :: forall w
171
+ . Readable w
173
172
-> String
174
- -> Eff eff Unit
173
+ -> Effect Unit
175
174
176
175
-- | Set the encoding used to read chunks as strings from the stream. This
177
176
-- | function may be useful when you are passing a readable stream to some other
@@ -180,146 +179,146 @@ foreign import setEncodingImpl
180
179
-- | Where possible, you should try to use `onDataString` instead of this
181
180
-- | function.
182
181
setEncoding
183
- :: forall w eff
184
- . Readable w eff
182
+ :: forall w
183
+ . Readable w
185
184
-> Encoding
186
- -> Eff eff Unit
185
+ -> Effect Unit
187
186
setEncoding r enc = setEncodingImpl r (show enc)
188
187
189
188
-- | Listen for `readable` events.
190
189
foreign import onReadable
191
- :: forall w eff
192
- . Readable w eff
193
- -> Eff eff Unit
194
- -> Eff eff Unit
190
+ :: forall w
191
+ . Readable w
192
+ -> Effect Unit
193
+ -> Effect Unit
195
194
196
195
-- | Listen for `end` events.
197
196
foreign import onEnd
198
- :: forall w eff
199
- . Readable w eff
200
- -> Eff eff Unit
201
- -> Eff eff Unit
197
+ :: forall w
198
+ . Readable w
199
+ -> Effect Unit
200
+ -> Effect Unit
202
201
203
202
-- | Listen for `finish` events.
204
203
foreign import onFinish
205
- :: forall w eff
206
- . Writable w eff
207
- -> Eff eff Unit
208
- -> Eff eff Unit
204
+ :: forall w
205
+ . Writable w
206
+ -> Effect Unit
207
+ -> Effect Unit
209
208
210
209
-- | Listen for `close` events.
211
210
foreign import onClose
212
- :: forall w eff
213
- . Stream w eff
214
- -> Eff eff Unit
215
- -> Eff eff Unit
211
+ :: forall w
212
+ . Stream w
213
+ -> Effect Unit
214
+ -> Effect Unit
216
215
217
216
-- | Listen for `error` events.
218
217
foreign import onError
219
- :: forall w eff
220
- . Stream w eff
221
- -> (Error -> Eff eff Unit )
222
- -> Eff eff Unit
218
+ :: forall w
219
+ . Stream w
220
+ -> (Error -> Effect Unit )
221
+ -> Effect Unit
223
222
224
223
-- | Resume reading from the stream.
225
- foreign import resume :: forall w eff . Readable w eff -> Eff eff Unit
224
+ foreign import resume :: forall w . Readable w -> Effect Unit
226
225
227
226
-- | Pause reading from the stream.
228
- foreign import pause :: forall w eff . Readable w eff -> Eff eff Unit
227
+ foreign import pause :: forall w . Readable w -> Effect Unit
229
228
230
229
-- | Check whether or not a stream is paused for reading.
231
- foreign import isPaused :: forall w eff . Readable w eff -> Eff eff Boolean
230
+ foreign import isPaused :: forall w . Readable w -> Effect Boolean
232
231
233
232
-- | Read chunks from a readable stream and write them to a writable stream.
234
233
foreign import pipe
235
- :: forall r w eff
236
- . Readable w eff
237
- -> Writable r eff
238
- -> Eff eff (Writable r eff )
234
+ :: forall r w
235
+ . Readable w
236
+ -> Writable r
237
+ -> Effect (Writable r )
239
238
240
239
-- | Detach a Writable stream previously attached using `pipe`.
241
240
foreign import unpipe
242
- :: forall r w eff
243
- . Readable w eff
244
- -> Writable r eff
245
- -> Eff eff Unit
241
+ :: forall r w
242
+ . Readable w
243
+ -> Writable r
244
+ -> Effect Unit
246
245
247
246
-- | Detach all Writable streams previously attached using `pipe`.
248
247
foreign import unpipeAll
249
- :: forall w eff
250
- . Readable w eff
251
- -> Eff eff Unit
248
+ :: forall w
249
+ . Readable w
250
+ -> Effect Unit
252
251
253
252
-- | Write a Buffer to a writable stream.
254
253
foreign import write
255
- :: forall r eff
256
- . Writable r eff
254
+ :: forall r
255
+ . Writable r
257
256
-> Buffer
258
- -> Eff eff Unit
259
- -> Eff eff Boolean
257
+ -> Effect Unit
258
+ -> Effect Boolean
260
259
261
260
foreign import writeStringImpl
262
- :: forall r eff
263
- . Writable r eff
261
+ :: forall r
262
+ . Writable r
264
263
-> String
265
264
-> String
266
- -> Eff eff Unit
267
- -> Eff eff Boolean
265
+ -> Effect Unit
266
+ -> Effect Boolean
268
267
269
268
-- | Write a string in the specified encoding to a writable stream.
270
269
writeString
271
- :: forall r eff
272
- . Writable r eff
270
+ :: forall r
271
+ . Writable r
273
272
-> Encoding
274
273
-> String
275
- -> Eff eff Unit
276
- -> Eff eff Boolean
274
+ -> Effect Unit
275
+ -> Effect Boolean
277
276
writeString w enc = writeStringImpl w (show enc)
278
277
279
278
-- | Force buffering of writes.
280
- foreign import cork :: forall r eff . Writable r eff -> Eff eff Unit
279
+ foreign import cork :: forall r . Writable r -> Effect Unit
281
280
282
281
-- | Flush buffered data.
283
- foreign import uncork :: forall r eff . Writable r eff -> Eff eff Unit
282
+ foreign import uncork :: forall r . Writable r -> Effect Unit
284
283
285
284
foreign import setDefaultEncodingImpl
286
- :: forall r eff
287
- . Writable r eff
285
+ :: forall r
286
+ . Writable r
288
287
-> String
289
- -> Eff eff Unit
288
+ -> Effect Unit
290
289
291
290
-- | Set the default encoding used to write strings to the stream. This function
292
291
-- | is useful when you are passing a writable stream to some other JavaScript
293
292
-- | library, which already expects a default encoding to be set. It has no
294
293
-- | effect on the behaviour of the `writeString` function (because that
295
294
-- | function ensures that the encoding is always supplied explicitly).
296
295
setDefaultEncoding
297
- :: forall r eff
298
- . Writable r eff
296
+ :: forall r
297
+ . Writable r
299
298
-> Encoding
300
- -> Eff eff Unit
299
+ -> Effect Unit
301
300
setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc)
302
301
303
302
-- | End writing data to the stream.
304
303
foreign import end
305
- :: forall r eff
306
- . Writable r eff
307
- -> Eff eff Unit
308
- -> Eff eff Unit
304
+ :: forall r
305
+ . Writable r
306
+ -> Effect Unit
307
+ -> Effect Unit
309
308
310
309
-- | Destroy the stream. It will release any internal resources.
311
310
--
312
311
-- Added in node 8.0.
313
312
foreign import destroy
314
- :: forall r eff
315
- . Stream r eff
316
- -> Eff eff Unit
313
+ :: forall r
314
+ . Stream r
315
+ -> Effect Unit
317
316
318
317
-- | Destroy the stream and emit 'error'.
319
318
--
320
319
-- Added in node 8.0.
321
320
foreign import destroyWithError
322
- :: forall r eff
323
- . Stream r eff
321
+ :: forall r
322
+ . Stream r
324
323
-> Error
325
- -> Eff eff Unit
324
+ -> Effect Unit
0 commit comments