1 module FuncTorrent.Fileops
7 import Prelude hiding (writeFile)
9 import System.IO (withFile, hSeek, IOMode(..), SeekMode(..))
10 import System.Directory (doesFileExist)
11 import Data.ByteString (ByteString, writeFile, hPut, hGet)
12 import qualified Data.ByteString.Char8 as BC (replicate)
14 createDummyFile :: FilePath -> Int -> IO ()
15 createDummyFile path size = do
16 dfe <- doesFileExist path
20 writeFile path (BC.replicate size '\0')
22 -- write into a file at a specific offet
23 writeFileAtOffset :: FilePath -> Integer -> ByteString -> IO ()
24 writeFileAtOffset path offset block =
25 withFile path ReadWriteMode (\h -> do
26 hSeek h AbsoluteSeek offset
28 readFileAtOffset :: FilePath -> Integer -> Integer -> IO ByteString
29 readFileAtOffset path offset len =
30 withFile path ReadWriteMode (\h -> do
31 hSeek h AbsoluteSeek offset
32 hGet h (fromInteger len))