MissingH API ManualContentsIndex
MissingH.IO.Binary
Portability portable to platforms supporting binary I/O
Stability provisional
Maintainer jgoerzen@complete.org
Contents
Entire File/Handle Utilities
Opened Handle Data Copying
Disk File Data Copying
Binary Single-Block I/O
Binary Multi-Block I/O
Lazy Interaction
Binary Block-based
Description

This module provides various helpful utilities for dealing with I/O.

Important note: binary functions are not supported in all Haskell implementations. Do not import or use this module unless you know you are using an implementation that supports them. At this time, here is the support status:

  • GHC 6.2: yes
  • GHC 6.x, earlier versions: unknown
  • GHC 5.x: no
  • nhc98: no
  • Hugs: partial (maybe complete; needs more testing)

Non-binary functions may be found in MissingH.IO.

Written by John Goerzen, jgoerzen@complete.org

Synopsis
hBlockCopy :: Int -> Handle -> Handle -> IO ()
blockCopy :: Int -> IO ()
copyFileBlocksToFile :: Int -> FilePath -> FilePath -> IO ()
hPutBufStr :: Handle -> String -> IO ()
putBufStr :: String -> IO ()
hGetBufStr :: Handle -> Int -> IO String
getBufStr :: Int -> IO String
hFullGetBufStr :: Handle -> Int -> IO String
fullGetBufStr :: Int -> IO String
hGetBlocks :: Handle -> Int -> IO [String]
getBlocks :: Int -> IO [String]
hFullGetBlocks :: Handle -> Int -> IO [String]
fullGetBlocks :: Int -> IO [String]
readBinaryFile :: FilePath -> IO String
writeBinaryFile :: FilePath -> String -> IO ()
hBlockInteract :: Int -> Handle -> Handle -> ([String] -> [String]) -> IO ()
blockInteract :: Int -> ([String] -> [String]) -> IO ()
hFullBlockInteract :: Int -> Handle -> Handle -> ([String] -> [String]) -> IO ()
fullBlockInteract :: Int -> ([String] -> [String]) -> IO ()
Entire File/Handle Utilities
Opened Handle Data Copying
hBlockCopy :: Int -> Handle -> Handle -> IO ()

Copies everything from the input handle to the output handle using binary blocks of the given size. This is actually a beautiful implementation:

 hBlockCopy bs hin hout = hBlockInteract bs hin hout id

(id is the built-in Haskell function that just returns whatever is given to it)

blockCopy :: Int -> IO ()
Copies from stdin to stdout using binary blocks of the given size. An alias for hBlockCopy over stdin and stdout
Disk File Data Copying
copyFileBlocksToFile :: Int -> FilePath -> FilePath -> IO ()

Copies one filename to another in binary mode.

Please note that the Unix permission bits on the output file cannot be set due to a limitation of the Haskell openBinaryFile function. Therefore, you may need to adjust those bits after the copy yourself.

This function is implemented using hBlockCopy internally.

Binary Single-Block I/O
hPutBufStr :: Handle -> String -> IO ()
As a wrapper around the standard function hPutBuf, this function takes a standard Haskell String instead of the far less convenient 'Ptr a'. The entire contents of the string will be written as a binary buffer using hPutBuf. The length of the output will be the length of the string.
putBufStr :: String -> IO ()
An alias for hPutBufStr stdout
hGetBufStr :: Handle -> Int -> IO String
As a wrapper around the standard function hGetBuf, this function returns a standard Haskell string instead of modifying a 'Ptr a' buffer. The length is the maximum length to read and the semantice are the same as with hGetBuf; namely, the empty string is returned with EOF is reached, and any given read may read fewer bytes than the given length.
getBufStr :: Int -> IO String
An alias for hGetBufStr stdin
hFullGetBufStr :: Handle -> Int -> IO String
Like hGetBufStr, but guarantees that it will only return fewer than the requested number of bytes when EOF is encountered.
fullGetBufStr :: Int -> IO String
An alias for hFullGetBufStr stdin
Binary Multi-Block I/O
hGetBlocks :: Handle -> Int -> IO [String]
Returns a lazily-evaluated list of all blocks in the input file, as read by hGetBufStr. There will be no 0-length block in this list. The list simply ends at EOF.
getBlocks :: Int -> IO [String]
An alias for hGetBlocks stdin
hFullGetBlocks :: Handle -> Int -> IO [String]
Same as hGetBlocks, but using hFullGetBufStr underneath.
fullGetBlocks :: Int -> IO [String]
An alias for hFullGetBlocks stdin
Lazy Interaction
readBinaryFile :: FilePath -> IO String
Like the built-in readFile, but opens the file in binary instead of text mode.
writeBinaryFile :: FilePath -> String -> IO ()
Like the built-in writeFile, but opens the file in binary instead of text mode.
Binary Block-based
hBlockInteract :: Int -> Handle -> Handle -> ([String] -> [String]) -> IO ()
Binary block-based interaction. This is useful for scenarios that take binary blocks, manipulate them in some way, and then write them out. Take a look at hBlockCopy for an example. The integer argument is the size of input binary blocks. This function uses hGetBlocks internally.
blockInteract :: Int -> ([String] -> [String]) -> IO ()
An alias for hBlockInteract over stdin and stdout
hFullBlockInteract :: Int -> Handle -> Handle -> ([String] -> [String]) -> IO ()
Same as hBlockInteract, but uses hFullGetBlocks instead of hGetBlocks internally.
fullBlockInteract :: Int -> ([String] -> [String]) -> IO ()
An alias for hFullBlockInteract over stdin and stdout
Produced by Haddock version 0.6