Skip to content

Commit eaf5b2e

Browse files
committed
Theoretical implementation of writeBlockArray
1 parent 267915b commit eaf5b2e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

System/TPFS/Block.hs

+12-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Control.Monad (replicateM)
3636
import Data.Array
3737
import Data.Binary
3838
import Data.Binary.Get
39+
import Data.Binary.Put
3940
import Data.ByteString.Lazy (ByteString)
4041
import qualified Data.ByteString.Lazy as B
4142
import Data.List
@@ -107,7 +108,17 @@ readBlockArray h hdr idx =
107108
}
108109
where elc = blockSize hdr `quot` 8 -- Word64 is 8 bytes
109110

110-
writeBlockArray = undefined
111+
-- | Writes a 'BlockArray' object to disk.
112+
writeBlockArray :: Device m h
113+
=> h
114+
-> Header
115+
-> BlockIndex
116+
-> BlockArray
117+
-> m ()
118+
119+
writeBlockArray h hdr idx ary = dPut h (blockIndexToAddress hdr idx) str
120+
where str = runPut $ foldl put (pure ()) (elems $ blocks ary) >> putWord64le (nextArray ary)
121+
put m e = m >> putWord64le e
111122

112123
linkBlockArray = undefined
113124

0 commit comments

Comments
 (0)