! Copyright (C) 2004, 2009 Slava Pestov, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. USING: kernel kernel.private sequences init namespaces system io io.backend io.pathnames io.encodings io.files.private alien.strings ; IN: io.files HOOK: (file-reader) io-backend ( path -- stream ) HOOK: (file-writer) io-backend ( path -- stream ) HOOK: (file-appender) io-backend ( path -- stream ) : ( path encoding -- stream ) swap normalize-path (file-reader) swap ; : ( path encoding -- stream ) swap normalize-path (file-writer) swap ; : ( path encoding -- stream ) swap normalize-path (file-appender) swap ; : file-lines ( path encoding -- seq ) stream-lines ; : with-file-reader ( path encoding quot -- ) [ ] dip with-input-stream ; inline : file-contents ( path encoding -- seq ) stream-contents ; : with-file-writer ( path encoding quot -- ) [ ] dip with-output-stream ; inline : set-file-lines ( seq path encoding -- ) [ [ print ] each ] with-file-writer ; : set-file-contents ( seq path encoding -- ) [ write ] with-file-writer ; : with-file-appender ( path encoding quot -- ) [ ] dip with-output-stream ; inline : exists? ( path -- ? ) normalize-path native-string>alien (exists?) ; ! Current directory [ cwd current-directory set-global 13 getenv alien>native-string cwd prepend-path \ image set-global 14 getenv alien>native-string cwd prepend-path \ vm set-global image parent-directory "resource-path" set-global ] "io.files" add-startup-hook