racket/collects/web-server/private/md5-store.ss
2008-08-15 18:49:52 +00:00

23 lines
553 B
Scheme
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#lang scheme
(require file/md5)
(provide/contract
[md5-home (parameter/c path?)]
[md5-store (bytes? . -> . bytes?)]
[md5-lookup (bytes? . -> . bytes?)])
(define md5-home (make-parameter (build-path (find-system-path 'home-dir) ".urls")))
(define (md5-store bs)
(define hash (md5 bs))
(with-output-to-file
(build-path (md5-home) (format "~a" hash))
(lambda ()
(write bs))
#:exists 'replace)
hash)
(define (md5-lookup hash)
(with-input-from-file
(build-path (md5-home) (format "~a" hash))
(lambda () (read))))