HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepipes-bytestring-2.1.7Haskell2010

Pipes.ByteString

This module provides pipes utilities for "byte streams", which are streams of strict ByteStrings chunks. Use byte streams to interact with both Handles and lazy ByteStrings.

To stream to or from Handles, use fromHandle or toHandle. For example, the following program copies data from one file to another:

import Pipes
import qualified Pipes.ByteString as P
import System.IO

main =
    withFile "inFile.txt"  ReadMode  $ \hIn  ->
    withFile "outFile.txt" WriteMode $ \hOut ->
    runEffect $ P.fromHandle hIn >-> P.toHandle hOut

You can stream to and from stdin and stdout using the predefined stdin and stdout pipes, like in the following "echo" program:

main = runEffect $ P.stdin >-> P.stdout

You can also translate pure lazy ByteStrings to and from pipes:

import qualified Data.ByteString.Lazy.Char8 as BL

main = runEffect $ P.fromLazy (BL.pack "Hello, world!\n") >-> P.stdout

In addition, this module provides many functions equivalent to lazy ByteString functions so that you can transform or fold byte streams. For example, to stream only the first three lines of stdin to stdout you would write:

import Lens.Family (over)
import Pipes
import qualified Pipes.ByteString as PB
import Pipes.Group (takes)

main = runEffect $ over PB.lines (takes 3) PB.stdin >-> PB.stdout

The above program will never bring more than one chunk (~ 32 KB) into memory, no matter how long the lines are.

Note that functions in this library are designed to operate on streams that are insensitive to chunk boundaries. This means that they may freely split chunks into smaller chunks and discard empty chunks. However, they will never concatenate chunks in order to provide strict upper bounds on memory usage.

  • 4 types
  • 69 values

Producers

7 declarations
valuehGetSome :: MonadIO m => Int -> Handle -> Producer' ByteString m ()
#

Convert a handle into a byte stream using a maximum chunk size

hGetSome forwards input immediately as it becomes available, splitting the input into multiple chunks if it exceeds the maximum chunk size.

Servers

2 declarations

Consumers

2 declarations

Pipes

8 declarations

Folds

19 declarations
valuefoldBytes
  1. :: Monad m
  2. => x -> Word8 -> x
  3. -> x
  4. -> x -> r
  5. -> Producer ByteString m ()
  6. -> m r
#

Reduce the stream of bytes using a strict left fold

Note: It's more efficient to use folds from Control.Foldl.ByteString in conjunction with Pipes.Prelude.fold when possible

Parsing

5 declarations

The following parsing utilities are single-byte analogs of the ones found in pipes-parse.

Parsing Lenses

8 declarations
valueline :: Monad m => Lens' (Producer ByteString m x) (Producer ByteString m (Producer ByteString m x))
#

Improper lens that splits a Producer after the first line

Unlike lines, this does not consume the newline marker, which is stored within the inner Producer

Note: This function is purely for demonstration purposes since it assumes a particular encoding. You should prefer the Text equivalent of this function from the pipes-text library.

Transforming Byte Streams

6 declarations

FreeT Transformations

10 declarations
valuelines :: Monad m => Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
#

Improper lens between a bytestream and its lines

Note: This function is purely for demonstration purposes since it assumes a particular encoding. You should prefer the Text equivalent of this function from the pipes-text library.

valueunlines :: Monad m => Lens' (FreeT (Producer ByteString m) m x) (Producer ByteString m x)
#

Improper lens between lines and a bytestream

Note: This function is purely for demonstration purposes since it assumes a particular encoding. You should prefer the Text equivalent of this function from the pipes-text library.

valuewords
  1. :: Monad m
  2. => Producer ByteString m x
  3. -> FreeT (Producer ByteString m) m x
#

Convert a bytestream to delimited words

Note: This function is purely for demonstration purposes since it assumes a particular encoding. You should prefer the Text equivalent of this function from the pipes-text library.

valueunwords
  1. :: Monad m
  2. => FreeT (Producer ByteString m) m x
  3. -> Producer ByteString m x
#

Convert delimited words back to a byte stream

Note: This function is purely for demonstration purposes since it assumes a particular encoding. You should prefer the Text equivalent of this function from the pipes-text library.

Re-exports

6 declarations

Data.ByteString re-exports the ByteString type.

Data.Word re-exports the Word8 type.

Pipes.Parse re-exports Parser.

Pipes.Group re-exports concats, intercalates, and FreeT (the type).

datadata ByteString
#

A space-efficient representation of a Word8 vector, supporting many efficient operations.

A ByteString contains 8-bit bytes, or by using the operations from Data.ByteString.Char8 it can be interpreted as containing 8-bit characters.

Instances15IsList, Eq, Data, Ord, Read, Show, …
  • IsList ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Eq ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Data ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Ord ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Read ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Show ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • IsString ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type

    Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

  • Semigroup ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Monoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • NFData ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Binary ByteStringDefined in binary-0.8.9.3 · Data.Binary.Class
  • Hashable ByteStringDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • Substitution ByteStringDefined in stringsearch-0.3.6.6 · Data.ByteString.Search.Substitution
  • Lift ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • type Item ByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
datadata Word8
#

8-bit unsigned integer type

Instances22Bounded, Enum, Eq, Integral, Data, Num, …
  • Bounded Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Enum Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Eq Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Integral Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Data Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ord Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Read Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Show Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Ix Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Bits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • FiniteBits Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Word
  • Storable Word8Defined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • PrintfArg Word8Defined in base-4.20.2.0 · Text.Printf
  • NFData Word8Defined in deepseq-1.5.0.0 · Control.DeepSeq
  • Binary Word8Defined in binary-0.8.9.3 · Data.Binary.Class
  • Hashable Word8Defined in hashable-1.4.7.0 · Data.Hashable.Class
  • Lift Word8Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • IArray UArray Word8Defined in array-0.5.8.0 · Data.Array.Base
  • MArray IOUArray Word8 IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • MArray (STUArray s) Word8 (ST s)Defined in array-0.5.8.0 · Data.Array.Base
newtypenewtype FreeT (f :: Type -> Type) (m :: Type -> Type) a
#

The "free monad transformer" for a functor f

Instances29MonadError, MonadReader, MonadState, MonadWriter, MonadBase, MonadFree, …