streamly-core
Copyright(c) 2021 Composewell Technologies
LicenseBSD-3-Clause
Maintainerstreamly@composewell.com
Stabilityreleased
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Streamly.Console.Stdio

Description

Combinators to work with standard input, output, and error streams. This module supports reading and writing binary data or UTF-8 encoded text only. However, it is possible to use specific encoders and decoders to implement other encodings.

These streaming APIs use the stdin and stdout handles for reading from and writing to the console. The reads and writes are buffered, meaning each stream has its own buffer. Be cautious when switching between these APIs and handle-based APIs (e.g., readChars, getLine), between different stream APIs (e.g., readChars, readChunks), or even between different calls to the same API (e.g., readChars, readChars). If you switch from one stream to another, you should drain the first stream completely if you care about preserving any buffered data.

See also: Streamly.Internal.Console.Stdio

Synopsis

Streams (stdin)

read :: forall (m :: Type -> Type). MonadIO m => Stream m Word8 Source #

Read a byte stream from standard input.

read = Handle.read stdin
read = Stream.unfold Stdio.reader ()

Pre-release

readChars :: forall (m :: Type -> Type). MonadIO m => Stream m Char Source #

Read a character stream from Utf8 encoded standard input.

readChars = Unicode.decodeUtf8 Stdio.read

Pre-release

readChunks :: forall (m :: Type -> Type). MonadIO m => Stream m (Array Word8) Source #

Read a stream of chunks from standard input. The maximum size of a single chunk is limited to defaultChunkSize. The actual size read may be less than defaultChunkSize.

readChunks = Handle.readChunks stdin
readChunks = Stream.unfold Stdio.chunkReader ()

Pre-release

Streams (srdout)

putChunks :: MonadIO m => Stream m (Array Word8) -> m () Source #

Write a stream of chunks to standard output.

putChunks = Handle.putChunks stdout
putChunks = Stream.fold Stdio.writeChunks

Pre-release

Unfolds (stdin)

reader :: forall (m :: Type -> Type). MonadIO m => Unfold m () Word8 Source #

Unfold standard input into a stream of Word8.

chunkReader :: forall (m :: Type -> Type). MonadIO m => Unfold m () (Array Word8) Source #

Unfolds standard input into a stream of Word8 arrays.

Write (stdout)

write :: forall (m :: Type -> Type). MonadIO m => Fold m Word8 () Source #

Fold a stream of Word8 to standard output.

writeChunks :: forall (m :: Type -> Type). MonadIO m => Fold m (Array Word8) () Source #

Fold a stream of Array Word8 to standard output.

Write (stderr)

writeErr :: forall (m :: Type -> Type). MonadIO m => Fold m Word8 () Source #

Fold a stream of Word8 to standard error.

writeErrChunks :: forall (m :: Type -> Type). MonadIO m => Fold m (Array Word8) () Source #

Fold a stream of Array Word8 to standard error.