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