1 ! Copyright (c) 2008 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: sequences math.parser io io.backend io.files
9 GENERIC: checksum-bytes ( bytes checksum -- value )
11 GENERIC: checksum-stream ( stream checksum -- value )
13 GENERIC: checksum-lines ( lines checksum -- value )
15 M: checksum checksum-stream
16 [ contents ] dip checksum-bytes ;
18 M: checksum checksum-lines
19 [ B{ CHAR: \n } join ] dip checksum-bytes ;
21 : checksum-file ( path checksum -- value )
22 #! normalize-path (file-reader) is equivalen to
23 #! binary <file-reader>. We use the lower-level form
24 #! so that we can move io.encodings.binary to basis/.
25 [ normalize-path (file-reader) ] dip checksum-stream ;
27 : hex-string ( seq -- str )
28 [ >hex 2 CHAR: 0 pad-left ] { } map-as concat ;