Last active
July 14, 2023 17:11
-
-
Save voidlizard/609b77b388f4b003771ff98e15b46034 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Streaming.Prelude qualified as S | |
import Streaming qualified as S | |
-- FIXME: move-to-library | |
readBlob :: forall m . ( MonadIO m | |
, HasStorage m | |
, Block ByteString ~ ByteString | |
) | |
=> HashRef | |
-> m (Maybe ByteString) | |
readBlob hr = do | |
sto <- getStorage | |
let readBlock h = liftIO $ getBlock sto h | |
chunks <- S.toList_ $ | |
deepScan ScanDeep (const $ S.yield Nothing) (fromHashRef hr) readBlock $ \ha -> do | |
unless (fromHashRef hr == ha) do | |
readBlock ha >>= S.yield | |
let mfo acc el = case (acc, el) of | |
(Nothing, Just s) -> Just [s] | |
(_, Nothing) -> Nothing | |
(Just ss, Just s) -> Just (s:ss) | |
pure $ LBS.concat . reverse <$> foldl mfo Nothing chunks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment