#lang racket/base
(provide record-resource
get-records)
(struct resource (path key content) #:prefab)
(define records (make-hash))
(define (get-records a-path)
(hash-ref records a-path '()))
(define (port->bytes p)
(define out (open-output-bytes))
(let loop ()
(define b (read-byte p))
(cond
[(eof-object? b)
(get-output-bytes out)]
[else
(write-byte b out)
(loop)])))
(define (record-resource a-module-path a-resource-path a-key)
(hash-set! records a-module-path
(cons (resource a-resource-path a-key (call-with-input-file a-resource-path
port->bytes))
(hash-ref records a-module-path '()))))