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