checksums: make checksum-state implement dispose.
parent
af62d33ba9
commit
1b54f0a434
|
@ -1,8 +1,7 @@
|
||||||
! Copyright (C) 2006, 2008 Doug Coleman.
|
! Copyright (C) 2006, 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors byte-arrays byte-vectors checksums destructors
|
USING: accessors byte-arrays byte-vectors checksums grouping
|
||||||
grouping io io.backend io.binary io.encodings.binary io.files
|
io.binary kernel locals make math sequences ;
|
||||||
kernel make math sequences locals ;
|
|
||||||
IN: checksums.common
|
IN: checksums.common
|
||||||
|
|
||||||
: calculate-pad-length ( length -- length' )
|
: calculate-pad-length ( length -- length' )
|
||||||
|
@ -23,8 +22,6 @@ TUPLE: block-checksum-state < checksum-state
|
||||||
{ bytes-read integer }
|
{ bytes-read integer }
|
||||||
{ block-size integer } ;
|
{ block-size integer } ;
|
||||||
|
|
||||||
M: block-checksum-state dispose drop ;
|
|
||||||
|
|
||||||
GENERIC: checksum-block ( bytes checksum-state -- )
|
GENERIC: checksum-block ( bytes checksum-state -- )
|
||||||
|
|
||||||
! Update the bytes-read before calculating checksum in case
|
! Update the bytes-read before calculating checksum in case
|
||||||
|
@ -48,11 +45,7 @@ M:: block-checksum-state add-checksum-bytes ( state data -- state )
|
||||||
remain [ >byte-vector ] [ BV{ } clone ] if* >>bytes ;
|
remain [ >byte-vector ] [ BV{ } clone ] if* >>bytes ;
|
||||||
|
|
||||||
M: block-checksum checksum-bytes
|
M: block-checksum checksum-bytes
|
||||||
initialize-checksum-state [
|
[ swap add-checksum-bytes get-checksum ] with-checksum-state ;
|
||||||
swap add-checksum-bytes get-checksum
|
|
||||||
] with-disposal ;
|
|
||||||
|
|
||||||
M: block-checksum checksum-stream
|
M: block-checksum checksum-stream
|
||||||
initialize-checksum-state [
|
[ swap add-checksum-stream get-checksum ] with-checksum-state ;
|
||||||
swap add-checksum-stream get-checksum
|
|
||||||
] with-disposal ;
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (c) 2008 Slava Pestov
|
! Copyright (c) 2008 Slava Pestov
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors byte-vectors io io.backend io.encodings.binary
|
USING: accessors byte-vectors destructors io io.backend
|
||||||
io.files io.streams.byte-array kernel sequences ;
|
io.encodings.binary io.files io.streams.byte-array kernel
|
||||||
|
sequences ;
|
||||||
IN: checksums
|
IN: checksums
|
||||||
|
|
||||||
MIXIN: checksum
|
MIXIN: checksum
|
||||||
|
@ -24,6 +25,8 @@ M: checksum checksum-lines
|
||||||
|
|
||||||
TUPLE: checksum-state checksum { bytes byte-vector } ;
|
TUPLE: checksum-state checksum { bytes byte-vector } ;
|
||||||
|
|
||||||
|
M: checksum-state dispose drop ;
|
||||||
|
|
||||||
M: checksum-state clone
|
M: checksum-state clone
|
||||||
call-next-method
|
call-next-method
|
||||||
[ clone ] change-bytes ;
|
[ clone ] change-bytes ;
|
||||||
|
@ -35,6 +38,9 @@ GENERIC: initialize-checksum-state ( checksum -- checksum-state )
|
||||||
GENERIC# add-checksum-bytes 1 ( checksum-state data -- checksum-state )
|
GENERIC# add-checksum-bytes 1 ( checksum-state data -- checksum-state )
|
||||||
GENERIC: get-checksum ( checksum-state -- value )
|
GENERIC: get-checksum ( checksum-state -- value )
|
||||||
|
|
||||||
|
: with-checksum-state ( ... checksum quot: ( ... checksum-state -- ..b ) -- ..b value )
|
||||||
|
[ initialize-checksum-state ] dip with-disposal ; inline
|
||||||
|
|
||||||
: add-checksum-stream ( checksum-state stream -- checksum-state )
|
: add-checksum-stream ( checksum-state stream -- checksum-state )
|
||||||
[ [ add-checksum-bytes ] each-block ] with-input-stream ;
|
[ [ add-checksum-bytes ] each-block ] with-input-stream ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue