file-contents and set-file-contents deal in sequences, not strings

db4
Doug Coleman 2009-01-29 00:08:40 -06:00
parent d647209ca5
commit d684e24ee8
3 changed files with 11 additions and 12 deletions

View File

@ -1,5 +1,5 @@
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"
@ -63,13 +63,13 @@ HELP: file-lines
{ $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

View File

@ -1,9 +1,8 @@
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

View File

@ -25,7 +25,7 @@ HOOK: (file-appender) io-backend ( path -- stream )
: 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 -- )
@ -34,7 +34,7 @@ HOOK: (file-appender) io-backend ( path -- stream )
: 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 -- )
@ -58,4 +58,4 @@ PRIVATE>
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
] "io.files" add-init-hook