-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Simple, composable, and easy-to-use stream I/O
--   
--   Overview
--   
--   The io-streams library contains simple and easy-to-use primitives for
--   I/O using streams. Most users will want to import the top-level
--   convenience module System.IO.Streams, which re-exports most of
--   the library:
--   
--   
--   import           System.IO.Streams (InputStream, OutputStream)
--   import qualified System.IO.Streams as Streams
--   
--   
--   For first-time users, io-streams comes with an included
--   tutorial, which can be found in the System.IO.Streams.Tutorial
--   module.
--   
--   Features
--   
--   The io-streams user API has two basic types: InputStream
--   a and OutputStream a, and three fundamental I/O
--   primitives:
--   
--   
--   -- read an item from an input stream
--   Streams.read :: InputStream a -> IO (Maybe a)
--   
--   -- push an item back to an input stream
--   Streams.unRead :: a -> InputStream a -> IO ()
--   
--   -- write to an output stream
--   Streams.write :: Maybe a -> OutputStream a -> IO ()
--   
--   
--   Streams can be transformed by composition and hooked together with
--   provided combinators:
--   
--   
--   ghci> Streams.fromList [1,2,3::Int] >>= Streams.map (*10) >>= Streams.toList
--   [10,20,30]
--   
--   
--   Stream composition leaves the original stream accessible:
--   
--   
--   ghci> input <- Streams.fromByteString "long string"
--   ghci> wrapped <- Streams.takeBytes 4 input
--   ghci> Streams.read wrapped
--   Just "long"
--   ghci> Streams.read wrapped
--   Nothing
--   ghci> Streams.read input
--   Just " string"
--   
--   
--   Simple types and operations in the IO monad mean straightforward and
--   simple exception handling and resource cleanup using Haskell standard
--   library facilities like Control.Exception.bracket.
--   
--   io-streams comes with:
--   
--   
--   
- functions to use files, handles, concurrent channels, sockets,
--   lists, vectors, and more as streams.
--   
- a variety of combinators for wrapping and transforming streams,
--   including compression and decompression using zlib, controlling
--   precisely how many bytes are read from or written to a stream,
--   buffering output using bytestring builders, folds, maps, filters,
--   zips, etc.
--   
- support for parsing from streams using attoparsec.
--   
- support for spawning processes and communicating with them using
--   streams.
--   
@package io-streams
@version 1.5.2.2

-- | Internal implementation of the io-streams library, intended
--   for library writers
--   
--   Library users should use the interface provided by
--   System.IO.Streams
module System.IO.Streams.Internal

-- | A strict pair type.
data SP a b
SP :: !a -> !b -> SP a b

-- | Internal convenience synonym for a pair of input/output streams.
type StreamPair a = SP InputStream a OutputStream a

-- | An InputStream generates values of type c in the
--   IO monad.
--   
--   Two primitive operations are defined on InputStream:
--   
--   
--   
- read :: InputStream c -> IO
--   (Maybe c) reads a value from the stream, where "end of
--   stream" is signaled by read returning Nothing.
--   
- unRead :: c -> InputStream c -> IO
--   () "pushes back" a value to the stream.
--   
--   
--   It is intended that InputStreams obey the following law:
--   
--   
--   unRead c stream >> read stream === return (Just c)
--   
data InputStream a
InputStream :: IO (Maybe a) -> (a -> IO ()) -> InputStream a
[_read] :: InputStream a -> IO (Maybe a)
[_unRead] :: InputStream a -> a -> IO ()

-- | An OutputStream consumes values of type c in the
--   IO monad. The only primitive operation defined on
--   OutputStream is:
--   
--   
--   
- 
write :: Maybe c -> OutputStream c
--   -> IO ()

--   
--   
--   Values of type c are written in an OutputStream by
--   wrapping them in Just, and the end of the stream is indicated
--   by supplying Nothing.
--   
--   If you supply a value after a Nothing, the behavior is defined
--   by the implementer of the given OutputStream. (All
--   OutputStream definitions in this library will simply discard
--   the extra input.)
data OutputStream a
OutputStream :: (Maybe a -> IO ()) -> OutputStream a
[_write] :: OutputStream a -> Maybe a -> IO ()

-- | Reads one value from an InputStream.
--   
--   Returns either a value wrapped in a Just, or Nothing if
--   the end of the stream is reached.
read :: InputStream a -> IO (Maybe a)

-- | Pushes a value back onto an input stream. read and
--   unRead should satisfy the following law, with the possible
--   exception of side effects:
--   
--   
--   Streams.unRead c stream >> Streams.read stream === return (Just c)
--   
--   
--   Note that this could be used to add values back to the stream that
--   were not originally drawn from the stream.
unRead :: a -> InputStream a -> IO ()

-- | Observes the first value from an InputStream without consuming
--   it.
--   
--   Returns Nothing if the InputStream is empty. peek
--   satisfies the following law:
--   
--   
--   Streams.peek stream >> Streams.read stream === Streams.read stream
--   
peek :: InputStream a -> IO (Maybe a)

-- | Feeds a value to an OutputStream. Values of type c are
--   written in an OutputStream by wrapping them in Just, and
--   the end of the stream is indicated by supplying Nothing.
write :: Maybe a -> OutputStream a -> IO ()

-- | Flipped version of write.
--   
--   Since: 1.3.0.0.
writeTo :: OutputStream a -> Maybe a -> IO ()

-- | Checks if an InputStream is at end-of-stream.
atEOF :: InputStream a -> IO Bool

-- | Creates an InputStream from a value-producing action.
--   
--   (makeInputStream m) calls the action m each time you
--   request a value from the InputStream. The given action is
--   extended with the default pushback mechanism (see
--   System.IO.Streams.Internal#pushback).
makeInputStream :: IO (Maybe a) -> IO (InputStream a)

-- | Creates an OutputStream from a value-consuming action.
--   
--   (makeOutputStream f) runs the computation f on each
--   value fed to it.
--   
--   Since version 1.2.0.0, makeOutputStream also ensures that
--   output streams no longer receive data once EOF is received (i.e. you
--   can now assume that makeOutputStream will feed your function
--   Nothing at most once.)
makeOutputStream :: (Maybe a -> IO ()) -> IO (OutputStream a)

-- | appendInputStream concatenates two InputStreams,
--   analogous to (++) for lists.
--   
--   The second InputStream continues where the first
--   InputStream ends.
--   
--   Note: values pushed back to appendInputStream are not
--   propagated to either wrapped InputStream.
appendInputStream :: InputStream a -> InputStream a -> IO (InputStream a)

-- | concatInputStreams concatenates a list of InputStreams,
--   analogous to (++) for lists.
--   
--   Subsequent InputStreams continue where the previous one
--   InputStream ends.
--   
--   Note: values pushed back to the InputStream returned by
--   concatInputStreams are not propagated to any of the source
--   InputStreams.
concatInputStreams :: [InputStream a] -> IO (InputStream a)

-- | Connects an InputStream and OutputStream, supplying
--   values from the InputStream to the OutputStream, and
--   propagating the end-of-stream message from the InputStream
--   through to the OutputStream.
--   
--   The connection ends when the InputStream yields a
--   Nothing.
connect :: InputStream a -> OutputStream a -> IO ()

-- | The connectTo function is just flip
--   connect.
--   
--   Useful for writing expressions like fromList [1,2,3] >>=
--   connectTo foo.
connectTo :: OutputStream a -> InputStream a -> IO ()

-- | Connects an InputStream to an OutputStream without
--   passing the end-of-stream notification through to the
--   OutputStream.
--   
--   Use this to supply an OutputStream with multiple
--   InputStreams and use connect for the final
--   InputStream to finalize the OutputStream, like so:
--   
--   
--   do Streams.supply  input1 output
--      Streams.supply  input2 output
--      Streams.connect input3 output
--   
supply :: InputStream a -> OutputStream a -> IO ()

-- | supply with the arguments flipped.
supplyTo :: OutputStream a -> InputStream a -> IO ()

-- | Converts an InputStream into a thread-safe InputStream,
--   at a slight performance penalty.
--   
--   For performance reasons, this library provides non-thread-safe streams
--   by default. Use the locking functions to convert these
--   streams into slightly slower, but thread-safe, equivalents.
lockingInputStream :: InputStream a -> IO (InputStream a)

-- | Converts an OutputStream into a thread-safe
--   OutputStream, at a slight performance penalty.
--   
--   For performance reasons, this library provides non-thread-safe streams
--   by default. Use the locking functions to convert these
--   streams into slightly slower, but thread-safe, equivalents.
lockingOutputStream :: OutputStream a -> IO (OutputStream a)

-- | An empty InputStream that yields Nothing immediately.
nullInput :: IO (InputStream a)

-- | An empty OutputStream that discards any input fed to it.
nullOutput :: IO (OutputStream a)

-- | A Generator is a coroutine monad that can be used to define
--   complex InputStreams. You can cause a value of type Just
--   r to appear when the InputStream is read by calling
--   yield:
--   
--   
--   g :: Generator Int ()
--   g = do
--       Streams.yield 1
--       Streams.yield 2
--       Streams.yield 3
--   
--   
--   A Generator can be turned into an InputStream by calling
--   fromGenerator:
--   
--   
--   m :: IO [Int]
--   m = Streams.fromGenerator g >>= Streams.toList     -- value returned is [1,2,3]
--   
--   
--   You can perform IO by calling liftIO, and turn a
--   Generator into an InputStream with fromGenerator.
--   
--   As a general rule, you should not acquire resources that need to be
--   freed from a Generator, because there is no guarantee the
--   coroutine continuation will ever be called, nor can you catch an
--   exception from within a Generator.
data Generator r a

-- | Turns a Generator into an InputStream.
fromGenerator :: Generator r a -> IO (InputStream r)

-- | Calling yield x causes the value Just
--   x to appear on the input when this generator is converted to an
--   InputStream. The rest of the computation after the call to
--   yield is resumed later when the InputStream is
--   read again.
yield :: r -> Generator r ()
data Consumer c a
fromConsumer :: Consumer r a -> IO (OutputStream r)
await :: Consumer r (Maybe r)
instance GHC.Internal.Base.Applicative (System.IO.Streams.Internal.Consumer r)
instance GHC.Internal.Base.Applicative (System.IO.Streams.Internal.Generator r)
instance GHC.Internal.IO.BufferedIO.BufferedIO (System.IO.Streams.Internal.InputStream Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.IO.BufferedIO.BufferedIO (System.IO.Streams.Internal.OutputStream Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.IO.BufferedIO.BufferedIO (System.IO.Streams.Internal.StreamPair Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.Base.Functor (System.IO.Streams.Internal.Consumer r)
instance GHC.Internal.Base.Functor (System.IO.Streams.Internal.Generator r)
instance GHC.Internal.IO.Device.IODevice (System.IO.Streams.Internal.InputStream Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.IO.Device.IODevice (System.IO.Streams.Internal.OutputStream Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.IO.Device.IODevice (System.IO.Streams.Internal.StreamPair Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.Base.Monad (System.IO.Streams.Internal.Consumer c)
instance GHC.Internal.Base.Monad (System.IO.Streams.Internal.Generator r)
instance Control.Monad.IO.Class.MonadIO (System.IO.Streams.Internal.Consumer c)
instance Control.Monad.IO.Class.MonadIO (System.IO.Streams.Internal.Generator r)
instance GHC.Internal.IO.Device.RawIO (System.IO.Streams.Internal.InputStream Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.IO.Device.RawIO (System.IO.Streams.Internal.OutputStream Data.ByteString.Internal.Type.ByteString)
instance GHC.Internal.IO.Device.RawIO (System.IO.Streams.Internal.StreamPair Data.ByteString.Internal.Type.ByteString)

-- | Input and output streams for file Handles.
module System.IO.Streams.Handle

-- | Converts a read-only handle into an InputStream of strict
--   ByteStrings.
--   
--   Note that the wrapped handle is not closed when it yields
--   end-of-stream; you can use atEndOfInput to close the handle if
--   you would like this behaviour.
handleToInputStream :: Handle -> IO (InputStream ByteString)

-- | Converts a writable handle into an OutputStream of strict
--   ByteStrings.
--   
--   Note that the wrapped handle is not closed when it receives
--   end-of-stream; you can use atEndOfOutput to close the handle if
--   you would like this behaviour.
--   
--   Note: to force the Handle to be flushed, you can write a
--   null string to the returned OutputStream:
--   
--   
--   Streams.write (Just "") os
--   
handleToOutputStream :: Handle -> IO (OutputStream ByteString)

-- | Converts a readable and writable handle into an
--   InputStream/OutputStream of strict ByteStrings.
--   
--   Note that the wrapped handle is not closed when it receives
--   end-of-stream; you can use atEndOfOutput to close the handle if
--   you would like this behaviour.
--   
--   Note: to force the Handle to be flushed, you can write a
--   null string to the returned OutputStream:
--   
--   
--   Streams.write (Just "") os
--   
--   
--   Since: 1.3.4.0.
handleToStreams :: Handle -> IO (InputStream ByteString, OutputStream ByteString)

-- | Converts an InputStream over bytestrings to a read-only
--   Handle. Note that the generated handle is opened unbuffered in
--   binary mode (i.e. no newline translation is performed).
--   
--   Note: the InputStream passed into this function is wrapped in
--   lockingInputStream to make it thread-safe.
--   
--   Since: 1.0.2.0.
inputStreamToHandle :: InputStream ByteString -> IO Handle

-- | Converts an OutputStream over bytestrings to a write-only
--   Handle. Note that the Handle will be opened in
--   non-buffering mode; if you buffer the OutputStream using the
--   Handle buffering then io-streams will copy the
--   Handle buffer when sending ByteString values to the
--   output, which might not be what you want.
--   
--   When the output buffer, if used, is flushed (using hFlush), an
--   empty string is written to the provided OutputStream.
--   
--   Note: the OutputStream passed into this function is
--   wrapped in lockingOutputStream to make it thread-safe.
--   
--   Since: 1.0.2.0.
outputStreamToHandle :: OutputStream ByteString -> IO Handle

-- | Converts a pair of InputStream and OutputStream over
--   bytestrings to a read-write Handle.
--   
--   Note: the streams passed into this function are wrapped in locking
--   primitives to make them thread-safe.
--   
--   Since: 1.0.2.0.
streamPairToHandle :: InputStream ByteString -> OutputStream ByteString -> IO Handle

-- | An InputStream for stdin.
stdin :: InputStream ByteString

-- | An OutputStream for stdout.
stdout :: OutputStream ByteString

-- | An OutputStream for stderr.
stderr :: OutputStream ByteString

-- | Input and output streams for files.
--   
--   The functions in this file use "with*" or "bracket" semantics, i.e.
--   they open the supplied FilePath, run a user computation, and
--   then close the file handle. If you need more control over the
--   lifecycle of the underlying file descriptor resources, you are
--   encouraged to use the functions from System.IO.Streams.Handle
--   instead.
module System.IO.Streams.File

-- | withFileAsInput name act opens the specified file in
--   "read mode" and passes the resulting InputStream to the
--   computation act. The file will be closed on exit from
--   withFileAsInput, whether by normal termination or by raising
--   an exception.
--   
--   If closing the file raises an exception, then that exception
--   will be raised by withFileAsInput rather than any exception
--   raised by act.
withFileAsInput :: FilePath -> (InputStream ByteString -> IO a) -> IO a

-- | Like withFileAsInput, but seeks to the specified byte offset
--   before attaching the given file descriptor to the InputStream.
withFileAsInputStartingAt :: Int64 -> FilePath -> (InputStream ByteString -> IO a) -> IO a

-- | Like withFileAsInputStartingAt, except that the
--   ByteString emitted by the created InputStream may reuse
--   its buffer. You may only use this function if you do not retain
--   references to the generated bytestrings emitted.
unsafeWithFileAsInputStartingAt :: Int64 -> FilePath -> (InputStream ByteString -> IO a) -> IO a

-- | Open a file for writing and attaches an OutputStream for you to
--   write to. The file will be closed on error or completion of your
--   action.
withFileAsOutput :: FilePath -> (OutputStream ByteString -> IO a) -> IO a

-- | Like withFileAsOutput, but allowing you control over the output
--   file mode and buffering behaviour.
withFileAsOutputExt :: FilePath -> IOMode -> BufferMode -> (OutputStream ByteString -> IO a) -> IO a

-- | Convenience module for debugging streams. Provides stream transformers
--   that wrap InputStreams and OutputStreams, sending a
--   description of all data to an OutputStream for debugging.
module System.IO.Streams.Debug
debugInput :: (a -> ByteString) -> ByteString -> OutputStream ByteString -> InputStream a -> IO (InputStream a)
debugOutput :: (a -> ByteString) -> ByteString -> OutputStream ByteString -> OutputStream a -> IO (OutputStream a)
debugInputBS :: ByteString -> OutputStream ByteString -> InputStream ByteString -> IO (InputStream ByteString)
debugOutputBS :: ByteString -> OutputStream ByteString -> OutputStream ByteString -> IO (OutputStream ByteString)

-- | Core types and functions for the io-streams library.
module System.IO.Streams.Core

-- | An InputStream generates values of type c in the
--   IO monad.
--   
--   Two primitive operations are defined on InputStream:
--   
--   
--   
- read :: InputStream c -> IO
--   (Maybe c) reads a value from the stream, where "end of
--   stream" is signaled by read returning Nothing.
--   
- unRead :: c -> InputStream c -> IO
--   () "pushes back" a value to the stream.
--   
--   
--   It is intended that InputStreams obey the following law:
--   
--   
--   unRead c stream >> read stream === return (Just c)
--   
data InputStream a

-- | An OutputStream consumes values of type c in the
--   IO monad. The only primitive operation defined on
--   OutputStream is:
--   
--   
--   
- 
write :: Maybe c -> OutputStream c
--   -> IO ()

--   
--   
--   Values of type c are written in an OutputStream by
--   wrapping them in Just, and the end of the stream is indicated
--   by supplying Nothing.
--   
--   If you supply a value after a Nothing, the behavior is defined
--   by the implementer of the given OutputStream. (All
--   OutputStream definitions in this library will simply discard
--   the extra input.)
data OutputStream a

-- | Creates an InputStream from a value-producing action.
--   
--   (makeInputStream m) calls the action m each time you
--   request a value from the InputStream. The given action is
--   extended with the default pushback mechanism (see
--   System.IO.Streams.Internal#pushback).
makeInputStream :: IO (Maybe a) -> IO (InputStream a)

-- | Creates an OutputStream from a value-consuming action.
--   
--   (makeOutputStream f) runs the computation f on each
--   value fed to it.
--   
--   Since version 1.2.0.0, makeOutputStream also ensures that
--   output streams no longer receive data once EOF is received (i.e. you
--   can now assume that makeOutputStream will feed your function
--   Nothing at most once.)
makeOutputStream :: (Maybe a -> IO ()) -> IO (OutputStream a)

-- | Reads one value from an InputStream.
--   
--   Returns either a value wrapped in a Just, or Nothing if
--   the end of the stream is reached.
read :: InputStream a -> IO (Maybe a)

-- | Pushes a value back onto an input stream. read and
--   unRead should satisfy the following law, with the possible
--   exception of side effects:
--   
--   
--   Streams.unRead c stream >> Streams.read stream === return (Just c)
--   
--   
--   Note that this could be used to add values back to the stream that
--   were not originally drawn from the stream.
unRead :: a -> InputStream a -> IO ()

-- | Observes the first value from an InputStream without consuming
--   it.
--   
--   Returns Nothing if the InputStream is empty. peek
--   satisfies the following law:
--   
--   
--   Streams.peek stream >> Streams.read stream === Streams.read stream
--   
peek :: InputStream a -> IO (Maybe a)

-- | Feeds a value to an OutputStream. Values of type c are
--   written in an OutputStream by wrapping them in Just, and
--   the end of the stream is indicated by supplying Nothing.
write :: Maybe a -> OutputStream a -> IO ()

-- | Flipped version of write.
--   
--   Since: 1.3.0.0.
writeTo :: OutputStream a -> Maybe a -> IO ()

-- | Checks if an InputStream is at end-of-stream.
atEOF :: InputStream a -> IO Bool

-- | Connects an InputStream and OutputStream, supplying
--   values from the InputStream to the OutputStream, and
--   propagating the end-of-stream message from the InputStream
--   through to the OutputStream.
--   
--   The connection ends when the InputStream yields a
--   Nothing.
connect :: InputStream a -> OutputStream a -> IO ()

-- | The connectTo function is just flip
--   connect.
--   
--   Useful for writing expressions like fromList [1,2,3] >>=
--   connectTo foo.
connectTo :: OutputStream a -> InputStream a -> IO ()

-- | Connects an InputStream to an OutputStream without
--   passing the end-of-stream notification through to the
--   OutputStream.
--   
--   Use this to supply an OutputStream with multiple
--   InputStreams and use connect for the final
--   InputStream to finalize the OutputStream, like so:
--   
--   
--   do Streams.supply  input1 output
--      Streams.supply  input2 output
--      Streams.connect input3 output
--   
supply :: InputStream a -> OutputStream a -> IO ()

-- | supply with the arguments flipped.
supplyTo :: OutputStream a -> InputStream a -> IO ()

-- | appendInputStream concatenates two InputStreams,
--   analogous to (++) for lists.
--   
--   The second InputStream continues where the first
--   InputStream ends.
--   
--   Note: values pushed back to appendInputStream are not
--   propagated to either wrapped InputStream.
appendInputStream :: InputStream a -> InputStream a -> IO (InputStream a)

-- | concatInputStreams concatenates a list of InputStreams,
--   analogous to (++) for lists.
--   
--   Subsequent InputStreams continue where the previous one
--   InputStream ends.
--   
--   Note: values pushed back to the InputStream returned by
--   concatInputStreams are not propagated to any of the source
--   InputStreams.
concatInputStreams :: [InputStream a] -> IO (InputStream a)

-- | Converts an InputStream into a thread-safe InputStream,
--   at a slight performance penalty.
--   
--   For performance reasons, this library provides non-thread-safe streams
--   by default. Use the locking functions to convert these
--   streams into slightly slower, but thread-safe, equivalents.
lockingInputStream :: InputStream a -> IO (InputStream a)

-- | Converts an OutputStream into a thread-safe
--   OutputStream, at a slight performance penalty.
--   
--   For performance reasons, this library provides non-thread-safe streams
--   by default. Use the locking functions to convert these
--   streams into slightly slower, but thread-safe, equivalents.
lockingOutputStream :: OutputStream a -> IO (OutputStream a)

-- | An empty InputStream that yields Nothing immediately.
nullInput :: IO (InputStream a)

-- | An empty OutputStream that discards any input fed to it.
nullOutput :: IO (OutputStream a)

-- | A Generator is a coroutine monad that can be used to define
--   complex InputStreams. You can cause a value of type Just
--   r to appear when the InputStream is read by calling
--   yield:
--   
--   
--   g :: Generator Int ()
--   g = do
--       Streams.yield 1
--       Streams.yield 2
--       Streams.yield 3
--   
--   
--   A Generator can be turned into an InputStream by calling
--   fromGenerator:
--   
--   
--   m :: IO [Int]
--   m = Streams.fromGenerator g >>= Streams.toList     -- value returned is [1,2,3]
--   
--   
--   You can perform IO by calling liftIO, and turn a
--   Generator into an InputStream with fromGenerator.
--   
--   As a general rule, you should not acquire resources that need to be
--   freed from a Generator, because there is no guarantee the
--   coroutine continuation will ever be called, nor can you catch an
--   exception from within a Generator.
data Generator r a

-- | Turns a Generator into an InputStream.
fromGenerator :: Generator r a -> IO (InputStream r)

-- | Calling yield x causes the value Just
--   x to appear on the input when this generator is converted to an
--   InputStream. The rest of the computation after the call to
--   yield is resumed later when the InputStream is
--   read again.
yield :: r -> Generator r ()

-- | Stream utilities for working with concurrent channels.
module System.IO.Streams.Concurrent

-- | Writes the contents of an input stream to a channel until the input
--   stream yields end-of-stream.
inputToChan :: InputStream a -> Chan (Maybe a) -> IO ()

-- | Turns a Chan into an input stream.
chanToInput :: Chan (Maybe a) -> IO (InputStream a)

-- | Turns a Chan into an output stream.
chanToOutput :: Chan (Maybe a) -> IO (OutputStream a)

-- | Concurrently merges a list of InputStreams, combining values in
--   the order they become available.
--   
--   Note: does not forward individual end-of-stream notifications,
--   the produced stream does not yield end-of-stream until all of the
--   input streams have finished.
--   
--   Any exceptions raised in one of the worker threads will be trapped and
--   re-raised in the current thread.
--   
--   If the supplied list is empty, concurrentMerge will return an
--   empty stream. (Since: 1.5.0.1)
concurrentMerge :: [InputStream a] -> IO (InputStream a)

-- | Create a new pair of streams using an underlying Chan.
--   Everything written to the OutputStream will appear as-is on the
--   InputStream.
--   
--   Since reading from the InputStream and writing to the
--   OutputStream are blocking calls, be sure to do so in different
--   threads.
makeChanPipe :: IO (InputStream a, OutputStream a)

-- | Generic stream manipulations
module System.IO.Streams.Combinators

-- | A side-effecting fold over an InputStream, as a stream
--   transformer.
--   
--   The IO action returned by inputFoldM can be used to fetch and
--   reset the updated seed value. Example:
--   
--   
--   ghci> is <- Streams.fromList [1, 2, 3::Int]
--   ghci> (is', getSeed) <- Streams.inputFoldM (\x y -> return (x+y)) 0 is
--   ghci> Streams.toList is'
--   [1,2,3]
--   ghci> getSeed
--   6
--   
inputFoldM :: (a -> b -> IO a) -> a -> InputStream b -> IO (InputStream b, IO a)

-- | A side-effecting fold over an OutputStream, as a stream
--   transformer.
--   
--   The IO action returned by outputFoldM can be used to fetch and
--   reset the updated seed value. Example:
--   
--   
--   ghci> is <- Streams.fromList [1, 2, 3::Int]
--   ghci> (os, getList) <- Streams.listOutputStream
--   ghci> (os', getSeed) <- Streams.outputFoldM (\x y -> return (x+y)) 0 os
--   ghci> Streams.connect is os'
--   ghci> getList
--   [1,2,3]
--   ghci> getSeed
--   6
--   
outputFoldM :: (a -> b -> IO a) -> a -> OutputStream b -> IO (OutputStream b, IO a)

-- | A left fold over an input stream. The input stream is fully consumed.
--   See foldl.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList [1..10] >>= Streams.fold (+) 0
--   55
--   
fold :: (s -> a -> s) -> s -> InputStream a -> IO s

-- | A side-effecting left fold over an input stream. The input stream is
--   fully consumed. See foldl.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList [1..10] >>= Streams.foldM (x y -> return (x + y)) 0
--   55
--   
foldM :: (s -> a -> IO s) -> s -> InputStream a -> IO s

-- | A variant of fold suitable for use with composable folds from
--   'beautiful folding' libraries like the foldl library. The input
--   stream is fully consumed.
--   
--   Example:
--   
--   
--   ghci> let folds = liftA3 (,,) Foldl.length Foldl.mean Foldl.maximum
--   ghci> Streams.fromList [1..10::Double] >>= Foldl.purely Streams.fold_ folds is
--   ghci> (10,5.5,Just 10.0)
--   
--   
--   Since 1.3.6.0
fold_ :: (x -> a -> x) -> x -> (x -> s) -> InputStream a -> IO s

-- | A variant of foldM suitable for use with composable folds from
--   'beautiful folding' libraries like the foldl library. The input
--   stream is fully consumed.
--   
--   Example:
--   
--   
--   ghci> let folds = Foldl.mapM_ print *> Foldl.generalize (liftA2 (,) Foldl.sum Foldl.mean)
--   ghci> Streams.fromList [1..3::Double] >>= Foldl.impurely Streams.foldM_ folds
--   1.0
--   2.0
--   3.0
--   (6.0,2.0)
--   
--   
--   Since 1.3.6.0
foldM_ :: (x -> a -> IO x) -> IO x -> (x -> IO s) -> InputStream a -> IO s

-- | any predicate stream returns True if any element in
--   stream matches the predicate.
--   
--   any consumes as few elements as possible, ending consumption if
--   an element satisfies the predicate.
--   
--   
--   ghci> is <- Streams.fromList [1, 2, 3]
--   ghci> Streams.any (> 0) is    -- Consumes one element
--   True
--   ghci> Streams.read is
--   Just 2
--   ghci> Streams.any even is     -- Only 3 remains
--   False
--   
any :: (a -> Bool) -> InputStream a -> IO Bool

-- | all predicate stream returns True if every element in
--   stream matches the predicate.
--   
--   all consumes as few elements as possible, ending consumption if
--   any element fails the predicate.
--   
--   
--   ghci> is <- Streams.fromList [1, 2, 3]
--   ghci> Streams.all (< 0) is    -- Consumes one element
--   False
--   ghci> Streams.read is
--   Just 2
--   ghci> Streams.all odd is      -- Only 3 remains
--   True
--   
all :: (a -> Bool) -> InputStream a -> IO Bool

-- | maximum stream returns the greatest element in
--   stream or Nothing if the stream is empty.
--   
--   maximum consumes the entire stream.
--   
--   
--   ghci> is <- Streams.fromList [1, 2, 3]
--   ghci> Streams.maximum is
--   3
--   ghci> Streams.read is     -- The stream is now empty
--   Nothing
--   
maximum :: Ord a => InputStream a -> IO (Maybe a)

-- | minimum stream returns the greatest element in
--   stream
--   
--   minimum consumes the entire stream.
--   
--   
--   ghci> is <- Streams.fromList [1, 2, 3]
--   ghci> Streams.minimum is
--   1
--   ghci> Streams.read is    -- The stream is now empty
--   Nothing
--   
minimum :: Ord a => InputStream a -> IO (Maybe a)

-- | unfoldM f seed builds an InputStream from successively
--   applying f to the seed value, continuing if
--   f produces Just and halting on Nothing.
--   
--   
--   ghci> is <- Streams.unfoldM (n -> return $ if n < 3 then Just (n, n + 1) else Nothing) 0
--   ghci> Streams.toList is
--   [0,1,2]
--   
unfoldM :: (b -> IO (Maybe (a, b))) -> b -> IO (InputStream a)

-- | Maps a pure function over an InputStream.
--   
--   map f s passes all output from s through the
--   function f.
--   
--   Satisfies the following laws:
--   
--   
--   Streams.map (g . f) === Streams.map f >=> Streams.map g
--   Streams.map id === Streams.makeInputStream . Streams.read
--   
map :: (a -> b) -> InputStream a -> IO (InputStream b)

-- | Maps an impure function over an InputStream.
--   
--   mapM f s passes all output from s through the IO
--   action f.
--   
--   Satisfies the following laws:
--   
--   
--   Streams.mapM (f >=> g) === Streams.mapM f >=> Streams.mapM g
--   Streams.mapM return === Streams.makeInputStream . Streams.read
--   
mapM :: (a -> IO b) -> InputStream a -> IO (InputStream b)

-- | Maps a side effect over an InputStream.
--   
--   mapM_ f s produces a new input stream that passes all output
--   from s through the side-effecting IO action f.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList [1,2,3] >>=
--         Streams.mapM_ (putStrLn . show . (*2)) >>=
--         Streams.toList
--   2
--   4
--   6
--   [1,2,3]
--   
mapM_ :: (a -> IO b) -> InputStream a -> IO (InputStream a)

-- | A version of map that discards elements
--   
--   mapMaybe f s passes all output from s through the
--   function f and discards elements for which f s
--   evaluates to Nothing.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList [Just 1, None, Just 3] >>=
--         Streams.mapMaybe id >>=
--         Streams.toList
--   [1,3]
--   
--   
--   Since: 1.2.1.0
mapMaybe :: (a -> Maybe b) -> InputStream a -> IO (InputStream b)

-- | Contravariant counterpart to map.
--   
--   contramap f s passes all input to s through the
--   function f.
--   
--   Satisfies the following laws:
--   
--   
--   Streams.contramap (g . f) === Streams.contramap g >=> Streams.contramap f
--   Streams.contramap id === return
--   
contramap :: (a -> b) -> OutputStream b -> IO (OutputStream a)

-- | Contravariant counterpart to mapM.
--   
--   contramapM f s passes all input to s through the IO
--   action f
--   
--   Satisfies the following laws:
--   
--   
--   Streams.contramapM (f >=> g) = Streams.contramapM g >=> Streams.contramapM f
--   Streams.contramapM return = return
--   
contramapM :: (a -> IO b) -> OutputStream b -> IO (OutputStream a)

-- | Equivalent to mapM_ for output.
--   
--   contramapM f s passes all input to s through the
--   side-effecting IO action f.
contramapM_ :: (a -> IO b) -> OutputStream a -> IO (OutputStream a)

-- | Contravariant counterpart to contramapMaybe.
--   
--   contramap f s passes all input to s through the
--   function f. Discards all the elements for which f
--   returns Nothing.
--   
--   Since: 1.2.1.0
contramapMaybe :: (a -> Maybe b) -> OutputStream b -> IO (OutputStream a)

-- | Drops chunks from an input stream if they fail to match a given filter
--   predicate. See filter.
--   
--   Items pushed back to the returned stream are propagated back upstream.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList ["the", "quick", "brown", "fox"] >>=
--         Streams.filter (/= "brown") >>= Streams.toList
--   ["the","quick","fox"]
--   
filter :: (a -> Bool) -> InputStream a -> IO (InputStream a)

-- | Drops chunks from an input stream if they fail to match a given filter
--   predicate. See filter.
--   
--   Items pushed back to the returned stream are propagated back upstream.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList ["the", "quick", "brown", "fox"] >>=
--         Streams.filterM (return . (/= "brown")) >>= Streams.toList
--   ["the","quick","fox"]
--   
filterM :: (a -> IO Bool) -> InputStream a -> IO (InputStream a)

-- | Filters output to be sent to the given OutputStream using a
--   pure function. See filter.
--   
--   Example:
--   
--   
--   ghci> import qualified Data.ByteString.Char8 as S
--   ghci> os1 <- Streams.stdout >>= Streams.'System.IO.Streams.unlines
--   ghci> os2 <- os1 >>= Streams.contramap (S.pack . show) >>= Streams.filterOutput even
--   ghci> Streams.write (Just 3) os2
--   ghci> Streams.write (Just 4) os2
--   4
--   
filterOutput :: (a -> Bool) -> OutputStream a -> IO (OutputStream a)

-- | Filters output to be sent to the given OutputStream using a
--   predicate function in IO. See filterM.
--   
--   Example:
--   
--   
--   ghci> let check a = putStrLn a ("Allow " ++ show a ++ "?") >> readLn :: IO Bool
--   ghci> import qualified Data.ByteString.Char8 as S
--   ghci> os1 <- Streams.unlines Streams.stdout
--   ghci> os2 <- os1 >>= Streams.contramap (S.pack . show) >>= Streams.filterOutputM check
--   ghci> Streams.write (Just 3) os2
--   Allow 3?
--   False<Enter>
--   ghci> Streams.write (Just 4) os2
--   Allow 4?
--   True<Enter>
--   4
--   
filterOutputM :: (a -> IO Bool) -> OutputStream a -> IO (OutputStream a)

-- | Wraps an OutputStream, producing a new OutputStream that
--   will pass at most n items on to the wrapped stream,
--   subsequently ignoring the rest of the input.
give :: Int64 -> OutputStream a -> IO (OutputStream a)

-- | Wraps an InputStream, producing a new InputStream that
--   will produce at most n items, subsequently yielding
--   end-of-stream forever.
--   
--   Items pushed back to the returned InputStream will be
--   propagated upstream, modifying the count of taken items accordingly.
--   
--   Example:
--   
--   
--   ghci> is <- Streams.fromList [1..9::Int]
--   ghci> is' <- Streams.take 1 is
--   ghci> Streams.read is'
--   Just 1
--   ghci> Streams.read is'
--   Nothing
--   ghci> Streams.peek is
--   Just 2
--   ghci> Streams.unRead 11 is'
--   ghci> Streams.peek is
--   Just 11
--   ghci> Streams.peek is'
--   Just 11
--   ghci> Streams.read is'
--   Just 11
--   ghci> Streams.read is'
--   Nothing
--   ghci> Streams.read is
--   Just 2
--   ghci> Streams.toList is
--   [3,4,5,6,7,8,9]
--   
take :: Int64 -> InputStream a -> IO (InputStream a)

-- | Wraps an InputStream, producing a new InputStream that
--   will drop the first n items produced by the wrapped stream.
--   See drop.
--   
--   Items pushed back to the returned InputStream will be
--   propagated upstream, modifying the count of dropped items accordingly.
drop :: Int64 -> InputStream a -> IO (InputStream a)

-- | Wraps an OutputStream, producing a new OutputStream that
--   will ignore the first n items received, subsequently passing
--   the rest of the input on to the wrapped stream.
ignore :: Int64 -> OutputStream a -> IO (OutputStream a)

-- | Combines two input streams. Continues yielding elements from both
--   input streams until one of them finishes.
zip :: InputStream a -> InputStream b -> IO (InputStream (a, b))

-- | Combines two input streams using the supplied function. Continues
--   yielding elements from both input streams until one of them finishes.
zipWith :: (a -> b -> c) -> InputStream a -> InputStream b -> IO (InputStream c)

-- | Combines two input streams using the supplied monadic function.
--   Continues yielding elements from both input streams until one of them
--   finishes.
zipWithM :: (a -> b -> IO c) -> InputStream a -> InputStream b -> IO (InputStream c)

-- | Takes apart a stream of pairs, producing a pair of input streams.
--   Reading from either of the produced streams will cause a pair of
--   values to be pulled from the original stream if necessary. Note that
--   reading n values from one of the returned streams will cause
--   n values to be buffered at the other stream.
--   
--   Access to the original stream is thread safe, i.e. guarded by a lock.
unzip :: InputStream (a, b) -> IO (InputStream a, InputStream b)

-- | Given two OutputStreams, returns a new stream that "unzips" the
--   tuples being written, writing the two elements to the corresponding
--   given streams.
--   
--   You can use this together with contramap (\ x -> (x,
--   x)) to "fork" a stream into two.
--   
--   Since: 1.5.2.0
contraunzip :: OutputStream a -> OutputStream b -> IO (OutputStream (a, b))

-- | The function intersperse v s wraps the OutputStream
--   s, creating a new output stream that writes its input to
--   s interspersed with the provided value v. See
--   intersperse.
--   
--   Example:
--   
--   
--   ghci> import Control.Monad ((>=>))
--   ghci> is <- Streams.fromList ["nom", "nom", "nom"::ByteString]
--   ghci> Streams.outputToList (Streams.intersperse "burp!" >=> Streams.connect is)
--   ["nom","burp!","nom","burp!","nom"]
--   
intersperse :: a -> OutputStream a -> IO (OutputStream a)

-- | Drives an InputStream to end-of-stream, discarding all of the
--   yielded values.
skipToEof :: InputStream a -> IO ()

-- | Wraps an OutputStream, ignoring any end-of-stream
--   Nothing values written to the returned stream.
--   
--   Since: 1.0.1.0
ignoreEof :: OutputStream a -> IO (OutputStream a)

-- | Wraps an InputStream, running the specified action when the
--   stream yields end-of-file.
--   
--   Since: 1.0.2.0
atEndOfInput :: IO b -> InputStream a -> IO (InputStream a)

-- | Wraps an OutputStream, running the specified action when the
--   stream receives end-of-file.
--   
--   Since: 1.0.2.0
atEndOfOutput :: IO b -> OutputStream a -> IO (OutputStream a)

-- | Buffering for output streams based on bytestring builders.
--   
--   Buffering an output stream can often improve throughput by reducing
--   the number of system calls made through the file descriptor. The
--   bytestring package provides an efficient monoidal datatype
--   used for serializing values directly to an output buffer, called a
--   Builder, originally implemented in the blaze-builder
--   package by Simon Meier. When compiling with bytestring
--   versions older than 0.10.4, (i.e. GHC <= 7.6) users must depend on
--   the bytestring-builder library to get the new builder
--   implementation. Since we try to maintain compatibility with the last
--   three GHC versions, the dependency on bytestring-builder can
--   be dropped after the release of GHC 7.12.
--   
--   Using this module
--   
--   Given an OutputStream taking ByteString:
--   
--   
--   someOutputStream :: OutputStream ByteString
--   
--   
--   You create a new output stream wrapping the original one that accepts
--   Builder values:
--   
--   
--   do
--       newStream <- Streams.builderStream someOutputStream
--       Streams.write (Just $ byteString "hello") newStream
--       ....
--   
--   
--   You can flush the output buffer using flush:
--   
--   
--   ....
--   Streams.write (Just flush) newStream
--   ....
--   
--   
--   As a convention, builderStream will write the empty string to
--   the wrapped OutputStream upon a builder buffer flush. Output
--   streams which receive ByteString should either ignore the empty
--   string or interpret it as a signal to flush their own buffers, as the
--   handleToOutputStream and System.IO.Streams.Zlib
--   functions do.
--   
--   Example
--   
--   
--   example :: IO [ByteString]
--   example = do
--       let l1 = intersperse " " ["the", "quick", "brown", "fox"]
--       let l2 = intersperse " " ["jumped", "over", "the"]
--       let l  = map byteString l1 ++ [flush] ++ map byteString l2
--       is          <- Streams.fromList l
--       (os0, grab) <- Streams.listOutputStream
--       os          <- Streams.builderStream os0
--       Streams.connect is os >> grab
--   
--   ghci> example
--   ["the quick brown fox","","jumped over the"]
--   
module System.IO.Streams.Builder

-- | Converts a ByteString sink into a Builder sink.
--   
--   Note that if the generated builder receives a flush, by
--   convention it will send an empty string to the supplied
--   OutputStream ByteString to indicate that any
--   output buffers are to be flushed.
builderStream :: OutputStream ByteString -> IO (OutputStream Builder)

-- | Converts a ByteString sink into a Builder sink, using
--   the supplied buffer size.
--   
--   Note that if the generated builder receives a flush, by
--   convention it will send an empty string to the supplied
--   OutputStream ByteString to indicate that any
--   output buffers are to be flushed.
--   
--   Since: 1.3.0.0.
builderStreamWithBufferSize :: Int -> OutputStream ByteString -> IO (OutputStream Builder)

-- | Unsafe variation on builderStream that reuses an existing
--   buffer for efficiency.
--   
--   NOTE: because the buffer is reused, subsequent
--   ByteString values written to the wrapped OutputString
--   will cause previous yielded strings to change. Do not retain
--   references to these ByteString values inside the
--   OutputStream you pass to this function, or you will violate
--   referential transparency.
--   
--   If you must retain copies of these values, then please use
--   copy to ensure that you have a fresh copy of the underlying
--   string.
--   
--   You can create a Buffer with newBuffer.
unsafeBuilderStream :: IO Buffer -> OutputStream ByteString -> IO (OutputStream Builder)

-- | This module provides support for parsing values from Text
--   InputStreams using attoparsec. Since: 1.4.0.0.
module System.IO.Streams.Attoparsec.Text

-- | Supplies an attoparsec Parser with an
--   InputStream, returning the final parsed value or throwing a
--   ParseException if parsing fails.
--   
--   parseFromStream consumes only as much input as necessary to
--   satisfy the Parser: any unconsumed input is pushed back onto
--   the InputStream.
--   
--   If the Parser exhausts the InputStream, the
--   end-of-stream signal is sent to attoparsec.
--   
--   Example:
--   
--   
--   ghci> import Data.Attoparsec.Text
--   ghci> is <- fromList ["12345xxx" :: Text]
--   ghci> parseFromStream (takeWhile isDigit) is
--   "12345"
--   ghci> read is
--   Just "xxx"
--   
parseFromStream :: Parser r -> InputStream Text -> IO r

-- | Given a Parser yielding values of type Maybe r,
--   transforms an InputStream over byte strings to an
--   InputStream yielding values of type r.
--   
--   If the parser yields Just x, then x will be passed
--   along downstream, and if the parser yields Nothing, that will
--   be interpreted as end-of-stream.
--   
--   Upon a parse error, parserToInputStream will throw a
--   ParseException.
--   
--   Example:
--   
--   
--   ghci> import Control.Applicative
--   ghci> import Data.Attoparsec.Text
--   ghci> is <- fromList ["1 2 3 4 5" :: Text]
--   ghci> let parser = (endOfInput >> pure Nothing) <|> (Just <$> (skipWhile isSpace *> decimal))
--   ghci> parserToInputStream parser is >>= toList
--   [1,2,3,4,5]
--   ghci> is' <- fromList ["1 2xx3 4 5" :: Text] >>= parserToInputStream parser
--   ghci> read is'
--   Just 1
--   ghci> read is'
--   Just 2
--   ghci> read is'
--   *** Exception: Parse exception: Failed reading: takeWhile1
--   
parserToInputStream :: Parser (Maybe r) -> InputStream Text -> IO (InputStream r)

-- | An exception raised when parsing fails.
data ParseException
ParseException :: String -> ParseException

-- | This module provides support for parsing values from ByteString
--   InputStreams using attoparsec. Since: 1.4.0.0.
module System.IO.Streams.Attoparsec.ByteString

-- | Supplies an attoparsec Parser with an
--   InputStream, returning the final parsed value or throwing a
--   ParseException if parsing fails.
--   
--   parseFromStream consumes only as much input as necessary to
--   satisfy the Parser: any unconsumed input is pushed back onto
--   the InputStream.
--   
--   If the Parser exhausts the InputStream, the
--   end-of-stream signal is sent to attoparsec.
--   
--   Example:
--   
--   
--   ghci> import Data.Attoparsec.ByteString.Char8
--   ghci> is <- fromList ["12345xxx" :: ByteString]
--   ghci> parseFromStream (takeWhile isDigit) is
--   "12345"
--   ghci> read is
--   Just "xxx"
--   
parseFromStream :: Parser r -> InputStream ByteString -> IO r

-- | Given a Parser yielding values of type Maybe r,
--   transforms an InputStream over byte strings to an
--   InputStream yielding values of type r.
--   
--   If the parser yields Just x, then x will be passed
--   along downstream, and if the parser yields Nothing, that will
--   be interpreted as end-of-stream.
--   
--   Upon a parse error, parserToInputStream will throw a
--   ParseException.
--   
--   Example:
--   
--   
--   ghci> import Control.Applicative
--   ghci> import Data.Attoparsec.ByteString.Char8
--   ghci> is <- fromList ["1 2 3 4 5" :: ByteString]
--   ghci> let parser = (endOfInput >> pure Nothing) <|> (Just <$> (skipWhile isSpace *> decimal))
--   ghci> parserToInputStream parser is >>= toList
--   [1,2,3,4,5]
--   ghci> is' <- fromList ["1 2xx3 4 5" :: ByteString] >>= parserToInputStream parser
--   ghci> read is'
--   Just 1
--   ghci> read is'
--   Just 2
--   ghci> read is'
--   *** Exception: Parse exception: Failed reading: takeWhile1
--   
parserToInputStream :: Parser (Maybe r) -> InputStream ByteString -> IO (InputStream r)

-- | An exception raised when parsing fails.
data ParseException
ParseException :: String -> ParseException

-- | This module is deprecated -- use
--   System.IO.Streams.Attoparsec.ByteString instead (this module simply
--   re-exports that one).
module System.IO.Streams.Attoparsec

-- | Supplies an attoparsec Parser with an
--   InputStream, returning the final parsed value or throwing a
--   ParseException if parsing fails.
--   
--   parseFromStream consumes only as much input as necessary to
--   satisfy the Parser: any unconsumed input is pushed back onto
--   the InputStream.
--   
--   If the Parser exhausts the InputStream, the
--   end-of-stream signal is sent to attoparsec.
--   
--   Example:
--   
--   
--   ghci> import Data.Attoparsec.ByteString.Char8
--   ghci> is <- fromList ["12345xxx" :: ByteString]
--   ghci> parseFromStream (takeWhile isDigit) is
--   "12345"
--   ghci> read is
--   Just "xxx"
--   
parseFromStream :: Parser r -> InputStream ByteString -> IO r

-- | Given a Parser yielding values of type Maybe r,
--   transforms an InputStream over byte strings to an
--   InputStream yielding values of type r.
--   
--   If the parser yields Just x, then x will be passed
--   along downstream, and if the parser yields Nothing, that will
--   be interpreted as end-of-stream.
--   
--   Upon a parse error, parserToInputStream will throw a
--   ParseException.
--   
--   Example:
--   
--   
--   ghci> import Control.Applicative
--   ghci> import Data.Attoparsec.ByteString.Char8
--   ghci> is <- fromList ["1 2 3 4 5" :: ByteString]
--   ghci> let parser = (endOfInput >> pure Nothing) <|> (Just <$> (skipWhile isSpace *> decimal))
--   ghci> parserToInputStream parser is >>= toList
--   [1,2,3,4,5]
--   ghci> is' <- fromList ["1 2xx3 4 5" :: ByteString] >>= parserToInputStream parser
--   ghci> read is'
--   Just 1
--   ghci> read is'
--   Just 2
--   ghci> read is'
--   *** Exception: Parse exception: Failed reading: takeWhile1
--   
parserToInputStream :: Parser (Maybe r) -> InputStream ByteString -> IO (InputStream r)

-- | An exception raised when parsing fails.
data ParseException
ParseException :: String -> ParseException

-- | List conversions and utilities.
module System.IO.Streams.List

-- | Transforms a list into an InputStream that produces no side
--   effects.
--   
--   
--   ghci> is <- Streams.fromList [1, 2]
--   ghci> replicateM 3 (Streams.read is)
--   [Just 1, Just 2, Nothing]
--   
fromList :: [c] -> IO (InputStream c)

-- | Drains an InputStream, converting it to a list. N.B. that this
--   function reads the entire InputStream strictly into memory and
--   as such is not recommended for streaming applications or where the
--   size of the input is not bounded or known.
--   
--   
--   ghci> is <- Streams.fromList [1, 2]
--   ghci> Streams.toList is
--   [1, 2]
--   
toList :: InputStream a -> IO [a]

-- | Given an IO action that requires an OutputStream, creates one
--   and captures all the output the action sends to it as a list.
--   
--   Example:
--   
--   
--   ghci> import Control.Applicative
--   ghci> (connect $ fromList ["a", "b", "c"]) >>= outputToList
--   ["a","b","c"]
--   
outputToList :: (OutputStream a -> IO b) -> IO [a]

-- | Feeds a list to an OutputStream. Does not write an
--   end-of-stream to the stream.
--   
--   
--   ghci> os <- Streams.unlines Streams.stdout >>= Streams.contramap (S.pack . show) :: IO (OutputStream Int)
--   ghci> Streams.writeList [1, 2] os
--   1
--   2
--   ghci> Streams.writeList [3, 4] os
--   3
--   4
--   
writeList :: [a] -> OutputStream a -> IO ()

-- | Splits an input stream into chunks of at most size n.
--   
--   Example:
--   
--   
--   ghci> fromList [1..14::Int] >>= chunkList 4 >>= toList
--   [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14]]
--   
chunkList :: Int -> InputStream a -> IO (InputStream [a])

-- | Splits an input stream into chunks whenever p elt count
--   returns true.
--   
--   Example:
--   
--   
--   ghci> fromList [1..14::Int] >>= chunkListWith (x n -> n>=4) >>= toList
--   [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14]]
--   ghci> fromList [a..z] >>= chunkListWith (x n -> n>=4 && x elem "aeiouy") >>= toList
--   ["abcde","fghi","jklmno","pqrstu","vwxy","z"]
--   
--   
--   Since: 1.3.3.0.
chunkListWith :: (a -> Int -> Bool) -> InputStream a -> IO (InputStream [a])

-- | Given an input stream containing lists, produces a new input stream
--   that will yield the concatenation of these lists. See concat.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList [[1,2,3::Int], [4,5,6]] >>=
--         Streams.concatLists >>=
--         Streams.toList
--   [1,2,3,4,5,6]
--   
concatLists :: InputStream [a] -> IO (InputStream a)

-- | listOutputStream returns an OutputStream which stores
--   values fed into it and an action which flushes all stored values to a
--   list.
--   
--   The flush action resets the store.
--   
--   Note that this function will buffer any input sent to it on the
--   heap. Please don't use this unless you're sure that the amount of
--   input provided is bounded and will fit in memory without issues.
--   
--   
--   ghci> (os, flush) <- Streams.listOutputStream :: IO (OutputStream Int, IO [Int])
--   ghci> Streams.writeList [1, 2] os
--   ghci> flush
--   [1, 2]
--   ghci> Streams.writeList [3, 4] os
--   ghci> flush
--   [3, 4]
--   
listOutputStream :: IO (OutputStream c, IO [c])

-- | Stream operations on ByteString.
module System.IO.Streams.ByteString

-- | Wraps an InputStream, counting the number of bytes produced by
--   the stream as a side effect. Produces a new InputStream as well
--   as an IO action to retrieve the count of bytes produced.
--   
--   Strings pushed back to the returned InputStream will be pushed
--   back to the original stream, and the count of produced bytes will be
--   subtracted accordingly.
--   
--   Example:
--   
--   
--   ghci> is <- Streams.fromList ["abc", "def", "ghi"::ByteString]
--   ghci> (is', getCount) <- Streams.countInput is
--   ghci> Streams.read is'
--   Just "abc"
--   ghci> getCount
--   3
--   ghci> Streams.unRead "bc" is'
--   ghci> getCount
--   1
--   ghci> Streams.peek is
--   Just "bc"
--   ghci> Streams.toList is'
--   ["bc","def","ghi"]
--   ghci> getCount
--   9
--   
countInput :: InputStream ByteString -> IO (InputStream ByteString, IO Int64)

-- | Wraps an OutputStream, counting the number of bytes consumed by
--   the stream as a side effect. Produces a new OutputStream as
--   well as an IO action to retrieve the count of bytes consumed.
--   
--   Example:
--   
--   
--   ghci> (os :: OutputStream ByteString, getList) <- Streams.listOutputStream
--   ghci> (os', getCount) <- Streams.countOutput os
--   ghci> Streams.fromList ["abc", "def", "ghi"] >>= Streams.connectTo os'
--   ghci> getList
--   ["abc","def","ghi"]
--   ghci> getCount
--   9
--   
countOutput :: OutputStream ByteString -> IO (OutputStream ByteString, IO Int64)

-- | Creates an InputStream from a ByteString.
fromByteString :: ByteString -> IO (InputStream ByteString)

-- | Creates an InputStream from a lazy ByteString.
fromLazyByteString :: ByteString -> IO (InputStream ByteString)

-- | Reads an n-byte ByteString from an input stream. Throws a
--   ReadTooShortException if fewer than n bytes were
--   available.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList ["long string"] >>= Streams.readExactly 6
--   "long s"
--   ghci> Streams.fromList ["short"] >>= Streams.readExactly 6
--   *** Exception: Short read, expected 6 bytes
--   
readExactly :: Int -> InputStream ByteString -> IO ByteString

-- | Takes from a stream until the given predicate is no longer satisfied.
--   Returns Nothing on end-of-stream, or Just "" if the predicate
--   is never satisfied. See takeWhile and takeWhile.
--   
--   Example:
--   
--   
--   ghci> Streams.fromList ["Hello, world!"] >>= Streams.takeBytesWhile (/= ',')
--   Just "Hello"
--   ghci> import Data.Char
--   ghci> Streams.fromList ["7 Samurai"] >>= Streams.takeBytesWhile isAlpha
--   Just ""
--   ghci> Streams.fromList [] >>= Streams.takeBytesWhile isAlpha
--   Nothing
--   
takeBytesWhile :: (Char -> Bool) -> InputStream ByteString -> IO (Maybe ByteString)

-- | Writes a lazy ByteString to an OutputStream.
--   
--   Example:
--   
--   
--   ghci> Streams.writeLazyByteString "Test\n" Streams.stdout
--   Test
--   
writeLazyByteString :: ByteString -> OutputStream ByteString -> IO ()

-- | Splits an InputStream over ByteStrings using a delimiter
--   predicate.
--   
--   Note that:
--   
--   
--   
- data pushed back with unRead is *not* propagated upstream
--   here.
--   
- the resulting InputStream may hold an unbounded amount of
--   the bytestring in memory waiting for the function to return true, so
--   this function should not be used in unsafe contexts.
--   
- the delimiter is NOT included in the output.
--   
- consecutive delimiters are not merged.
--   
- if the input ends in the delimiter, a final empty string is
--   not emitted. (/Since: 1.5.0.0. Previous versions had the
--   opposite behaviour, which was changed to match lines./)
--   
--   
--   Example:
--   
--   
--   ghci> Streams.fromList ["the quick br", "own  fox"::ByteString] >>=
--         Streams.splitOn (== ' ') >>= Streams.toList
--   ["the","quick","brown","","fox"]
--   
splitOn :: (Char -> Bool) -> InputStream ByteString -> IO (InputStream ByteString)

-- | Splits a bytestring InputStream into lines. See splitOn
--   and lines.
--   
--   Example:
--   
--   
--   ghci> is <- Streams.fromList ["Hello,\n world!"] >>= Streams.lines
--   ghci> replicateM 3 (Streams.read is)
--   [Just "Hello", Just ", world!", Nothing]
--   
--   
--   Note that this may increase the chunk size if the input contains
--   extremely long lines.
lines :: InputStream ByteString -> IO (InputStream ByteString)

-- | Intersperses string chunks sent to the given OutputStream with
--   newlines. See intersperse and unlines.
--   
--   
--   ghci> os <- Streams.unlines Streams.stdout
--   ghci> Streams.write (Just "Hello,") os
--   Hello
--   ghci> Streams.write Nothing os
--   ghci> Streams.write (Just "world!") os
--   world!
--   
unlines :: OutputStream ByteString -> IO (OutputStream ByteString)

-- | Splits a bytestring InputStream into words. See splitOn
--   and words.
--   
--   Example:
--   
--   
--   ghci> is <- Streams.fromList ["Hello, world!"] >>= Streams.words
--   ghci> replicateM 3 (Streams.read is)
--   [Just "Hello,", Just "world!", Nothing]
--   
--   
--   Note that this may increase the chunk size if the input contains
--   extremely long words.
words :: InputStream ByteString -> IO (InputStream ByteString)

-- | Intersperses string chunks sent to the given OutputStream with
--   spaces. See intersperse and unwords.
--   
--   
--   ghci> os <- Streams.unwords Streams.stdout
--   ghci> forM_ [Just "Hello,", Nothing, Just "world!\n"] $ w -> Streams.write w os
--   Hello, world!
--   
unwords :: OutputStream ByteString -> IO (OutputStream ByteString)

-- | Wraps an OutputStream, producing a new stream that will pass
--   along at most n bytes to the wrapped stream, throwing any
--   subsequent input away.
--   
--   Example:
--   
--   
--   ghci> (os :: OutputStream ByteString, getList) <- Streams.listOutputStream
--   ghci> os' <- Streams.giveBytes 6 os
--   ghci> Streams.fromList ["long ", "string"] >>= Streams.connectTo os'
--   ghci> getList
--   ["long ","s"]
--   
giveBytes :: Int64 -> OutputStream ByteString -> IO (OutputStream ByteString)

-- | Wraps an OutputStream, producing a new stream that will pass
--   along exactly n bytes to the wrapped stream. If the stream is
--   sent more or fewer than the given number of bytes, the resulting
--   stream will throw an exception (either
--   TooFewBytesWrittenException or
--   TooManyBytesWrittenException) during a call to write.
--   
--   Example:
--   
--   
--   ghci> is <- Streams.fromList ["ok"]
--   ghci> Streams.outputToList (Streams.giveExactly 2 >=> Streams.connect is)
--   ["ok"]
--   ghci> is <- Streams.fromList ["ok"]
--   ghci> Streams.outputToList (Streams.giveExactly 1 >=> Streams.connect is)
--   *** Exception: Too many bytes written
--   ghci> is <- Streams.fromList ["ok"]
--   ghci> Streams.outputToList (Streams.giveExactly 3 >=> Streams.connect is)
--   *** Exception: Too few bytes written
--   
giveExactly :: Int64 -> OutputStream ByteString -> IO (OutputStream ByteString)

-- | Wraps an InputStream, producing a new InputStream that
--   will produce at most n bytes, subsequently yielding
--   end-of-stream forever.
--   
--   Strings pushed back to the returned InputStream will be
--   propagated upstream, modifying the count of taken bytes accordingly.
--   
--   Example:
--   
--   
--   ghci> is <- Streams.fromList ["truncated", " string"::ByteString]
--   ghci> is' <- Streams.takeBytes 9 is
--   ghci> Streams.read is'
--   Just "truncated"
--   ghci> Streams.read is'
--   Nothing
--   ghci> Streams.peek is
--   Just " string"
--   ghci> Streams.unRead "cated" is'
--   ghci> Streams.peek is
--   Just "cated"
--   ghci> Streams.peek is'
--   Just "cated"
--   ghci> Streams.read is'
--   Just "cated"
--   ghci> Streams.read is'
--   Nothing
--   ghci> Streams.read is
--   Just " string"
--   
takeBytes :: Int64 -> InputStream ByteString -> IO (InputStream ByteString)

-- | Like Streams.takeBytes, but throws
--   ReadTooShortException when there aren't enough bytes present on
--   the source.
takeExactly :: Int64 -> InputStream ByteString -> IO (InputStream ByteString)

-- | Wraps an OutputStream, producing a new stream that will pass
--   along at most n bytes to the wrapped stream. If more than
--   n bytes are sent to the outer stream, a
--   TooManyBytesWrittenException will be thrown.
--   
--   Note: if more than n bytes are sent to the outer
--   stream, throwIfConsumesMoreThan will not necessarily send the
--   first n bytes through to the wrapped stream before throwing
--   the exception.
--   
--   Example:
--   
--   
--   ghci> (os :: OutputStream ByteString, getList) <- Streams.listOutputStream
--   ghci> os' <- Streams.throwIfConsumesMoreThan 5 os
--   ghci> Streams.fromList ["short"] >>= Streams.connectTo os'
--   ghci> getList
--   ["short"]
--   ghci> os'' <- Streams.throwIfConsumesMoreThan 5 os
--   ghci> Streams.fromList ["long", "string"] >>= Streams.connectTo os''
--   *** Exception: Too many bytes written
--   
throwIfConsumesMoreThan :: Int64 -> OutputStream ByteString -> IO (OutputStream ByteString)

-- | Wraps an InputStream. If more than n bytes are
--   produced by this stream, read will throw a
--   TooManyBytesReadException.
--   
--   If a chunk yielded by the input stream would result in more than
--   n bytes being produced, throwIfProducesMoreThan will
--   cut the generated string such that exactly n bytes are
--   yielded by the returned stream, and the subsequent read will
--   throw an exception. Example:
--   
--   
--   ghci> is <- Streams.fromList ["abc", "def", "ghi"] >>=
--               Streams.throwIfProducesMoreThan 5
--   ghci> replicateM 2 (read is)
--   [Just "abc",Just "de"]
--   ghci> Streams.read is
--   *** Exception: Too many bytes read
--   
--   
--   Strings pushed back to the returned InputStream will be
--   propagated upstream, modifying the count of taken bytes accordingly.
--   Example:
--   
--   
--   ghci> is  <- Streams.fromList ["abc", "def", "ghi"]
--   ghci> is' <- Streams.throwIfProducesMoreThan 5 is
--   ghci> Streams.read is'
--   Just "abc"
--   ghci> Streams.unRead "xyz" is'
--   ghci> Streams.peek is
--   Just "xyz"
--   ghci> Streams.read is
--   Just "xyz"
--   ghci> Streams.read is
--   Just "de"
--   ghci> Streams.read is
--   *** Exception: Too many bytes read
--   
throwIfProducesMoreThan :: Int64 -> InputStream ByteString -> IO (InputStream ByteString)

-- | Rate-limits an input stream. If the input stream is not read from
--   faster than the given rate, reading from the wrapped stream will throw
--   a RateTooSlowException.
--   
--   Strings pushed back to the returned InputStream will be
--   propagated up to the original stream.
throwIfTooSlow :: IO () -> Double -> Int -> InputStream ByteString -> IO (InputStream ByteString)

-- | MatchInfo provides match information when performing string
--   search.
data MatchInfo
Match :: {-# UNPACK #-} !ByteString -> MatchInfo
NoMatch :: {-# UNPACK #-} !ByteString -> MatchInfo

-- | Given a ByteString to look for (the "needle") and an
--   InputStream, produces a new InputStream which yields
--   data of type MatchInfo.
--   
--   Example:
--   
--   
--   ghci> fromList ["food", "oof", "oodles", "ok"] >>=
--         search "foo" >>= toList
--   [Match "foo",NoMatch "d",NoMatch "oo",Match "foo",NoMatch "dlesok"]
--   
--   
--   Uses the Boyer-Moore-Horspool algorithm
--   (http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore%E2%80%93Horspool_algorithm).
search :: ByteString -> InputStream ByteString -> IO (InputStream MatchInfo)

-- | Thrown by throwIfTooSlow if input is not being produced fast
--   enough by the given InputStream.
data RateTooSlowException

-- | Thrown by readExactly and takeExactly when not enough
--   bytes were available on the input.
data ReadTooShortException

-- | Thrown by throwIfProducesMoreThan when too many bytes were read
--   from the original InputStream.
data TooManyBytesReadException

-- | Thrown by throwIfConsumesMoreThan when too many bytes were sent
--   to the produced OutputStream.
data TooManyBytesWrittenException

-- | Thrown by giveExactly when too few bytes were written to the
--   produced OutputStream.
data TooFewBytesWrittenException
instance GHC.Internal.Exception.Type.Exception System.IO.Streams.ByteString.RateTooSlowException
instance GHC.Internal.Exception.Type.Exception System.IO.Streams.ByteString.ReadTooShortException
instance GHC.Internal.Exception.Type.Exception System.IO.Streams.ByteString.TooFewBytesWrittenException
instance GHC.Internal.Exception.Type.Exception System.IO.Streams.ByteString.TooManyBytesReadException
instance GHC.Internal.Exception.Type.Exception System.IO.Streams.ByteString.TooManyBytesWrittenException
instance GHC.Internal.Show.Show System.IO.Streams.ByteString.RateTooSlowException
instance GHC.Internal.Show.Show System.IO.Streams.ByteString.ReadTooShortException
instance GHC.Internal.Show.Show System.IO.Streams.ByteString.TooFewBytesWrittenException
instance GHC.Internal.Show.Show System.IO.Streams.ByteString.TooManyBytesReadException
instance GHC.Internal.Show.Show System.IO.Streams.ByteString.TooManyBytesWrittenException

-- | Converting network Sockets to streams.
module System.IO.Streams.Network

-- | Converts a Socket to an InputStream /
--   OutputStream pair. Note that, as is usually the case in
--   io-streams, writing a Nothing to the generated
--   OutputStream does not cause the underlying Socket to be
--   closed.
socketToStreams :: Socket -> IO (InputStream ByteString, OutputStream ByteString)

-- | Converts a Socket to an InputStream /
--   OutputStream pair, with control over the size of the receive
--   buffers. Note that, as is usually the case in io-streams,
--   writing a Nothing to the generated OutputStream does not
--   cause the underlying Socket to be closed.
socketToStreamsWithBufferSize :: Int -> Socket -> IO (InputStream ByteString, OutputStream ByteString)

-- | A module adapting the functions from System.Process to work
--   with io-streams.
module System.IO.Streams.Process

-- | Waits for the specified process to terminate, and returns its exit
--   code. On Unix systems, may throw UserInterrupt when using
--   delegate_ctlc.
--   
--   GHC Note: in order to call waitForProcess without blocking
--   all the other threads in the system, you must compile the program with
--   -threaded.
--   
--   Note that it is safe to call waitForProcess for the same
--   process in multiple threads. When the process ends, threads blocking
--   on this call will wake in FIFO order. When using delegate_ctlc
--   and the process is interrupted, only the first waiting thread will
--   throw UserInterrupt.
--   
--   (Since: 1.2.0.0) On Unix systems, a negative value
--   ExitFailure -signum indicates that the child
--   was terminated by signal signum. The signal numbers
--   are platform-specific, so to test for a specific signal use the
--   constants provided by System.Posix.Signals in the unix
--   package. Note: core dumps are not reported, use
--   System.Posix.Process if you need this detail.
waitForProcess :: ProcessHandle -> IO ExitCode

-- | This is the most general way to spawn an external process. The process
--   can be a command line to be executed by a shell or a raw command with
--   a list of arguments. The stdin, stdout, and stderr streams of the new
--   process may individually be attached to new pipes, to existing
--   Handles, or just inherited from the parent (the default.)
--   
--   The details of how to create the process are passed in the
--   CreateProcess record. To make it easier to construct a
--   CreateProcess, the functions proc and shell are
--   supplied that fill in the fields with default values which can be
--   overriden as needed.
--   
--   createProcess returns (mb_stdin_hdl,
--   mb_stdout_hdl, mb_stderr_hdl, ph), where
--   
--   
--   
- if std_in == CreatePipe, then
--   mb_stdin_hdl will be Just h, where
--   h is the write end of the pipe connected to the child
--   process's stdin.
--   
- otherwise, mb_stdin_hdl == Nothing
--   
--   
--   Similarly for mb_stdout_hdl and
--   mb_stderr_hdl.
--   
--   For example, to execute a simple ls command:
--   
--   
--   r <- createProcess (proc "ls" [])
--   
--   
--   To create a pipe from which to read the output of ls:
--   
--   
--   (_, Just hout, _, _) <-
--       createProcess (proc "ls" []){ std_out = CreatePipe }
--   
--   
--   To also set the directory in which to run ls:
--   
--   
--   (_, Just hout, _, _) <-
--       createProcess (proc "ls" []){ cwd = Just "/home/bob",
--                                     std_out = CreatePipe }
--   
--   
--   Note that Handles provided for std_in,
--   std_out, or std_err via the UseHandle
--   constructor will be closed by calling this function. This is not
--   always the desired behavior. In cases where you would like to leave
--   the Handle open after spawning the child process, please use
--   createProcess_ instead. All created Handles are
--   initially in text mode; if you need them to be in binary mode then use
--   hSetBinaryMode.
--   
--   ph contains a handle to the running process. On
--   Windows use_process_jobs can be set in CreateProcess in order
--   to create a Win32 Job object to monitor a process tree's progress. If
--   it is set then that job is also returned inside ph.
--   ph can be used to kill all running sub-processes. This
--   feature has been available since 1.5.0.0.
createProcess :: CreateProcess -> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)

-- | A handle to a process, which can be used to wait for termination of
--   the process using waitForProcess.
--   
--   None of the process-creation functions in this library wait for
--   termination: they all return a ProcessHandle which may be used
--   to wait for the process later.
--   
--   On Windows a second wait method can be used to block for event
--   completion. This requires two handles. A process job handle and a
--   events handle to monitor.
data ProcessHandle
data StdStream

-- | Inherit Handle from parent
Inherit :: StdStream

-- | Use the supplied Handle
UseHandle :: Handle -> StdStream

-- | Create a new pipe. The returned Handle will use the default
--   encoding and newline translation mode (just like Handles
--   created by openFile).
CreatePipe :: StdStream

-- | Close the stream's file descriptor without passing a Handle. On POSIX
--   systems this may lead to strange behavior in the child process because
--   attempting to read or write after the file has been closed throws an
--   error. This should only be used with child processes that don't use
--   the file descriptor at all. If you wish to ignore the child process's
--   output you should either create a pipe and drain it manually or pass a
--   Handle that writes to /dev/null.
NoStream :: StdStream
data CmdSpec

-- | A command line to execute using the shell
ShellCommand :: String -> CmdSpec

-- | The name of an executable with a list of arguments
--   
--   The FilePath argument names the executable, and is interpreted
--   according to the platform's standard policy for searching for
--   executables. Specifically:
--   
--   
--   
- on Unix systems the execvp(3) semantics is used, where if
--   the executable filename does not contain a slash (/) then the
--   PATH environment variable is searched for the
--   executable.
--   
- on Windows systems the Win32 CreateProcess semantics is
--   used. Briefly: if the filename does not contain a path, then the
--   directory containing the parent executable is searched, followed by
--   the current directory, then some standard locations, and finally the
--   current PATH. An .exe extension is added if the
--   filename does not already have an extension. For full details see the
--   documentation for the Windows SearchPath API.
--   
--   
--   Windows does not have a mechanism for passing multiple arguments. When
--   using RawCommand on Windows, the command line is serialised
--   into a string, with arguments quoted separately. Command line parsing
--   is up individual programs, so the default behaviour may not work for
--   some programs. If you are not getting the desired results, construct
--   the command line yourself and use ShellCommand.
RawCommand :: FilePath -> [String] -> CmdSpec
data CreateProcess
CreateProcess :: CmdSpec -> Maybe FilePath -> Maybe [(String, String)] -> StdStream -> StdStream -> StdStream -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe GroupID -> Maybe UserID -> Bool -> CreateProcess

-- | Sends an interrupt signal to the process group of the given process.
--   
--   On Unix systems, it sends the group the SIGINT signal.
--   
--   On Windows systems, it generates a CTRL_BREAK_EVENT and will only work
--   for processes created using createProcess and setting the
--   create_group flag
interruptProcessGroupOf :: ProcessHandle -> IO ()

-- | Construct a CreateProcess record for passing to
--   createProcess, representing a raw command with arguments.
--   
--   See RawCommand for precise semantics of the specified
--   FilePath.
proc :: FilePath -> [String] -> CreateProcess

-- | Construct a CreateProcess record for passing to
--   createProcess, representing a command to be passed to the
--   shell.
shell :: String -> CreateProcess

-- | readProcess forks an external process, reads its standard
--   output strictly, blocking until the process terminates, and returns
--   the output string. The external process inherits the standard error.
--   
--   If an asynchronous exception is thrown to the thread executing
--   readProcess, the forked process will be terminated and
--   readProcess will wait (block) until the process has been
--   terminated.
--   
--   Output is returned strictly, so this is not suitable for launching
--   processes that require interaction over the standard file streams.
--   
--   This function throws an IOError if the process ExitCode
--   is anything other than ExitSuccess. If instead you want to get
--   the ExitCode then use readProcessWithExitCode.
--   
--   Users of this function should compile with -threaded if they
--   want other Haskell threads to keep running while waiting on the result
--   of readProcess.
--   
--   
--   > readProcess "date" [] []
--   "Thu Feb  7 10:03:39 PST 2008\n"
--   
--   
--   The arguments are:
--   
--   
--   
- The command to run, which must be in the $PATH, or an absolute or
--   relative path
--   
- A list of separate command line arguments to the program. See
--   RawCommand for further discussion of Windows semantics.
--   
- A string to pass on standard input to the forked process.
--   
readProcess :: FilePath -> [String] -> String -> IO String

-- | readProcessWithExitCode is like readProcess but with
--   two differences:
--   
--   
--   
- it returns the ExitCode of the process, and does not throw
--   any exception if the code is not ExitSuccess.
--   
- it reads and returns the output from process' standard error
--   handle, rather than the process inheriting the standard error
--   handle.
--   
--   
--   On Unix systems, see waitForProcess for the meaning of exit
--   codes when the process died as the result of a signal.
readProcessWithExitCode :: FilePath -> [String] -> String -> IO (ExitCode, String, String)

-- | Given a program p and arguments args,
--   showCommandForUser p args returns a string
--   suitable for pasting into /bin/sh (on Unix systems) or
--   CMD.EXE (on Windows).
showCommandForUser :: FilePath -> [String] -> String

-- | This is a non-blocking version of waitForProcess. If the
--   process is still running, Nothing is returned. If the process
--   has exited, then Just e is returned where e
--   is the exit code of the process.
--   
--   On Unix systems, see waitForProcess for the meaning of exit
--   codes when the process died as the result of a signal. May throw
--   UserInterrupt when using delegate_ctlc.
getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)

-- | Attempts to terminate the specified process. This function should not
--   be used under normal circumstances - no guarantees are given regarding
--   how cleanly the process is terminated. To check whether the process
--   has indeed terminated, use getProcessExitCode.
--   
--   On Unix systems, terminateProcess sends the process the SIGTERM
--   signal. On Windows systems, if use_process_jobs is True
--   then the Win32 TerminateJobObject function is called to kill
--   all processes associated with the job and passing the exit code of 1
--   to each of them. Otherwise if use_process_jobs is False
--   then the Win32 TerminateProcess function is called, passing
--   an exit code of 1.
--   
--   Note: on Windows, if the process was a shell command created by
--   createProcess with shell, or created by
--   runCommand or runInteractiveCommand, then
--   terminateProcess will only terminate the shell, not the command
--   itself. On Unix systems, both processes are in a process group and
--   will be terminated together.
terminateProcess :: ProcessHandle -> IO ()

-- | Runs a command using the shell.
runCommand :: String -> IO ProcessHandle

-- | Computation system cmd returns the exit code produced when
--   the operating system runs the shell command cmd.
--   
--   This computation may fail with one of the following IOErrorType
--   exceptions:
--   
--   
--   
- PermissionDenied The process has insufficient
--   privileges to perform the operation.
--   
- ResourceExhausted Insufficient resources are
--   available to perform the operation.
--   
- UnsupportedOperation The implementation does not
--   support system calls.
--   
--   
--   On Windows, system passes the command to the Windows command
--   interpreter (CMD.EXE or COMMAND.COM), hence Unixy
--   shell tricks will not work.
--   
--   On Unix systems, see waitForProcess for the meaning of exit
--   codes when the process died as the result of a signal.
system :: String -> IO ExitCode

-- | The computation rawSystem cmd args runs
--   the operating system command cmd in such a way that it
--   receives as arguments the args strings exactly as
--   given, with no funny escaping or shell meta-syntax expansion. It will
--   therefore behave more portably between operating systems than
--   system.
--   
--   The return codes and possible failures are the same as for
--   system.
rawSystem :: String -> [String] -> IO ExitCode

-- | Runs a command using the shell, and returns streams that may be used
--   to communicate with the process via its stdin, stdout, and stderr
--   respectively.
--   
--   The streams returned by this command are guarded by locks and are
--   therefore safe to use in multithreaded code.
--   
--   Since: 1.0.2.0
runInteractiveCommand :: String -> IO (OutputStream ByteString, InputStream ByteString, InputStream ByteString, ProcessHandle)

-- | Runs a raw command, and returns streams that may be used to
--   communicate with the process via its stdin, stdout
--   and stderr respectively.
--   
--   For example, to start a process and feed a string to its stdin:
--   
--   
--   (inp,out,err,pid) <- runInteractiveProcess "..."
--   forkIO (Streams.write (Just str) inp)
--   
--   
--   The streams returned by this command are guarded by locks and are
--   therefore safe to use in multithreaded code.
--   
--   Since: 1.0.2.0
runInteractiveProcess :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO (OutputStream ByteString, InputStream ByteString, InputStream ByteString, ProcessHandle)

-- | Stream primitives for decoding and encoding Text values in
--   UTF-8 format.
module System.IO.Streams.Text

-- | Decode an InputStream of ByteStrings in UTF-8 format
--   into an InputStream of Text values. If decoding fails,
--   will throw an exception. See
--   Data.Text.Encoding.decodeUtf8.
decodeUtf8 :: InputStream ByteString -> IO (InputStream Text)

-- | Decode an InputStream of ByteStrings in UTF-8 format
--   into an InputStream of Text values. If decoding fails,
--   invokes the given OnDecodeError function to decide what to do.
--   See Data.Text.Encoding.decodeUtf8With.
decodeUtf8With :: OnDecodeError -> InputStream ByteString -> IO (InputStream Text)

-- | Convert an OutputStream taking ByteStrings to an
--   OutputStream that takes Text, encoding the data as
--   UTF-8. See Data.Text.Encoding.encodeUtf8.
encodeUtf8 :: OutputStream ByteString -> IO (OutputStream Text)

module System.IO.Streams.Tutorial

-- | Vector conversions and utilities.
module System.IO.Streams.Vector

-- | Transforms a vector into an InputStream that yields each of the
--   values in the vector in turn.
--   
--   
--   ghci> import Control.Monad
--   ghci> import qualified System.IO.Streams as Streams
--   ghci> import qualified Data.Vector as V
--   ghci> let v = V.fromList [1, 2]
--   ghci> is <- Streams.fromVector v
--   ghci> replicateM 3 (Streams.read is)
--   [Just 1,Just 2,Nothing]
--   
fromVector :: Vector v a => v a -> IO (InputStream a)

-- | Drains an InputStream, converting it to a vector. Note that
--   this function reads the entire InputStream strictly into memory
--   and as such is not recommended for streaming applications or where the
--   size of the input is not bounded or known.
--   
--   
--   ghci> is <- Streams.fromList [(1::Int)..4]
--   ghci> Streams.toVector is :: IO (V.Vector Int)
--   fromList [1,2,3,4]
--   
toVector :: Vector v a => InputStream a -> IO (v a)

-- | Like toVector, but allows control over how large the vector
--   buffer is to start with.
toVectorSized :: Vector v a => Int -> InputStream a -> IO (v a)

-- | Given an IO action that requires an OutputStream, creates one
--   and captures all the output the action sends to it as a vector.
--   
--   Example:
--   
--   
--   ghci> ((connect $ fromList [1, 2, 3]) >>= outputToVector)
--             :: IO (Vector Int)
--   fromList [1,2,3]
--   
outputToVector :: Vector v a => (OutputStream a -> IO b) -> IO (v a)

-- | Like outputToVector, but allows control over how large the
--   vector buffer is to start with.
outputToVectorSized :: Vector v a => Int -> (OutputStream a -> IO b) -> IO (v a)

-- | Drains an InputStream, converting it to a mutable vector. Note
--   that this function reads the entire InputStream strictly into
--   memory and as such is not recommended for streaming applications or
--   where the size of the input is not bounded or known.
toMutableVector :: MVector v a => InputStream a -> IO (v (PrimState IO) a)

-- | Like toMutableVector, but allows control over how large the
--   vector buffer is to start with.
toMutableVectorSized :: MVector v a => Int -> InputStream a -> IO (v (PrimState IO) a)

-- | Given an IO action that requires an OutputStream, creates one
--   and captures all the output the action sends to it as a mutable
--   vector.
--   
--   Example:
--   
--   
--   ghci> import Control.Applicative
--   ghci> (connect <$> fromList [1, 2, 3::Int])
--          >>= outputToMutableVector
--          >>= V.freeze
--   fromList [1,2,3]
--   
outputToMutableVector :: MVector v a => (OutputStream a -> IO b) -> IO (v (PrimState IO) a)

-- | Like outputToMutableVector, but allows control over how large
--   the vector buffer is to start with.
outputToMutableVectorSized :: MVector v a => Int -> (OutputStream a -> IO b) -> IO (v (PrimState IO) a)

-- | Feeds a vector to an OutputStream. Does not write an
--   end-of-stream to the stream.
--   
--   
--   ghci> let v = V.fromList [1..4] :: V.Vector Int
--   ghci> os <- Streams.unlines Streams.stdout >>= Streams.contramap (S.pack . show) :: IO (OutputStream Int)
--   ghci> Streams.writeVector v os
--   1
--   2
--   3
--   4
--   
writeVector :: Vector v a => v a -> OutputStream a -> IO ()

-- | Splits an input stream into chunks of at most size n.
--   
--   Example:
--   
--   
--   ghci> (fromList [1..14::Int] >>= chunkVector 4 >>= toList)
--            :: IO [Vector Int]
--   [fromList [1,2,3,4],fromList [5,6,7,8],fromList [9,10,11,12],fromList [13,14]]
--   
chunkVector :: Vector v a => Int -> InputStream a -> IO (InputStream (v a))

-- | vectorOutputStream returns an OutputStream which stores
--   values fed into it and an action which flushes all stored values to a
--   vector.
--   
--   The flush action resets the store.
--   
--   Note that this function will buffer any input sent to it on the
--   heap. Please don't use this unless you're sure that the amount of
--   input provided is bounded and will fit in memory without issues.
--   
--   
--   ghci> (os, flush) <- Streams.vectorOutputStream :: IO (OutputStream Int, IO (V.Vector Int))
--   ghci> Streams.write (Just 1) os
--   ghci> Streams.write (Just 2) os
--   ghci> flush
--   fromList [1,2]
--   ghci> Streams.write (Just 3) os
--   ghci> Streams.write Nothing  os
--   ghci> Streams.write (Just 4) os
--   ghci> flush
--   fromList [3]
--   
vectorOutputStream :: Vector v c => IO (OutputStream c, IO (v c))

-- | Like vectorOutputStream, but allows control over how large the
--   vector buffer is to start with.
vectorOutputStreamSized :: Vector v c => Int -> IO (OutputStream c, IO (v c))

-- | mutableVectorOutputStream returns an OutputStream which
--   stores values fed into it and an action which flushes all stored
--   values to a vector.
--   
--   The flush action resets the store.
--   
--   Note that this function will buffer any input sent to it on the
--   heap. Please don't use this unless you're sure that the amount of
--   input provided is bounded and will fit in memory without issues.
mutableVectorOutputStream :: MVector v c => IO (OutputStream c, IO (v (PrimState IO) c))

-- | Like mutableVectorOutputStream, but allows control over how
--   large the vector buffer is to start with.
mutableVectorOutputStreamSized :: MVector v c => Int -> IO (OutputStream c, IO (v (PrimState IO) c))

-- | Interface to zlib and gzip compression for
--   Bytestrings and Builders
module System.IO.Streams.Zlib

-- | Decompress an InputStream of strict ByteStrings from the
--   gzip format
gunzip :: InputStream ByteString -> IO (InputStream ByteString)

-- | Decompress an InputStream of strict ByteStrings from the
--   zlib format
decompress :: InputStream ByteString -> IO (InputStream ByteString)

-- | Convert an OutputStream that consumes compressed
--   ByteStrings into an OutputStream that consumes
--   uncompressed ByteStrings in the gzip format
gzip :: CompressionLevel -> OutputStream ByteString -> IO (OutputStream ByteString)

-- | Convert an OutputStream that consumes compressed
--   ByteStrings into an OutputStream that consumes
--   uncompressed ByteStrings in the zlib format
compress :: CompressionLevel -> OutputStream ByteString -> IO (OutputStream ByteString)

-- | Convert an OutputStream that consumes compressed
--   Builders into an OutputStream that consumes uncompressed
--   Builders in the gzip format
gzipBuilder :: CompressionLevel -> OutputStream Builder -> IO (OutputStream Builder)

-- | Convert an OutputStream that consumes compressed
--   Builders into an OutputStream that consumes uncompressed
--   Builders in the zlib format
compressBuilder :: CompressionLevel -> OutputStream Builder -> IO (OutputStream Builder)

-- | Parameter that defines the tradeoff between speed and compression
--   ratio
newtype CompressionLevel
CompressionLevel :: Int -> CompressionLevel

-- | A compression level that balances speed with compression ratio
defaultCompressionLevel :: CompressionLevel
instance GHC.Classes.Eq System.IO.Streams.Zlib.CompressionLevel
instance GHC.Internal.Num.Num System.IO.Streams.Zlib.CompressionLevel
instance GHC.Internal.Read.Read System.IO.Streams.Zlib.CompressionLevel
instance GHC.Internal.Show.Show System.IO.Streams.Zlib.CompressionLevel

-- | This module is a top-level convenience module which re-exports most of
--   the io-streams library.
--   
--   It is recommended to import this module qualified, as follows:
--   
--   
--   import           System.IO.Streams (Generator, InputStream, OutputStream)
--   import qualified System.IO.Streams as Streams
--   
--   
--   For an in-depth tutorial on how to use io-streams, please see
--   the System.IO.Streams.Tutorial module.
--   
--   Is there a function missing from this library? Interested in
--   contributing? Send a pull request to
--   http://github.com/snapframework/io-streams.
module System.IO.Streams

-- | An InputStream generates values of type c in the
--   IO monad.
--   
--   Two primitive operations are defined on InputStream:
--   
--   
--   
- read :: InputStream c -> IO
--   (Maybe c) reads a value from the stream, where "end of
--   stream" is signaled by read returning Nothing.
--   
- unRead :: c -> InputStream c -> IO
--   () "pushes back" a value to the stream.
--   
--   
--   It is intended that InputStreams obey the following law:
--   
--   
--   unRead c stream >> read stream === return (Just c)
--   
data InputStream a

-- | An OutputStream consumes values of type c in the
--   IO monad. The only primitive operation defined on
--   OutputStream is:
--   
--   
--   
- 
write :: Maybe c -> OutputStream c
--   -> IO ()

--   
--   
--   Values of type c are written in an OutputStream by
--   wrapping them in Just, and the end of the stream is indicated
--   by supplying Nothing.
--   
--   If you supply a value after a Nothing, the behavior is defined
--   by the implementer of the given OutputStream. (All
--   OutputStream definitions in this library will simply discard
--   the extra input.)
data OutputStream a

-- | Creates an InputStream from a value-producing action.
--   
--   (makeInputStream m) calls the action m each time you
--   request a value from the InputStream. The given action is
--   extended with the default pushback mechanism (see
--   System.IO.Streams.Internal#pushback).
makeInputStream :: IO (Maybe a) -> IO (InputStream a)

-- | Creates an OutputStream from a value-consuming action.
--   
--   (makeOutputStream f) runs the computation f on each
--   value fed to it.
--   
--   Since version 1.2.0.0, makeOutputStream also ensures that
--   output streams no longer receive data once EOF is received (i.e. you
--   can now assume that makeOutputStream will feed your function
--   Nothing at most once.)
makeOutputStream :: (Maybe a -> IO ()) -> IO (OutputStream a)

-- | Reads one value from an InputStream.
--   
--   Returns either a value wrapped in a Just, or Nothing if
--   the end of the stream is reached.
read :: InputStream a -> IO (Maybe a)

-- | Pushes a value back onto an input stream. read and
--   unRead should satisfy the following law, with the possible
--   exception of side effects:
--   
--   
--   Streams.unRead c stream >> Streams.read stream === return (Just c)
--   
--   
--   Note that this could be used to add values back to the stream that
--   were not originally drawn from the stream.
unRead :: a -> InputStream a -> IO ()

-- | Observes the first value from an InputStream without consuming
--   it.
--   
--   Returns Nothing if the InputStream is empty. peek
--   satisfies the following law:
--   
--   
--   Streams.peek stream >> Streams.read stream === Streams.read stream
--   
peek :: InputStream a -> IO (Maybe a)

-- | Feeds a value to an OutputStream. Values of type c are
--   written in an OutputStream by wrapping them in Just, and
--   the end of the stream is indicated by supplying Nothing.
write :: Maybe a -> OutputStream a -> IO ()

-- | Flipped version of write.
--   
--   Since: 1.3.0.0.
writeTo :: OutputStream a -> Maybe a -> IO ()

-- | Checks if an InputStream is at end-of-stream.
atEOF :: InputStream a -> IO Bool

-- | Connects an InputStream and OutputStream, supplying
--   values from the InputStream to the OutputStream, and
--   propagating the end-of-stream message from the InputStream
--   through to the OutputStream.
--   
--   The connection ends when the InputStream yields a
--   Nothing.
connect :: InputStream a -> OutputStream a -> IO ()

-- | The connectTo function is just flip
--   connect.
--   
--   Useful for writing expressions like fromList [1,2,3] >>=
--   connectTo foo.
connectTo :: OutputStream a -> InputStream a -> IO ()

-- | Connects an InputStream to an OutputStream without
--   passing the end-of-stream notification through to the
--   OutputStream.
--   
--   Use this to supply an OutputStream with multiple
--   InputStreams and use connect for the final
--   InputStream to finalize the OutputStream, like so:
--   
--   
--   do Streams.supply  input1 output
--      Streams.supply  input2 output
--      Streams.connect input3 output
--   
supply :: InputStream a -> OutputStream a -> IO ()

-- | supply with the arguments flipped.
supplyTo :: OutputStream a -> InputStream a -> IO ()

-- | appendInputStream concatenates two InputStreams,
--   analogous to (++) for lists.
--   
--   The second InputStream continues where the first
--   InputStream ends.
--   
--   Note: values pushed back to appendInputStream are not
--   propagated to either wrapped InputStream.
appendInputStream :: InputStream a -> InputStream a -> IO (InputStream a)

-- | concatInputStreams concatenates a list of InputStreams,
--   analogous to (++) for lists.
--   
--   Subsequent InputStreams continue where the previous one
--   InputStream ends.
--   
--   Note: values pushed back to the InputStream returned by
--   concatInputStreams are not propagated to any of the source
--   InputStreams.
concatInputStreams :: [InputStream a] -> IO (InputStream a)

-- | Converts an InputStream into a thread-safe InputStream,
--   at a slight performance penalty.
--   
--   For performance reasons, this library provides non-thread-safe streams
--   by default. Use the locking functions to convert these
--   streams into slightly slower, but thread-safe, equivalents.
lockingInputStream :: InputStream a -> IO (InputStream a)

-- | Converts an OutputStream into a thread-safe
--   OutputStream, at a slight performance penalty.
--   
--   For performance reasons, this library provides non-thread-safe streams
--   by default. Use the locking functions to convert these
--   streams into slightly slower, but thread-safe, equivalents.
lockingOutputStream :: OutputStream a -> IO (OutputStream a)

-- | An empty InputStream that yields Nothing immediately.
nullInput :: IO (InputStream a)

-- | An empty OutputStream that discards any input fed to it.
nullOutput :: IO (OutputStream a)

-- | A Generator is a coroutine monad that can be used to define
--   complex InputStreams. You can cause a value of type Just
--   r to appear when the InputStream is read by calling
--   yield:
--   
--   
--   g :: Generator Int ()
--   g = do
--       Streams.yield 1
--       Streams.yield 2
--       Streams.yield 3
--   
--   
--   A Generator can be turned into an InputStream by calling
--   fromGenerator:
--   
--   
--   m :: IO [Int]
--   m = Streams.fromGenerator g >>= Streams.toList     -- value returned is [1,2,3]
--   
--   
--   You can perform IO by calling liftIO, and turn a
--   Generator into an InputStream with fromGenerator.
--   
--   As a general rule, you should not acquire resources that need to be
--   freed from a Generator, because there is no guarantee the
--   coroutine continuation will ever be called, nor can you catch an
--   exception from within a Generator.
data Generator r a

-- | Turns a Generator into an InputStream.
fromGenerator :: Generator r a -> IO (InputStream r)

-- | Calling yield x causes the value Just
--   x to appear on the input when this generator is converted to an
--   InputStream. The rest of the computation after the call to
--   yield is resumed later when the InputStream is
--   read again.
yield :: r -> Generator r ()
