@@ -36,27 +36,29 @@ module Node.Stream
3636 , readEither
3737 , readEither'
3838 , write
39+ , write'
3940 , writeString
41+ , writeString'
4042 , cork
4143 , uncork
4244 , setDefaultEncoding
4345 , end
46+ , end'
4447 , destroy
45- , destroyWithError
48+ , destroy'
4649 ) where
4750
4851import Prelude
4952
5053import Data.Either (Either (..))
5154import Data.Maybe (Maybe (..))
5255import Data.Nullable (Nullable , toMaybe )
53- import Data.Nullable as N
5456import Effect (Effect )
5557import 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 )
5759import Node.Buffer (Buffer )
5860import Node.Buffer as Buffer
59- import Node.Encoding (Encoding )
61+ import Node.Encoding (Encoding , encodingToNode )
6062import Node.EventEmitter (EventEmitter , EventHandle (..))
6163import Node.EventEmitter.UtilTypes (EventHandle1 , EventHandle0 )
6264import Unsafe.Coerce (unsafeCoerce )
@@ -235,12 +237,6 @@ readEither' r size = do
235237 (mkEffectFn1 (pure <<< Just <<< Left ))
236238 c
237239
238- foreign import setEncodingImpl
239- :: forall w
240- . Readable w
241- -> String
242- -> Effect Unit
243-
244240-- | Set the encoding used to read chunks as strings from the stream. This
245241-- | function may be useful when you are passing a readable stream to some other
246242-- | JavaScript library, which already expects an encoding to be set.
@@ -252,7 +248,9 @@ setEncoding
252248 . Readable w
253249 -> Encoding
254250 -> 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
256254
257255closeH :: forall rw . EventHandle0 (Stream rw )
258256closeH = EventHandle " close" identity
@@ -285,79 +283,72 @@ endH :: forall w. EventHandle0 (Readable w)
285283endH = EventHandle " end" identity
286284
287285-- | 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 )
289290
290291-- | 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 )
292296
293297-- | 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 )
295302
296303-- | 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 )
302308
303309-- | 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 )
309314
310315-- | 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
315318
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 )
322320
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
331323
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 )
339325
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 )
349340
350341-- | 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 )
352346
353347-- | 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
355350
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 )
361352
362353-- | Set the default encoding used to write strings to the stream. This function
363354-- | is useful when you are passing a writable stream to some other JavaScript
@@ -369,35 +360,28 @@ setDefaultEncoding
369360 . Writable r
370361 -> Encoding
371362 -> Effect Unit
372- setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc)
363+ setDefaultEncoding r enc = runEffectFn2 setDefaultEncodingImpl r (show enc)
373364
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
379366
380367-- | 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
387370
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
395387
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