Module

Node.Stream

Package
purescript-node-streams
Repository
purescript-node/purescript-node-streams

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

#Stream Source

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 Source

data Read

A phantom type associated with readable streams.

#Readable Source

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

A readable stream.

#Write Source

data Write

A phantom type associated with writable streams.

#Writable Source

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

A writable stream.

#Duplex Source

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

A duplex (readable and writable stream)

#onData Source

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 Source

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 Source

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 Source

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 Source

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

Listen for readable events.

#onEnd Source

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

Listen for end events.

#onFinish Source

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

Listen for finish events.

#onClose Source

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

Listen for close events.

#onError Source

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

Listen for error events.

#resume Source

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

Resume reading from the stream.

#pause Source

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

Pause reading from the stream.

#isPaused Source

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

Check whether or not a stream is paused for reading.

#pipe Source

pipe :: forall w r. Readable w -> Writable r -> Effect (Writable r)

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

#unpipe Source

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

Detach a Writable stream previously attached using pipe.

#unpipeAll Source

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

Detach all Writable streams previously attached using pipe.

#read Source

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

#readString Source

#readEither Source

#write Source

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

Write a Buffer to a writable stream.

#writeString Source

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

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

#cork Source

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

Force buffering of writes.

#uncork Source

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

Flush buffered data.

#setDefaultEncoding Source

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 Source

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

End writing data to the stream.

#destroy Source

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

Destroy the stream. It will release any internal resources.

Modules
Node.Stream