((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/vfs" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (toc) (tags "egg")) (section 2 "vfs" (section 3 "Introduction" (p (int-link "tinyclos" "TinyCLOS") " wrappers for some file operations, which are:") (pre "open-input-file\nopen-output-file\nfile-exists?\ndelete-file\nrename-file") (p "When this extension is used, all of the above procedures invoke user-defined generic functions implementing the actual file system operations. Since nearly all file operations (with the exception of those invoking operations from the " (int-link "/man/3/Unit posix" "posix") " library unit) most procedures working on files can take advantage of this facility.") (p "To distinguish between different file-systems, a pathname may be preceded by an URI scheme of the form \"" (tt "<scheme>://") "\".  If no scheme is given the current " (i "default file system") " is used.")) (section 3 "Requirements" (p (int-link "tinyclos") ", " (int-link "regex-case"))) (section 3 "Documentation" (section 4 "class vfs:file-system" (def (sig (class "<vfs:file-system>" (id <vfs:file-system>))) (p "Represents an object that can be accessed via file-system operations."))) (section 4 "vfs:open-input-file") (section 4 "vfs:open-output-file" (def (sig (method "(vfs:open-file FILESYSTEM PATHNAME OUTPUT? MODES)" (id vfs:open-file)) (method "(vfs:open-input-file FILESYSTEM PATHNAME MODES)" (id vfs:open-input-file)) (method "(vfs:open-output-file FILESYSTEM PATHNAME MODES)" (id vfs:open-output-file))) (p "Called for " (tt "FILESYSTEM") " (an instance of " (tt "<vfs:file-system>") ") when a file should be opened for reading or writing. " (tt "PATHNAME") " is a string representing the path to the desired file. " (tt "MODES") " is a list of one or more keywords specifying extra attributes for the file to be opened which are:") (pre "#:append\n#:binary\n#:text") (p "See the " (int-link "/man/3" "The User's Manual") " for a description of these modes. If the " (tt "vfs:open-file") " method is not implemented for a given file system, then either " (tt "vfs:open-input-file") " or " (tt "vfs:open-output-file") " are called, depending on the boolean " (tt "OUTPUT?") ".") (p "All of these generic functions should return a port object."))) (section 4 "vfs:file-exists?" (def (sig (method "(vfs:file-exists? FILESYSTEM PATHNAME)" (id vfs:file-exists?))) (p "Called for " (tt "file-exists?") " when the given pathname refers to " (tt "FILESYSTEM") ". Should return true when the designated file exists or " (tt "#f") " if not."))) (section 4 "vfs:delete-file" (def (sig (method "(vfs:delete-file FILESYSTEM PATHNAME)" (id vfs:delete-file))) (p "Called for " (tt "delete-file!") " and should delete the entity represented by " (tt "PATHNAME") " in the given filesystem."))) (section 4 "vfs:rename-file" (def (sig (method "(vfs:rename-file FILESYSTEM OLDPATHNAME NEWPATHNAME)" (id vfs:rename-file))) (p "Called for " (tt "rename-file") "."))) (section 4 "vfs:register-file-system" (def (sig (procedure "(vfs:register-file-system SCHEME FILESYSTEM)" (id vfs:register-file-system))) (p "Registers a filesystem prefix named " (tt "SCHEME") " (a string) for " (tt "FILESYSTEM") ". Any of the above mentioned file operations that refer to a pathname prefixed with " (tt "<SCHEME>://") " will invoke the appropriate method implemented for " (tt "FILESYSTEM") " or a default method that signals an error. The actual path passed to the file operation methods will receive the pathname with the prefix removed."))) (section 4 "vfs:unregister-file-system" (def (sig (procedure "(vfs:unregister-file-system SCHEME)" (id vfs:unregister-file-system))) (p "Un-registers a filesystem prefix."))) (section 4 "class vfs:local-file-system" (def (sig (class "<vfs:local-file-system>" (id <vfs:local-file-system>))) (p "A subclass of " (tt "<vfs:file-system>") " representing the default local, native fileystem. Implements all methods and does the usual stuff."))) (section 4 "vfs:current-file-system" (def (sig (parameter "vfs:current-file-system" (id vfs:current-file-system))) (p "Holds the current file system, which is used if a pathname has no filesystem prefix.")))) (section 3 "Examples" (highlight scheme "; hash-fs: a simple hash-table based file system\n\n(use vfs tinyclos)\n\n\n(define-class <hash-file-system> (<vfs:file-system>) (table))\n\n(define-method (vfs:open-input-file (fs <hash-file-system>) name modes)\n  (open-input-string\n   (hash-table-ref \n    (slot-ref fs 'table) name\n    (cut error 'open-input-file \"file not found\" name fs)) ) )\n\n(define-method (vfs:open-output-file (fs <hash-file-system>) name modes)\n  (let ((o (open-output-string))\n\t(t (slot-ref fs 'table)))\n    (when (memq #:append modes)\n      (display (hash-table-ref/default t name \"\") o) )\n    (make-output-port\n     (cut display <> o)\n     (cut hash-table-set! t name (get-output-string o)) ) ) )\n\n(define-method (vfs:file-exists? (fs <hash-file-system>) name)\n  (and (hash-table-exists? (slot-ref fs 'table) name) \n       name) )\n\n(define-method (vfs:delete-file (fs <hash-file-system>) name)\n  (hash-table-delete! (slot-ref fs 'table) name) )\n\n(define-method (vfs:rename-file (fs <hash-file-system>) old new)\n  (let* ((t (slot-ref fs 'table))\n\t (x (hash-table-ref\n\t     t old\n\t     (cut error 'rename-file \"file not found\" old fs)) ) )\n    (hash-table-delete! t old)\n    (hash-table-set! t new x) ) )\n\n(define-method (initialize (fs <hash-file-system>) initargs)\n  (set! (slot-ref fs 'table) (make-hash-table string=?)) )\n\n(vfs:register-file-system \"hash\" (make <hash-file-system>))")) (section 3 "Author" (p (int-link "/users/felix winkelmann" "felix winkelmann"))) (section 3 "License" (pre "Copyright (c) 2007, Felix L. Winkelmann\nAll rights reserved.") (pre "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following\nconditions are met:") (pre "  Redistributions of source code must retain the above copyright notice, this list of conditions and the following\n    disclaimer. \n  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following\n    disclaimer in the documentation and/or other materials provided with the distribution. \n  Neither the name of the author nor the names of its contributors may be used to endorse or promote\n    products derived from this software without specific prior written permission. ") (pre "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS\nOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR\nCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\nCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\nOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGE.")) (section 3 "Version History" (dl (dt "0.1") (dd "Initial version")))))