aboutsummaryrefslogtreecommitdiff
path: root/guix/hash.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-07-19 17:08:53 +0200
committerLudovic Courtès <ludo@gnu.org>2018-07-19 17:08:53 +0200
commitc71cd4a61fc8085ccb17169aad826d6f9ee1718b (patch)
treef269f2a7772da03d0698c45131d4ca5b0aab19b1 /guix/hash.scm
parentf5db54eaa51f4fdd9cec14254e413e17bfca4cca (diff)
downloadgnu-guix-c71cd4a61fc8085ccb17169aad826d6f9ee1718b.tar
gnu-guix-c71cd4a61fc8085ccb17169aad826d6f9ee1718b.tar.gz
hash: sha256 port now implements 'port-position'.
* guix/hash.scm (open-sha256-port)[position]: New variable. [get-position]: New procedure. Pass it to 'make-custom-binary-output-port'. * tests/hash.scm ("open-sha256-port, hello"): Test 'port-position'.
Diffstat (limited to 'guix/hash.scm')
-rw-r--r--guix/hash.scm7
1 files changed, 6 insertions, 1 deletions
diff --git a/guix/hash.scm b/guix/hash.scm
index 39834043e1..8d7ba21425 100644
--- a/guix/hash.scm
+++ b/guix/hash.scm
@@ -101,6 +101,7 @@ output port."
(open-sha256-md))
(define digest #f)
+ (define position 0)
(define (finalize!)
(let ((ptr (md-read sha256-md 0)))
@@ -114,14 +115,18 @@ output port."
0)
(let ((ptr (bytevector->pointer bv offset)))
(md-write sha256-md ptr len)
+ (set! position (+ position len))
len)))
+ (define (get-position)
+ position)
+
(define (close)
(unless digest
(finalize!)))
(values (make-custom-binary-output-port "sha256"
- write! #f #f
+ write! get-position #f
close)
(lambda ()
(unless digest