]> git.rkrishnan.org Git - functorrent.git/blob - src/FuncTorrent/Fileops.hs
f1bbefe1126df9e78693726caa9c0481fe428f9d
[functorrent.git] / src / FuncTorrent / Fileops.hs
1 module FuncTorrent.Fileops
2        (createDummyFile,
3         writeFileAtOffset
4        ) where
5
6 import Prelude hiding (writeFile)
7
8 import System.IO (withFile, hSeek, IOMode(..), SeekMode(..))
9 import Data.ByteString (ByteString, writeFile, hPut)
10 import qualified Data.ByteString.Char8 as BC (replicate)
11
12 createDummyFile :: FilePath -> Int -> IO ()
13 createDummyFile path size =
14   writeFile path (BC.replicate size '\0')
15
16 -- write into a file at a specific offet
17 writeFileAtOffset :: FilePath -> Integer -> ByteString -> IO ()
18 writeFileAtOffset path offset block =
19   withFile path ReadWriteMode (\h -> do
20                                   hSeek h AbsoluteSeek offset
21                                   hPut h block)