Word8-Based IO
Ashley Yakeley
ashley@semantic.org
Tue, 20 Aug 2002 21:55:45 -0700
Was there any kind of consensus emerging on this? Leaving aside what
might be done with the Char-based functions (and people seem to think
they're fine as is) I'd like to suggest the following:
* System.IO: addition of new Word8-based functions
hGetOctet :: Handle -> IO Word8
hLookAheadOctet :: Handle -> IO Word8
hPutOctet :: Handle -> Word8 -> IO ()
hPutArray :: Handle -> [Word8] -> IO ()
hLazyGetArray :: Handle -> IO [Word8]
...as per hGetChar, hLookAhead, hPutChar, hPutStr and hGetContents.
hGetArrayBlock :: Handle -> Int -> IO [Word8]
hGetArrayReady :: Handle -> Int -> IO [Word8]
hGetArrayBlock would read so many octets from the handle, up to the EOF.
hGetArrayReady would read so many octets from the handle, up to the EOF
or octets not ready. The semantics would be something like this:
hGetArrayBlock h 0 = return [];
hGetArrayBlock h n = do {
eof <- hIsEOF h;
if eof then return [] else do {
first <- hGetOctet;
rest <- hGetArrayBlock h (n - 1);
return (first:rest);
};
};
hGetArrayReady h 0 = return [];
hGetArrayReady h n = do {
ready <- hReady h;
if not ready then return [] else do {
first <- hGetOctet;
rest <- hGetArrayReady h (n - 1);
return (first:rest);
};
};
...but I expect they should be implemented natively.
hSetFileSize :: Handle -> Integer -> IO ()
There's currently no way to set the size of a file. hSetFileSize would
truncate the file or pad with zero octets.
* Network.Socket
The send & receive functions don't do any kind of character
interpretation do they? I suggest these functions be given new types (and
probably new names, as I suppose we'll need the old ones for
compatibility):
sendTo :: Socket -> [Word8] -> SockAddr -> IO Int
recvFrom :: Socket -> Int -> IO ([Word8], Int, SockAddr)
send :: Socket -> [Word8] -> IO Int
recv :: Socket -> Int -> IO [Word8]
--
Ashley Yakeley, Seattle WA