;;;; hash-fs.scm (use srfi-69 vfs tinyclos) (define-class () (table)) (define-method (vfs:open-input-file (fs ) name modes) (open-input-string (hash-table-ref (slot-ref fs 'table) name (cut error 'open-input-file "file not found" name fs)) ) ) (define-method (vfs:open-output-file (fs ) name modes) (let ((o (open-output-string)) (t (slot-ref fs 'table))) (when (memq #:append modes) (display (hash-table-ref/default t name "") o) ) (make-output-port (cut display <> o) (cut hash-table-set! t name (get-output-string o)) ) ) ) (define-method (vfs:file-exists? (fs ) name) (and (hash-table-exists? (slot-ref fs 'table) name) name) ) (define-method (vfs:delete-file (fs ) name) (hash-table-delete! (slot-ref fs 'table) name) ) (define-method (vfs:rename-file (fs ) old new) (let* ((t (slot-ref fs 'table)) (x (hash-table-ref t old (cut error 'rename-file "file not found" old fs)) ) ) (hash-table-delete! t old) (hash-table-set! t new x) ) ) (define-method (initialize (fs ) initargs) (set! (slot-ref fs 'table) (make-hash-table string=?)) ) (vfs:register-file-system "hash" (make ))