[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/02: hash: sha256 port now implements 'port-position'.
From: |
Ludovic Courtès |
Subject: |
01/02: hash: sha256 port now implements 'port-position'. |
Date: |
Thu, 19 Jul 2018 11:59:56 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit c71cd4a61fc8085ccb17169aad826d6f9ee1718b
Author: Ludovic Courtès <address@hidden>
Date: Thu Jul 19 17:08:53 2018 +0200
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'.
---
guix/hash.scm | 7 ++++++-
tests/hash.scm | 4 ++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/guix/hash.scm b/guix/hash.scm
index 3983404..8d7ba21 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
diff --git a/tests/hash.scm b/tests/hash.scm
index da87616..47dff39 100644
--- a/tests/hash.scm
+++ b/tests/hash.scm
@@ -64,12 +64,12 @@
(get)))
(test-equal "open-sha256-port, hello"
- %hello-sha256
+ (list %hello-sha256 (string-length "hello world"))
(let-values (((port get)
(open-sha256-port)))
(put-bytevector port (string->utf8 "hello world"))
(force-output port)
- (get)))
+ (list (get) (port-position port))))
(test-assert "port-sha256"
(let* ((file (search-path %load-path "ice-9/psyntax.scm"))