USING: help.markup help.syntax io strings arrays io.backend
-io.files.private quotations ;
+io.files.private quotations sequences ;
IN: io.files
ARTICLE: "io.files" "Reading and writing files"
{ $errors "Throws an error if the file cannot be opened for reading." } ;
HELP: set-file-contents
-{ $values { "str" "a string" } { "path" "a pathname string" } { "encoding" "an encoding descriptor" } }
-{ $description "Sets the contents of a file to a string with the given encoding." }
+{ $values { "seq" sequence } { "path" "a pathname string" } { "encoding" "an encoding descriptor" } }
+{ $description "Sets the contents of a file to a sequence with the given encoding." }
{ $errors "Throws an error if the file cannot be opened for writing." } ;
HELP: file-contents
-{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "str" "a string" } }
-{ $description "Opens the file at the given path using the given encoding, and the contents of that file as a string." }
+{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "seq" sequence } }
+{ $description "Opens the file at the given path using the given encoding, and the contents of that file as a sequence." }
{ $errors "Throws an error if the file cannot be opened for reading." } ;
{ set-file-lines file-lines set-file-contents file-contents } related-words
USING: tools.test io.files io.files.private io.files.temp
io.directories io.encodings.8-bit arrays make system
-io.encodings.binary io
-threads kernel continuations io.encodings.ascii sequences
-strings accessors io.encodings.utf8 math destructors namespaces
-;
+io.encodings.binary io threads kernel continuations
+io.encodings.ascii sequences strings accessors
+io.encodings.utf8 math destructors namespaces ;
IN: io.files.tests
\ exists? must-infer
: with-file-reader ( path encoding quot -- )
[ <file-reader> ] dip with-input-stream ; inline
-: file-contents ( path encoding -- str )
+: file-contents ( path encoding -- seq )
<file-reader> contents ;
: with-file-writer ( path encoding quot -- )
: set-file-lines ( seq path encoding -- )
[ [ print ] each ] with-file-writer ;
-: set-file-contents ( str path encoding -- )
+: set-file-contents ( seq path encoding -- )
[ write ] with-file-writer ;
: with-file-appender ( path encoding quot -- )
13 getenv cwd prepend-path \ image set-global
14 getenv cwd prepend-path \ vm set-global
image parent-directory "resource-path" set-global
-] "io.files" add-init-hook
\ No newline at end of file
+] "io.files" add-init-hook