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).
#toEventEmitter Source
toEventEmitter :: forall rw. Stream rw -> EventEmitter
#closeH Source
closeH :: forall rw. EventHandle0 (Stream rw)
#drainH Source
drainH :: forall r. EventHandle0 (Writable r)
#finishH Source
finishH :: forall r. EventHandle0 (Writable r)
#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
#pauseH Source
pauseH :: forall w. EventHandle0 (Readable w)
#readableH Source
readableH :: forall w. EventHandle0 (Readable w)
#resumeH Source
resumeH :: forall w. EventHandle0 (Readable w)
#endH Source
endH :: forall w. EventHandle0 (Readable w)
#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.
#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).
- Modules
- Node.
Stream - Node.
Stream. Aff