1313-- * Support for verifying checksums of files.
1414-- * Support for a text file format listing file checksums.
1515--
16- -- TODO: specialise all the functions here to IO
1716module Database.LSMTree.Internal.CRC32C (
1817
1918 CRC32C (.. ),
@@ -80,7 +79,7 @@ initialCRC32C = CRC32C 0 -- same as crc32c BS.empty
8079updateCRC32C :: BS. ByteString -> CRC32C -> CRC32C
8180updateCRC32C bs (CRC32C crc) = CRC32C (CRC. crc32c_update crc bs)
8281
83-
82+ {-# SPECIALISE hGetSomeCRC32C :: HasFS IO h -> Handle h -> Word64 -> CRC32C -> IO (BS.ByteString, CRC32C) #-}
8483hGetSomeCRC32C :: Monad m
8584 => HasFS m h
8685 -> Handle h
@@ -101,6 +100,7 @@ hGetSomeCRC32C fs h n crc = do
101100-- TODO: To reliably return a strict bytestring without additional copying,
102101-- @fs-api@ needs to support directly reading into a buffer, which is currently
103102-- work in progress: <https://github.com/input-output-hk/fs-sim/pull/46>
103+ {-# SPECIALISE hGetExactlyCRC32C :: HasFS IO h -> Handle h -> Word64 -> CRC32C -> IO (BSL.ByteString, CRC32C) #-}
104104hGetExactlyCRC32C :: MonadThrow m
105105 => HasFS m h
106106 -> Handle h
@@ -112,6 +112,7 @@ hGetExactlyCRC32C fs h n crc = do
112112 return (lbs, crc')
113113
114114
115+ {-# SPECIALISE hPutSomeCRC32C :: HasFS IO h -> Handle h -> BS.ByteString -> CRC32C -> IO (Word64, CRC32C) #-}
115116hPutSomeCRC32C :: Monad m
116117 => HasFS m h
117118 -> Handle h
@@ -124,6 +125,7 @@ hPutSomeCRC32C fs h bs crc = do
124125
125126
126127-- | This function makes sure that the whole 'BS.ByteString' is written.
128+ {-# SPECIALISE hPutAllCRC32C :: HasFS IO h -> Handle h -> BS.ByteString -> CRC32C -> IO (Word64, CRC32C) #-}
127129hPutAllCRC32C :: forall m h
128130 . Monad m
129131 => HasFS m h
@@ -142,6 +144,7 @@ hPutAllCRC32C fs h = go 0
142144 else go written' bs' crc'
143145
144146-- | This function makes sure that the whole /lazy/ 'BSL.ByteString' is written.
147+ {-# SPECIALISE hPutAllChunksCRC32C :: HasFS IO h -> Handle h -> BSL.ByteString -> CRC32C -> IO (Word64, CRC32C) #-}
145148hPutAllChunksCRC32C :: forall m h
146149 . Monad m
147150 => HasFS m h
@@ -156,6 +159,7 @@ hPutAllChunksCRC32C fs h = \lbs crc ->
156159 (n, crc') <- hPutAllCRC32C fs h bs crc
157160 return (written + n, crc')
158161
162+ {-# SPECIALISE readFileCRC32C :: HasFS IO h -> FsPath -> IO CRC32C #-}
159163readFileCRC32C :: forall m h . MonadThrow m => HasFS m h -> FsPath -> m CRC32C
160164readFileCRC32C fs file =
161165 withFile fs file ReadMode (\ h -> go h initialCRC32C)
@@ -267,6 +271,7 @@ data ChecksumsFileFormatError = ChecksumsFileFormatError FsPath BSC.ByteString
267271
268272instance Exception ChecksumsFileFormatError
269273
274+ {-# SPECIALISE readChecksumsFile :: HasFS IO h -> FsPath -> IO ChecksumsFile #-}
270275readChecksumsFile :: MonadThrow m
271276 => HasFS m h -> FsPath -> m ChecksumsFile
272277readChecksumsFile fs path = do
@@ -275,13 +280,15 @@ readChecksumsFile fs path = do
275280 Left badline -> throwIO (ChecksumsFileFormatError path badline)
276281 Right checksums -> return checksums
277282
283+ {-# SPECIALISE writeChecksumsFile :: HasFS IO h -> FsPath -> ChecksumsFile -> IO () #-}
278284writeChecksumsFile :: MonadThrow m
279285 => HasFS m h -> FsPath -> ChecksumsFile -> m ()
280286writeChecksumsFile fs path checksums =
281287 withFile fs path (WriteMode MustBeNew ) $ \ h -> do
282288 _ <- hPutAll fs h (formatChecksumsFile checksums)
283289 return ()
284290
291+ {-# SPECIALISE writeChecksumsFile' :: HasFS IO h -> Handle h -> ChecksumsFile -> IO () #-}
285292writeChecksumsFile' :: MonadThrow m
286293 => HasFS m h -> Handle h -> ChecksumsFile -> m ()
287294writeChecksumsFile' fs h checksums = void $ hPutAll fs h (formatChecksumsFile checksums)
0 commit comments