Index: simple-md5.scm =================================================================== --- simple-md5.scm (revision 43989) +++ simple-md5.scm (working copy) @@ -6,16 +6,18 @@ (import scheme (chicken base) (chicken blob) (chicken file) (chicken foreign) (chicken file posix) (chicken fixnum) - memory-mapped-files) + (chicken memory) memory-mapped-files) (foreign-declare "#include \"md5-base.c\"") +(foreign-declare "#include ") (define digest-length (foreign-value "MD5_DIGEST_SIZE" unsigned-int)) (define context-size (foreign-value "sizeof(struct MD5Context)" unsigned-int)) +(define chunk-size (foreign-value "INT_MAX" unsigned-integer)) (define init (foreign-lambda void MD5Init scheme-pointer)) -(define update (foreign-lambda void MD5Update scheme-pointer scheme-pointer unsigned-int)) -(define raw-update (foreign-lambda void MD5Update scheme-pointer c-pointer unsigned-int)) +(define update (foreign-lambda void MD5Update scheme-pointer scheme-pointer unsigned-integer)) +(define raw-update (foreign-lambda void MD5Update scheme-pointer c-pointer unsigned-integer)) (define final (foreign-lambda void MD5Final scheme-pointer scheme-pointer)) (define (char->hexdigits c) @@ -52,6 +54,11 @@ (ptr (memory-mapped-file-pointer mmap))) (k ptr (cut unmap-file-from-memory mmap)))))) +(define (chunk-update ctxt buffer fsize) + (unless (zero? fsize) + (let ((size (min fsize chunk-size))) + (raw-update ctxt buffer size) + (chunk-update ctxt (pointer+ buffer size) (- fsize size))))) (define (file-md5sum fname) (and (file-exists? fname) @@ -65,7 +72,7 @@ (mapped-pointer fname fd fsize (lambda (buffer cleanup) - (raw-update ctxt buffer fsize) + (chunk-update ctxt buffer fsize) (cleanup)))) (final ctxt digest) (file-close fd)