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 -> Row Effect -> 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 eff w. Readable w (exception :: EXCEPTION | eff) -> (Buffer -> Eff (exception :: EXCEPTION | eff) Unit) -> Eff (exception :: EXCEPTION | eff) Unit

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

#read Source

read :: forall eff w. Readable w (exception :: EXCEPTION | eff) -> Maybe Int -> Eff (exception :: EXCEPTION | eff) (Maybe Buffer)

#readString Source

readString :: forall eff w. Readable w (exception :: EXCEPTION | eff) -> Maybe Int -> Encoding -> Eff (exception :: EXCEPTION | eff) (Maybe String)

#readEither Source

readEither :: forall eff w. Readable w eff -> Maybe Int -> Eff eff (Maybe (Either String Buffer))

#onDataString Source

onDataString :: forall eff w. Readable w (exception :: EXCEPTION | eff) -> Encoding -> (String -> Eff (exception :: EXCEPTION | eff) Unit) -> Eff (exception :: EXCEPTION | eff) 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 eff r. Readable r (exception :: EXCEPTION | eff) -> (Either String Buffer -> Eff (exception :: EXCEPTION | eff) Unit) -> Eff (exception :: EXCEPTION | eff) 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 eff w. Readable w eff -> Encoding -> Eff eff 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 eff w. Readable w eff -> Eff eff Unit -> Eff eff Unit

Listen for readable events.

#onEnd Source

onEnd :: forall eff w. Readable w eff -> Eff eff Unit -> Eff eff Unit

Listen for end events.

#onClose Source

onClose :: forall eff w. Readable w eff -> Eff eff Unit -> Eff eff Unit

Listen for close events.

#onError Source

onError :: forall eff w. Readable w eff -> (Error -> Eff eff Unit) -> Eff eff Unit

Listen for error events.

#resume Source

resume :: forall eff w. Readable w eff -> Eff eff Unit

Resume reading from the stream.

#pause Source

pause :: forall eff w. Readable w eff -> Eff eff Unit

Pause reading from the stream.

#isPaused Source

isPaused :: forall eff w. Readable w eff -> Eff eff Boolean

Check whether or not a stream is paused for reading.

#pipe Source

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

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

#write Source

write :: forall eff r. Writable r eff -> Buffer -> Eff eff Unit -> Eff eff Boolean

Write a Buffer to a writable stream.

#writeString Source

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

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

#cork Source

cork :: forall eff r. Writable r eff -> Eff eff Unit

Force buffering of writes.

#uncork Source

uncork :: forall eff r. Writable r eff -> Eff eff Unit

Flush buffered data.

#setDefaultEncoding Source

setDefaultEncoding :: forall eff r. Writable r eff -> Encoding -> Eff eff 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 eff r. Writable r eff -> Eff eff Unit -> Eff eff Unit

End writing data to the stream.

Modules
Node.Stream