hbs2 hash command re-implemented

This commit is contained in:
voidlizard 2025-06-06 07:17:07 +03:00
parent 8e7165331c
commit fd0f0f05f5
2 changed files with 22 additions and 10 deletions

View File

@ -42,6 +42,13 @@
) )
) )
( (list? [sym? hash] ...)
(begin
(local what (if (eq? (type ...) :list) ... '()))
(display (eval `(hbs2:hash ,@what)))
)
)
( (list? [sym? has] hash) ( (list? [sym? has] hash)
(begin (begin
(local s (hbs2:peer:storage:block:size hash)) (local s (hbs2:peer:storage:block:size hash))

View File

@ -32,6 +32,7 @@ import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Cont import Control.Monad.Trans.Cont
import Data.ByteString.Char8 qualified as BS8 import Data.ByteString.Char8 qualified as BS8
import Data.ByteString.Lazy qualified as LBS import Data.ByteString.Lazy qualified as LBS
import Data.ByteString qualified as BS
import Data.Text qualified as Text import Data.Text qualified as Text
import Lens.Micro.Platform import Lens.Micro.Platform
@ -171,18 +172,22 @@ internalEntries = do
-- TODO: re-implement-all-on-top-of-opaque -- TODO: re-implement-all-on-top-of-opaque
entry $ bindMatch "hbs2:hash" $ \syn -> do entry $ bindMatch "hbs2:hash" $ \case
i <- case syn of [] -> liftIO do
[ListVal (StringLikeList xs)] -> pure xs LBS.getContents
StringLikeList xs -> pure xs <&> mkSym . HashRef . hashObject @HbSync
e -> throwIO (BadFormException @c (mkList e))
r <- forM i $ \f -> do [ StringLike fn ] -> liftIO do
liftIO (LBS.readFile f) LBS.readFile fn
<&> hashObject @HbSync <&> mkSym . HashRef . hashObject @HbSync
<&> mkSym @c . show . pretty
pure $ mkList r [isOpaqueOf @LBS.ByteString -> Just s ] -> do
pure $ mkSym $ HashRef $ hashObject @HbSync s
[isOpaqueOf @BS.ByteString -> Just s ] -> do
pure $ mkSym $ HashRef $ hashObject @HbSync s
e -> throwIO (BadFormException @c (mkList e))
entry $ bindMatch "blob:base58" $ \case entry $ bindMatch "blob:base58" $ \case
[LitStrVal t] -> do [LitStrVal t] -> do