Raw I/O library proposal, second (more pragmatic) draft
Ben Rudiak-Gould
benrg@dark.darkweb.com
Fri, 1 Aug 2003 16:38:18 -0700 (PDT)
On Fri, 1 Aug 2003, Simon Marlow wrote:
> class InputStream s where
> streamGet :: s -> IO Word8
> streamReadBuffer :: s -> Integer -> Buffer -> IO ()
> streamGetBuffer :: s -> Integer -> IO ImmutableBuffer
> streamGetContents :: s -> IO [Word8]
>
> class OutputStream s where
> streamPut :: s -> Word8 -> IO ()
> streamPuts :: s -> [Word8] -> IO ()
> streamWriteBuffer :: s -> Integer -> Buffer -> IO ()
Now that I think about it, we should parameterize these classes over the
input/output data type also. Then we could have
filterInputStream ::
(Storable a, Storable b, InputStream s a, InputStream t b) =>
BlockRecoder a b -> s -> t
filterOutputStream ::
(Storable a, Storable b, OutputStream s a, OutputStream t b) =>
BlockRecoder b a -> s -> t
Text streams would fit into this model. Plus, there are many useful stream
filters which don't go octet -> char or char -> octet, such as:
packBitsLE, packBitsBE :: BlockRecoder Bool Word8
unpackBitsLE, unpackBitsBE :: BlockRecoder Word8 Bool
zlibPack, zlibUnpack :: BlockRecoder Word8 Word8
recodeNewlines :: NewlineFormat -> BlockRecoder Char Char
serialize :: (Serializable a) => BlockRecoder a Word8
unserialize :: (Unserializable a) => BlockRecoder Word8 a
-- Ben