Module

Node.Stream

This module provides a low-level wrapper for the Node Stream API (v18 LTS).

#Read

data Read

A phantom type associated with readable streams.

#Write

data Write

A phantom type associated with writable streams.

#Stream

data Stream :: Row Type -> Typedata Stream t0

A stream.

The type arguments track, in order:

  • Whether reading and/or writing from/to the stream are allowed.
  • Effects associated with reading/writing from/to this stream.

#Readable

type Readable :: Row Type -> Typetype Readable r = Stream (read :: Read | r)

A readable stream.

#Writable

type Writable :: Row Type -> Typetype Writable r = Stream (write :: Write | r)

A writable stream.

#Duplex

type Duplex = Stream (read :: Read, write :: Write)

A duplex (readable and writable stream)

#toEventEmitter

toEventEmitter :: forall rw. Stream rw -> EventEmitter

#closeH

closeH :: forall rw. EventHandle0 (Stream rw)

#errorH

errorH :: forall rw. EventHandle1 (Stream rw) Error

#drainH

drainH :: forall r. EventHandle0 (Writable r)

#finishH

finishH :: forall r. EventHandle0 (Writable r)

#pipeH

pipeH :: forall r w. EventHandle1 (Writable r) (Readable w)

#unpipeH

unpipeH :: forall r w. EventHandle1 (Writable r) (Readable w)

#Chunk

data Chunk

Internal type. This should not be used by end-users.

#dataH

dataH :: forall w. EventHandle (Readable w) (Buffer -> Effect Unit) (EffectFn1 Chunk Unit)

Listen for data events, returning data in a Buffer. Note that this will fail if setEncoding has been called on the stream.

This is likely the handler you want to use for converting a Stream into a String:

let useStringCb = ...
ref <- Ref.new
stream # on dataH \buf ->
  Ref.modify_ (\ref' -> Array.snoc ref' buf) ref
stream # on endH do
  bufs <- Ref.read ref
  useStringCb $ Buffer.toString UTF8 $ Buffer.concat bufs

#dataHStr

dataHStr :: forall w. EventHandle (Readable w) (String -> Effect Unit) (EffectFn1 Chunk Unit)

Listen for data events, returning data as a String. Note that this will fail if setEncoding has NOT been called on the stream.

#dataHEither

dataHEither :: forall w. EventHandle (Readable w) (Either Buffer String -> Effect Unit) (EffectFn1 Chunk Unit)

Listen for data events, returning data in a Buffer or String. This will work regardless of whether setEncoding has been called or not.

#pauseH

pauseH :: forall w. EventHandle0 (Readable w)

#readableH

#resumeH

resumeH :: forall w. EventHandle0 (Readable w)

#endH

endH :: forall w. EventHandle0 (Readable w)

#readable

readable :: forall w. Readable w -> Effect Boolean

#readableEnded

#readableFlowing

#readableHighWaterMark

#readableLength

#resume

resume :: forall w. Readable w -> Effect Unit

Resume reading from the stream.

#pause

pause :: forall w. Readable w -> Effect Unit

Pause reading from the stream.

#isPaused

isPaused :: forall w. Readable w -> Effect Boolean

Check whether or not a stream is paused for reading.

#pipe

pipe :: forall w r. Readable w -> Writable r -> Effect Unit

Read chunks from a readable stream and write them to a writable stream.

#pipe'

pipe' :: forall w r. Readable w -> Writable r -> { end :: Boolean } -> Effect Unit

#unpipe

unpipe :: forall w r. Readable w -> Writable r -> Effect Unit

Detach a Writable stream previously attached using pipe.

#unpipeAll

unpipeAll :: forall w. Readable w -> Effect Unit

Detach all Writable streams previously attached using pipe.

#read

read :: forall w. Readable w -> Effect (Maybe Buffer)

Note: this will fail if setEncoding has been called on the stream.

#read'

read' :: forall w. Readable w -> Int -> Effect (Maybe Buffer)

Note: this will fail if setEncoding has been called on the stream.

#readString

readString :: forall w. Readable w -> Encoding -> Effect (Maybe String)

Reads the stream to get a Buffer and converts that into a String with the given encoding. Note: this will fail if setEncoding has been called on the stream. If that is the case, use readEither instead.

#readString'

readString' :: forall w. Readable w -> Int -> Encoding -> Effect (Maybe String)

Reads the given number of bytes from the stream to get a Buffer and converts that into a String with the given encoding. Note: this will fail if setEncoding has been called on the stream. If that is the case, use readEither' instead.

#readEither

readEither :: forall w. Readable w -> Effect (Maybe (Either String Buffer))

Reads a chunk from the stream. This will work whether or not setEncoding has been called on the stream.

#readEither'

readEither' :: forall w. Readable w -> Int -> Effect (Maybe (Either String Buffer))

Reads the given number of bytes from the stream. This will work whether or not setEncoding has been called on the stream.

#writeable

writeable :: forall r. Writable r -> Effect Boolean

#writeableEnded

#writeableCorked

#errored

errored :: forall rw. Stream rw -> Effect Boolean

#writeableFinished

#writeableHighWaterMark

#writeableLength

#writeableNeedDrain

#write

write :: forall r. Writable r -> Buffer -> Effect Boolean

#write'

write' :: forall r. Writable r -> Buffer -> (Maybe Error -> Effect Unit) -> Effect Boolean

#writeString

#writeString'

#cork

cork :: forall r. Writable r -> Effect Unit

Force buffering of writes.

#uncork

uncork :: forall r. Writable r -> Effect Unit

Flush buffered data.

#setEncoding

setEncoding :: forall w. Readable w -> Encoding -> Effect Unit

Set the encoding used to read chunks as strings from the stream. This function may be useful when you are passing a readable stream to some other JavaScript library, which already expects an encoding to be set.

#setDefaultEncoding

setDefaultEncoding :: forall r. Writable r -> Encoding -> Effect Unit

Set the default encoding used to write strings to the stream. This function is useful when you are passing a writable stream to some other JavaScript library, which already expects a default encoding to be set. It has no effect on the behaviour of the writeString function (because that function ensures that the encoding is always supplied explicitly).

#end

end :: forall r. Writable r -> Effect Unit

End writing data to the stream.

#end'

end' :: forall r. Writable r -> (Maybe Error -> Effect Unit) -> Effect Unit

#destroy

destroy :: forall r. Stream r -> Effect Unit

#destroy'

destroy' :: forall r. Stream r -> Error -> Effect Unit

#closed

closed :: forall r. Stream r -> Effect Boolean

#destroyed

destroyed :: forall r. Stream r -> Effect Boolean

#allowHalfOpen

#pipeline

pipeline :: forall w r. Readable w -> Array Duplex -> Writable r -> (Maybe Error -> Effect Unit) -> Effect Unit

#readableFromString

#readableFromBuffer

#newPassThrough

Modules