factor/core/checksums/checksums.factor

29 lines
838 B
Factor
Raw Normal View History

2008-04-30 17:11:55 -04:00
! Copyright (c) 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
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 )
M: checksum checksum-stream
[ contents ] dip checksum-bytes ;
2008-04-30 17:11:55 -04: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 )
#! 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 )
[ >hex 2 CHAR: 0 pad-head ] { } map-as concat ;