Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Uniform-IO provides a typeclass for uniform access of different types of targets, and implementations for abstracting standard streams, files and network connections. This module also provides TLS wraping over other IO targets.
- class UniformIO a where
- uRead :: a -> Int -> IO ByteString
- uPut :: a -> ByteString -> IO ()
- uClose :: a -> IO ()
- startTls :: TlsSettings -> a -> IO a
- isSecure :: a -> Bool
- data TlsSettings = TlsSettings {}
- data SomeIO = forall a . UniformIO a => SomeIO a
- mapOverInput :: forall a io. UniformIO io => io -> Int -> (a -> ByteString -> IO a) -> a -> IO a
- uGetContents :: UniformIO io => io -> Int -> IO ByteString
Documentation
class UniformIO a where Source
Typeclass for uniform IO targets.
uRead :: a -> Int -> IO ByteString Source
uRead fd n
Reads a block of at most n bytes of data from the IO target. Reading will block if there's no data available, but will return immediately if any amount of data is availble.
Must thow System.IO.Error.EOFError if reading beihond EOF.
uPut :: a -> ByteString -> IO () Source
uPut fd text
Writes all the bytes of text into the IO target. Takes care of retrying if needed.
fClose fd
Closes the IO target, releasing any allocated resource. Resources may leak if not called for every oppened fd.
startTls :: TlsSettings -> a -> IO a Source
startTLS fd
Starts a TLS connection over the IO target.
isSecure fd
Indicates whether the data written or read from fd is secure at transport.
UniformIO SomeIO Source | |
UniformIO ByteStringIO Source | |
UniformIO HandlePair Source | UniformIO that reads from stdin and writes to stdout. |
A type that wraps any type in the UniformIO class.
mapOverInput :: forall a io. UniformIO io => io -> Int -> (a -> ByteString -> IO a) -> a -> IO a Source
mapOverInput io block_size f initial
Reads io untill the end of file, evaluating a(i) <- f a(i-1) read_data where a(0) = initial and the last value after io reaches EOF is returned.
Notice that the length of read_data might not be equal block_size.
uGetContents :: UniformIO io => io -> Int -> IO ByteString Source
Returns the entire contents recieved from this target.