]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/FuncTorrent/FileSystem.hs
FileSystem: do not expose msgs outside the module, instead expose helper fns
[functorrent.git] / src / FuncTorrent / FileSystem.hs
index e064b713c68607bd05941e22e5bce8ae64d86ddb..df203b09b752c0f8cf17bd5c398e72b5ea136df1 100644 (file)
@@ -2,18 +2,17 @@ module FuncTorrent.FileSystem
        (startThread,
         MsgChannel,
         createMsgChannel,
-        Msg(..),
+        writePiece,
         Piece(..),
         pieceMapFromFile
        )
        where
 
 import           Control.Concurrent (ThreadId, forkIO)
-import           Control.Concurrent.Chan (Chan, newChan, readChan)
+import           Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
 import           Control.Concurrent.MVar (MVar, putMVar)
 import           Control.Monad (forever)
 import           Data.Map (traverseWithKey)
-
 import qualified Data.ByteString as BS
 import           Data.Map ((!))
 import           System.IO (Handle, IOMode (ReadWriteMode), withFile)
@@ -75,3 +74,8 @@ pieceMapFromFile filePath fileLen pieceMap = do
       if isHashValid
         then return $ v { dlstate = Have }
         else return v
+
+writePiece :: MsgChannel -> PieceNum -> BS.ByteString -> IO ()
+writePiece c pieceNum bs = do
+  writeChan c $ WritePiece (Piece pieceNum bs)
+