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 (v18 LTS).

#Read Source

data Read

A phantom type associated with readable streams.

#Write Source

data Write

A phantom type associated with writable streams.

#Stream Source

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 Source

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

A readable stream.

#Writable Source

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

A writable stream.

#Duplex Source

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

A duplex (readable and writable stream)

#toEventEmitter Source

toEventEmitter :: forall rw. Stream rw -> EventEmitter

#closeH Source

closeH :: forall rw. EventHandle0 (Stream rw)

#errorH Source

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

#drainH Source

drainH :: forall r. EventHandle0 (Writable r)

#finishH Source

finishH :: forall r. EventHandle0 (Writable r)

#pipeH Source

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

#unpipeH Source

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

#Chunk Source

data Chunk

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

#dataH Source

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 Source

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 Source

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 Source

pauseH :: forall w. EventHandle0 (Readable w)

#readableH Source

#resumeH Source

resumeH :: forall w. EventHandle0 (Readable w)

#endH Source

endH :: forall w. EventHandle0 (Readable w)

#readable Source

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

#readableEnded Source

#readableFlowing Source

#readableHighWaterMark Source

#readableLength Source

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

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

#pipe' Source

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

#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 -> Effect (Maybe Buffer)

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

#read' Source

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

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

#readString Source

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' Source

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 Source

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' Source

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 Source

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

#writeableEnded Source

#writeableCorked Source

#errored Source

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

#writeableFinished Source

#writeableHighWaterMark Source

#writeableLength Source

#writeableNeedDrain Source

#write Source

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

#write' Source

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

#writeString Source

#writeString' Source

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

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

#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

End writing data to the stream.

#end' Source

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

#destroy Source

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

#destroy' Source

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

#closed Source

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

#destroyed Source

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

#pipeline Source

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

#readableFromString Source

#readableFromBuffer Source