module Sound.MIDI.IO
(openBinaryFile, readBinaryFile, writeBinaryFile,
ByteString, stringCharFromByte, stringByteFromChar)
where
import System.IO
import Control.Exception(bracket)
import Control.Monad(liftM)
import Data.Char (ord, chr)
import Data.Word (Word8)
type ByteString = [Word8]
writeBinaryFile :: FilePath -> ByteString -> IO ()
writeBinaryFile path str =
bracket (openBinaryFile path WriteMode) hClose
(flip hPutStr (stringCharFromByte str))
stringCharFromByte :: ByteString -> String
stringCharFromByte = map (chr . fromIntegral)
readBinaryFile :: FilePath -> IO ByteString
readBinaryFile path =
liftM stringByteFromChar .
hGetContents =<< openBinaryFile path ReadMode
stringByteFromChar :: String -> ByteString
stringByteFromChar = map (fromIntegral . ord)