aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cas.scm34
-rw-r--r--guix.scm4
-rw-r--r--scratch.scm16
3 files changed, 53 insertions, 1 deletions
diff --git a/cas.scm b/cas.scm
new file mode 100644
index 0000000..e314cf9
--- /dev/null
+++ b/cas.scm
@@ -0,0 +1,34 @@
+(define-module (cas)
+ #:use-module (rnrs bytevectors)
+ #:use-module (leveldb)
+ #:use-module (srfi srfi-167)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-9)
+ #:use-module (gcrypt hash)
+
+ #:export (make-cas
+ cas?
+ cas-okvs
+
+ cas-put!
+ cas-get))
+
+(define blake2b-256
+ (cut bytevector-hash <> (hash-algorithm blake2b-256)))
+
+(define-record-type <cas>
+ (%make-cas okvs hash)
+ cas?
+ (okvs cas-okvs)
+ (hash cas-hash))
+
+(define* (make-cas okvs #:optional (hash blake2b-256))
+ (%make-cas okvs hash))
+
+(define (cas-put! cas bv)
+ (let ((key (apply (cas-hash cas) (list bv))))
+ (okvs-set! (cas-okvs cas) key bv)
+ key))
+
+(define (cas-get cas key)
+ (okvs-ref (cas-okvs cas) key))
diff --git a/guix.scm b/guix.scm
index edcf87b..91bd494 100644
--- a/guix.scm
+++ b/guix.scm
@@ -6,6 +6,7 @@
(gnu packages pkg-config)
(gnu packages guile)
(gnu packages guile-xyz)
+ (gnu packages gnupg)
(gnu packages databases)
(guix build-system gnu)
(guix licenses))
@@ -25,7 +26,8 @@
("automake" ,automake)))
(inputs
`(("guile" ,guile-3.0)
- ("leveldb" ,leveldb)))
+ ("leveldb" ,leveldb)
+ ("guile-gcrypt" ,guile3.0-gcrypt)))
(synopsis "Experimentations into data model/data storage for openEngiadina")
(description "Experimentations into data model/data storage for openEngiadina")
(home-page "https://gitlab.com/openEngiadina/data-model")
diff --git a/scratch.scm b/scratch.scm
index d100315..add804b 100644
--- a/scratch.scm
+++ b/scratch.scm
@@ -1,4 +1,5 @@
(use-modules (leveldb)
+ (cas)
(srfi srfi-167)
(rnrs bytevectors))
@@ -39,4 +40,19 @@
(utf8->string
(okvs-ref okvs (make-bytevector 1 2))))
+
+;; Create a Content-addressable storage
+(define cas
+ (make-cas okvs))
+
+;; Store a string in the cas and get the key
+(define key
+ (cas-put! cas (string->utf8 "Hello World!")))
+
+;; the content can now be accessed by its key (which is also it's hash)
+(display key)
+
+;; Retrieve contetn
+(utf8->string (cas-get cas key))
+
(okvs-close okvs)