Module

Node.Stream

This module provides a low-level wrapper for the Node Stream API.

#Stream

data Stream :: Row Type -> Type

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.

#Read

data Read

A phantom type associated with readable streams.

#Readable

type Readable r = Stream (read :: Read | r)

A readable stream.

#Write

data Write

A phantom type associated with writable streams.

#Writable

type Writable r = Stream (write :: Write | r)

A writable stream.

#Duplex

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

A duplex (readable and writable stream)

#onData

onData :: forall w. Readable w -> (Buffer -> Effect Unit) -> Effect Unit

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

#onDataString

onDataString :: forall w. Readable w -> Encoding -> (String -> Effect Unit) -> Effect Unit

Listen for data events, returning data in a String, which will be decoded using the given encoding. Note that this will fail if setEncoding has been called on the stream.

#onDataEither

onDataEither :: forall r. Readable r -> (Either String Buffer -> Effect Unit) -> Effect Unit

Listen for data events, returning data in an Either String Buffer. This function is provided for the (hopefully rare) case that setEncoding has been called on the stream.

#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.

Where possible, you should try to use onDataString instead of this function.

#onReadable

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

Listen for readable events.

#onEnd

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

Listen for end events.

#onFinish

onFinish :: forall w. Writable w -> Effect Unit -> Effect Unit

Listen for finish events.

#onClose

onClose :: forall w. Stream w -> Effect Unit -> Effect Unit

Listen for close events.

#onError

onError :: forall w. Stream w -> (Error -> Effect Unit) -> Effect Unit

Listen for error events.

#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 r w. Readable w -> Writable r -> Effect (Writable r)

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

#unpipe

unpipe :: forall r w. 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 -> Maybe Int -> Effect (Maybe Buffer)

#readString

#readEither

#write

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

Write a Buffer to a writable stream.

#writeString

writeString :: forall r. Writable r -> Encoding -> String -> Effect Unit -> Effect Boolean

Write a string in the specified encoding to a writable stream.

#cork

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

Force buffering of writes.

#uncork

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

Flush buffered data.

#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 -> Effect Unit

End writing data to the stream.

#destroy

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

Destroy the stream. It will release any internal resources.

Modules