2008-04-30 17:11:55 -04:00
|
|
|
! Copyright (c) 2008 Slava Pestov
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-12-14 21:03:00 -05:00
|
|
|
USING: sequences math.parser io io.backend io.files
|
2008-12-08 15:58:00 -05:00
|
|
|
kernel ;
|
2008-04-30 17:11:55 -04:00
|
|
|
IN: checksums
|
|
|
|
|
|
|
|
MIXIN: checksum
|
|
|
|
|
|
|
|
GENERIC: checksum-bytes ( bytes checksum -- value )
|
|
|
|
|
|
|
|
GENERIC: checksum-stream ( stream checksum -- value )
|
|
|
|
|
|
|
|
GENERIC: checksum-lines ( lines checksum -- value )
|
|
|
|
|
2008-11-23 03:44:56 -05:00
|
|
|
M: checksum checksum-stream
|
|
|
|
[ contents ] dip checksum-bytes ;
|
2008-04-30 17:11:55 -04:00
|
|
|
|
2008-11-23 03:44:56 -05:00
|
|
|
M: checksum checksum-lines
|
|
|
|
[ B{ CHAR: \n } join ] dip checksum-bytes ;
|
2008-04-30 17:11:55 -04:00
|
|
|
|
2008-05-01 21:02:34 -04:00
|
|
|
: checksum-file ( path checksum -- value )
|
2008-12-14 21:03:00 -05:00
|
|
|
#! normalize-path (file-reader) is equivalen to
|
|
|
|
#! binary <file-reader>. We use the lower-level form
|
|
|
|
#! so that we can move io.encodings.binary to basis/.
|
|
|
|
[ normalize-path (file-reader) ] dip checksum-stream ;
|
2008-04-30 17:11:55 -04:00
|
|
|
|
|
|
|
: hex-string ( seq -- str )
|
2009-01-29 23:19:07 -05:00
|
|
|
[ >hex 2 CHAR: 0 pad-head ] { } map-as concat ;
|