made it work on strings too (the result is always a byte string)

svn: r17366
This commit is contained in:
Eli Barzilay 2009-12-20 09:50:12 +00:00
parent bbb4228d44
commit 63fe729cc6
2 changed files with 5 additions and 3 deletions

View File

@ -72,6 +72,7 @@
;; 2009-12-20 / Eli
;; - `mzscheme' -> `scheme/base'
;; - moved from mzlib/md5 to file/md5
;; - made it work on strings again
(require (for-syntax scheme/base))
@ -220,9 +221,10 @@
[(a-thing) (md5 a-thing #t)]
[(a-thing hex-encode?)
(let ([a-port
(cond [(bytes? a-thing) (open-input-bytes a-thing)]
(cond [(bytes? a-thing) (open-input-bytes a-thing)]
[(string? a-thing) (open-input-string a-thing)]
[(input-port? a-thing) a-thing]
[else (raise-type-error 'md5 "input-port or bytes"
[else (raise-type-error 'md5 "input-port, bytes, or string"
a-thing)])])
(encode (step4 a-port) hex-encode?))]))

View File

@ -11,7 +11,7 @@
@defmodule[file/md5]
@defproc[(md5 [in (or/c input-port? bytes?)]) bytes?]{
@defproc[(md5 [in (or/c input-port? bytes? string?)]) bytes?]{
Produces a byte string containing 32 hexadecimal digits (lowercase)
that is the MD5 hash of the given input stream or byte string.