Updated to work with .77 cvs.
Uses 'content' word as per slava's blog. Added 'file>md5' and 'stream>md5'.cvs
parent
80c1553a5a
commit
5384a2f805
|
@ -17,6 +17,10 @@ SYMBOL: old-d
|
|||
: nth-int ( string n -- int )
|
||||
4 * dup 4 + rot subseq le> ;
|
||||
|
||||
: contents ( stream -- string )
|
||||
#! Read the entire stream into a string.
|
||||
4096 <sbuf> [ stream-copy ] keep >string ;
|
||||
|
||||
: initialize ( -- )
|
||||
HEX: 67452301 dup a set old-a set
|
||||
HEX: efcdab89 dup b set old-b set
|
||||
|
@ -179,7 +183,11 @@ SYMBOL: old-d
|
|||
64 * dup 64 + rot subseq ;
|
||||
|
||||
: hex-string ( str -- str )
|
||||
[ >hex 2 CHAR: 0 pad-left ] map concat ;
|
||||
[
|
||||
[
|
||||
>hex 2 48 pad-left %
|
||||
] each
|
||||
] make-string ;
|
||||
|
||||
: get-md5 ( -- str )
|
||||
[
|
||||
|
@ -193,6 +201,15 @@ SYMBOL: old-d
|
|||
2drop get-md5
|
||||
] with-scope ;
|
||||
|
||||
: stream>md5 ( stream -- md5 )
|
||||
[
|
||||
contents string>md5
|
||||
] with-scope ;
|
||||
: file>md5 ( file -- md5 )
|
||||
[
|
||||
<file-reader> stream>md5
|
||||
] with-scope ;
|
||||
|
||||
: test-md5 ( -- )
|
||||
[ "d41d8cd98f00b204e9800998ecf8427e" ] [ "" string>md5 ] unit-test
|
||||
[ "0cc175b9c0f1b6a831c399e269772661" ] [ "a" string>md5 ] unit-test
|
||||
|
|
Loading…
Reference in New Issue