+module FuncTorrent.Fileops
+ (createDummyFile,
+ writeFileAtOffset
+ ) where
+
+import Prelude hiding (writeFile)
+
+import System.IO (withFile, hSeek, IOMode(..), SeekMode(..))
+import Data.ByteString (ByteString, writeFile, hPut)
+import qualified Data.ByteString.Char8 as BC (replicate)
+
+createDummyFile :: FilePath -> Int -> IO ()
+createDummyFile path size =
+ writeFile path (BC.replicate size '\0')
+
+-- write into a file at a specific offet
+writeFileAtOffset :: FilePath -> Integer -> ByteString -> IO ()
+writeFileAtOffset path offset block =
+ withFile path ReadWriteMode (\h -> do
+ hSeek h AbsoluteSeek offset
+ hPut h block)