summaryrefslogtreecommitdiff
path: root/src/Erebos/Storage/Backend.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Erebos/Storage/Backend.hs')
-rw-r--r--src/Erebos/Storage/Backend.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Erebos/Storage/Backend.hs b/src/Erebos/Storage/Backend.hs
index c802d95..719e87f 100644
--- a/src/Erebos/Storage/Backend.hs
+++ b/src/Erebos/Storage/Backend.hs
@@ -12,15 +12,21 @@ module Erebos.Storage.Backend (
withStorageBackend,
refDigestBytes,
+ allocateScrubbedBytes,
+ unsafeUseScrubbedBytesAsCStringLen,
WatchID, startWatchID, nextWatchID,
) where
import Control.Concurrent.MVar
+import Data.ByteArray qualified as BA
import Data.ByteString (ByteString)
import Data.HashTable.IO qualified as HT
+import Foreign.C.String
+import Foreign.Ptr
+
import ConvertByteString
import Erebos.Object.Internal
import Erebos.Storage.Internal
@@ -38,3 +44,9 @@ withStorageBackend Storage {..} f = f stBackend
refDigestBytes :: RefDigest -> ByteString
refDigestBytes = toByteString
+
+allocateScrubbedBytes :: Int -> (Ptr a -> IO ()) -> IO ScrubbedBytes
+allocateScrubbedBytes len f = snd <$> BA.allocRet len f
+
+unsafeUseScrubbedBytesAsCStringLen :: ScrubbedBytes -> (CStringLen -> IO a) -> IO a
+unsafeUseScrubbedBytesAsCStringLen sb f = withByteArray sb (\ptr -> f ( ptr, BA.length sb ))