@@ -36,27 +36,29 @@ module Node.Stream
36
36
, readEither
37
37
, readEither'
38
38
, write
39
+ , write'
39
40
, writeString
41
+ , writeString'
40
42
, cork
41
43
, uncork
42
44
, setDefaultEncoding
43
45
, end
46
+ , end'
44
47
, destroy
45
- , destroyWithError
48
+ , destroy'
46
49
) where
47
50
48
51
import Prelude
49
52
50
53
import Data.Either (Either (..))
51
54
import Data.Maybe (Maybe (..))
52
55
import Data.Nullable (Nullable , toMaybe )
53
- import Data.Nullable as N
54
56
import Effect (Effect )
55
57
import Effect.Exception (Error , throw )
56
- import Effect.Uncurried (EffectFn1 , EffectFn2 , EffectFn3 , mkEffectFn1 , runEffectFn1 , runEffectFn2 , runEffectFn3 )
58
+ import Effect.Uncurried (EffectFn1 , EffectFn2 , EffectFn3 , EffectFn4 , mkEffectFn1 , runEffectFn1 , runEffectFn2 , runEffectFn3 , runEffectFn4 )
57
59
import Node.Buffer (Buffer )
58
60
import Node.Buffer as Buffer
59
- import Node.Encoding (Encoding )
61
+ import Node.Encoding (Encoding , encodingToNode )
60
62
import Node.EventEmitter (EventEmitter , EventHandle (..))
61
63
import Node.EventEmitter.UtilTypes (EventHandle1 , EventHandle0 )
62
64
import Unsafe.Coerce (unsafeCoerce )
@@ -235,12 +237,6 @@ readEither' r size = do
235
237
(mkEffectFn1 (pure <<< Just <<< Left ))
236
238
c
237
239
238
- foreign import setEncodingImpl
239
- :: forall w
240
- . Readable w
241
- -> String
242
- -> Effect Unit
243
-
244
240
-- | Set the encoding used to read chunks as strings from the stream. This
245
241
-- | function may be useful when you are passing a readable stream to some other
246
242
-- | JavaScript library, which already expects an encoding to be set.
@@ -252,7 +248,9 @@ setEncoding
252
248
. Readable w
253
249
-> Encoding
254
250
-> Effect Unit
255
- setEncoding r enc = setEncodingImpl r (show enc)
251
+ setEncoding r enc = runEffectFn2 setEncodingImpl r (show enc)
252
+
253
+ foreign import setEncodingImpl :: forall w . EffectFn2 (Readable w ) String Unit
256
254
257
255
closeH :: forall rw . EventHandle0 (Stream rw )
258
256
closeH = EventHandle " close" identity
@@ -285,79 +283,72 @@ endH :: forall w. EventHandle0 (Readable w)
285
283
endH = EventHandle " end" identity
286
284
287
285
-- | Resume reading from the stream.
288
- foreign import resume :: forall w . Readable w -> Effect Unit
286
+ resume :: forall w . Readable w -> Effect Unit
287
+ resume r = runEffectFn1 resumeImpl r
288
+
289
+ foreign import resumeImpl :: forall w . EffectFn1 (Readable w ) (Unit )
289
290
290
291
-- | Pause reading from the stream.
291
- foreign import pause :: forall w . Readable w -> Effect Unit
292
+ pause :: forall w . Readable w -> Effect Unit
293
+ pause r = runEffectFn1 pauseImpl r
294
+
295
+ foreign import pauseImpl :: forall w . EffectFn1 (Readable w ) (Unit )
292
296
293
297
-- | Check whether or not a stream is paused for reading.
294
- foreign import isPaused :: forall w . Readable w -> Effect Boolean
298
+ isPaused :: forall w . Readable w -> Effect Boolean
299
+ isPaused r = runEffectFn1 isPausedImpl r
300
+
301
+ foreign import isPausedImpl :: forall w . EffectFn1 (Readable w ) (Boolean )
295
302
296
303
-- | Read chunks from a readable stream and write them to a writable stream.
297
- foreign import pipe
298
- :: forall r w
299
- . Readable w
300
- -> Writable r
301
- -> Effect (Writable r )
304
+ pipe :: forall w r . Readable w -> Writable r -> Effect Unit
305
+ pipe r w = runEffectFn2 pipeImpl r w
306
+
307
+ foreign import pipeImpl :: forall w r . EffectFn2 (Readable w ) (Writable r ) (Unit )
302
308
303
309
-- | Detach a Writable stream previously attached using `pipe`.
304
- foreign import unpipe
305
- :: forall r w
306
- . Readable w
307
- -> Writable r
308
- -> Effect Unit
310
+ unpipe :: forall w r . Readable w -> Writable r -> Effect Unit
311
+ unpipe r w = runEffectFn2 unpipeImpl r w
312
+
313
+ foreign import unpipeImpl :: forall w r . EffectFn2 (Readable w ) (Writable r ) (Unit )
309
314
310
315
-- | Detach all Writable streams previously attached using `pipe`.
311
- foreign import unpipeAll
312
- :: forall w
313
- . Readable w
314
- -> Effect Unit
316
+ unpipeAll :: forall w . Readable w -> Effect Unit
317
+ unpipeAll r = runEffectFn1 unpipeAllImpl r
315
318
316
- foreign import writeImpl
317
- :: forall r
318
- . Writable r
319
- -> Buffer
320
- -> EffectFn1 (N.Nullable Error ) Unit
321
- -> Effect Boolean
319
+ foreign import unpipeAllImpl :: forall w . EffectFn1 (Readable w ) (Unit )
322
320
323
- -- | Write a Buffer to a writable stream.
324
- write
325
- :: forall r
326
- . Writable r
327
- -> Buffer
328
- -> (Maybe Error -> Effect Unit )
329
- -> Effect Boolean
330
- write w b cb = writeImpl w b $ mkEffectFn1 (cb <<< N .toMaybe)
321
+ write :: forall r . Writable r -> Buffer -> Effect Boolean
322
+ write w b = runEffectFn2 writeImpl w b
331
323
332
- foreign import writeStringImpl
333
- :: forall r
334
- . Writable r
335
- -> String
336
- -> String
337
- -> EffectFn1 (N.Nullable Error ) Unit
338
- -> Effect Boolean
324
+ foreign import writeImpl :: forall r a . EffectFn2 (Writable r ) (Buffer ) (a )
339
325
340
- -- | Write a string in the specified encoding to a writable stream.
341
- writeString
342
- :: forall r
343
- . Writable r
344
- -> Encoding
345
- -> String
346
- -> (Maybe Error -> Effect Unit )
347
- -> Effect Boolean
348
- writeString w enc s cb = writeStringImpl w (show enc) s $ mkEffectFn1 (cb <<< N .toMaybe)
326
+ write' :: forall r . Writable r -> Buffer -> (Maybe Error -> Effect Unit ) -> Effect Boolean
327
+ write' w b cb = runEffectFn3 writeCbImpl w b $ mkEffectFn1 \err -> cb (toMaybe err)
328
+
329
+ foreign import writeCbImpl :: forall r a . EffectFn3 (Writable r ) (Buffer ) (EffectFn1 (Nullable Error ) Unit ) (a )
330
+
331
+ writeString :: forall r . Writable r -> Encoding -> String -> Effect Boolean
332
+ writeString w enc str = runEffectFn3 writeStringImpl w str (encodingToNode enc)
333
+
334
+ foreign import writeStringImpl :: forall r a . EffectFn3 (Writable r ) (String ) (String ) (a )
335
+
336
+ writeString' :: forall r . Writable r -> Encoding -> String -> (Maybe Error -> Effect Unit ) -> Effect Boolean
337
+ writeString' w enc str cb = runEffectFn4 writeStringCbImpl w str (encodingToNode enc) $ mkEffectFn1 \err -> cb (toMaybe err)
338
+
339
+ foreign import writeStringCbImpl :: forall r a . EffectFn4 (Writable r ) (String ) (String ) (EffectFn1 (Nullable Error ) Unit ) (a )
349
340
350
341
-- | Force buffering of writes.
351
- foreign import cork :: forall r . Writable r -> Effect Unit
342
+ cork :: forall r . Writable r -> Effect Unit
343
+ cork s = runEffectFn1 corkImpl s
344
+
345
+ foreign import corkImpl :: forall r . EffectFn1 (Writable r ) (Unit )
352
346
353
347
-- | Flush buffered data.
354
- foreign import uncork :: forall r . Writable r -> Effect Unit
348
+ uncork :: forall r . Writable r -> Effect Unit
349
+ uncork w = runEffectFn1 uncorkImpl w
355
350
356
- foreign import setDefaultEncodingImpl
357
- :: forall r
358
- . Writable r
359
- -> String
360
- -> Effect Unit
351
+ foreign import uncorkImpl :: forall r . EffectFn1 (Writable r ) (Unit )
361
352
362
353
-- | Set the default encoding used to write strings to the stream. This function
363
354
-- | is useful when you are passing a writable stream to some other JavaScript
@@ -369,35 +360,28 @@ setDefaultEncoding
369
360
. Writable r
370
361
-> Encoding
371
362
-> Effect Unit
372
- setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc)
363
+ setDefaultEncoding r enc = runEffectFn2 setDefaultEncodingImpl r (show enc)
373
364
374
- foreign import endImpl
375
- :: forall r
376
- . Writable r
377
- -> EffectFn1 (N.Nullable Error ) Unit
378
- -> Effect Unit
365
+ foreign import setDefaultEncodingImpl :: forall r . EffectFn2 (Writable r ) String Unit
379
366
380
367
-- | End writing data to the stream.
381
- end
382
- :: forall r
383
- . Writable r
384
- -> (Maybe Error -> Effect Unit )
385
- -> Effect Unit
386
- end w cb = endImpl w $ mkEffectFn1 (cb <<< N .toMaybe)
368
+ end :: forall r . Writable r -> Effect Unit
369
+ end w = runEffectFn1 endImpl w
387
370
388
- -- | Destroy the stream. It will release any internal resources.
389
- --
390
- -- Added in node 8.0.
391
- foreign import destroy
392
- :: forall r
393
- . Stream r
394
- -> Effect Unit
371
+ foreign import endImpl :: forall r . EffectFn1 (Writable r ) (Unit )
372
+
373
+ end' :: forall r . Writable r -> (Maybe Error -> Effect Unit ) -> Effect Unit
374
+ end' w cb = runEffectFn2 endCbImpl w $ mkEffectFn1 \err -> cb (toMaybe err)
375
+
376
+ foreign import endCbImpl :: forall r . EffectFn2 (Writable r ) (EffectFn1 (Nullable Error ) Unit ) (Unit )
377
+
378
+ destroy :: forall r . Stream r -> Effect Unit
379
+ destroy w = runEffectFn1 destroyImpl w
380
+
381
+ foreign import destroyImpl :: forall r . EffectFn1 (Stream r ) (Unit )
382
+
383
+ destroy' :: forall r . Stream r -> Error -> Effect Unit
384
+ destroy' w e = runEffectFn2 destroyErrorImpl w e
385
+
386
+ foreign import destroyErrorImpl :: forall r . EffectFn2 (Stream r ) (Error ) Unit
395
387
396
- -- | Destroy the stream and emit 'error'.
397
- --
398
- -- Added in node 8.0.
399
- foreign import destroyWithError
400
- :: forall r
401
- . Stream r
402
- -> Error
403
- -> Effect Unit
0 commit comments