mirror of https://github.com/voidlizard/hbs2
hbs2 hash command re-implemented
This commit is contained in:
parent
8e7165331c
commit
fd0f0f05f5
7
bf6/hbs2
7
bf6/hbs2
|
@ -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))
|
||||||
|
|
|
@ -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,19 +172,23 @@ 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
|
||||||
|
|
||||||
|
[ StringLike fn ] -> liftIO do
|
||||||
|
LBS.readFile fn
|
||||||
|
<&> mkSym . HashRef . hashObject @HbSync
|
||||||
|
|
||||||
|
[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))
|
e -> throwIO (BadFormException @c (mkList e))
|
||||||
|
|
||||||
r <- forM i $ \f -> do
|
|
||||||
liftIO (LBS.readFile f)
|
|
||||||
<&> hashObject @HbSync
|
|
||||||
<&> mkSym @c . show . pretty
|
|
||||||
|
|
||||||
pure $ mkList r
|
|
||||||
|
|
||||||
entry $ bindMatch "blob:base58" $ \case
|
entry $ bindMatch "blob:base58" $ \case
|
||||||
[LitStrVal t] -> do
|
[LitStrVal t] -> do
|
||||||
bs <- pure (Text.unpack t & BS8.pack & fromBase58)
|
bs <- pure (Text.unpack t & BS8.pack & fromBase58)
|
||||||
|
|
Loading…
Reference in New Issue