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.

#StreamSource

data Stream :: # Type -> # 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.

#ReadSource

data Read

A phantom type associated with readable streams.

#ReadableSource

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

A readable stream.

#WriteSource

data Write

A phantom type associated with writable streams.

#WritableSource

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

A writable stream.

#DuplexSource

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

A duplex (readable and writable stream)

#onDataSource

onData :: forall w eff. Readable w (err :: EXCEPTION | eff) -> (Buffer -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: 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.

#readSource

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

#readStringSource

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

#readEitherSource

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

#onDataStringSource

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

#onDataEitherSource

onDataEither :: forall r eff. Readable r (err :: EXCEPTION | eff) -> (Either String Buffer -> Eff (err :: EXCEPTION | eff) Unit) -> Eff (err :: 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.

#setEncodingSource

setEncoding :: forall w eff. 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.

#onReadableSource

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

Listen for readable events.

#onEndSource

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

Listen for end events.

#onCloseSource

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

Listen for close events.

#onErrorSource

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

Listen for error events.

#resumeSource

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

Resume reading from the stream.

#pauseSource

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

Pause reading from the stream.

#isPausedSource

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

Check whether or not a stream is paused for reading.

#pipeSource

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

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

#writeSource

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

Write a Buffer to a writable stream.

#writeStringSource

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

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

#corkSource

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

Force buffering of writes.

#uncorkSource

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

Flush buffered data.

#setDefaultEncodingSource

setDefaultEncoding :: forall r eff. 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).

#endSource

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

End writing data to the stream.

Modules
Node.Stream