1 USING: help.markup help.syntax io strings arrays io.backend
2 io.files.private quotations ;
5 ARTICLE: "io.files" "Reading and writing files"
7 { $subsection <file-reader> }
8 { $subsection <file-writer> }
9 { $subsection <file-appender> }
10 "Reading and writing the entire contents of a file; this is only recommended for smaller files:"
11 { $subsection file-contents }
12 { $subsection set-file-contents }
13 { $subsection file-lines }
14 { $subsection set-file-lines }
15 "Utility combinators:"
16 { $subsection with-file-reader }
17 { $subsection with-file-writer }
18 { $subsection with-file-appender } ;
23 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "stream" "an input stream" } }
24 { $description "Outputs an input stream for reading from the specified pathname using the given encoding." }
25 { $errors "Throws an error if the file is unreadable." } ;
28 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "stream" "an output stream" } }
29 { $description "Outputs an output stream for writing to the specified pathname using the given encoding. The file's length is truncated to zero." }
30 { $errors "Throws an error if the file cannot be opened for writing." } ;
33 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "stream" "an output stream" } }
34 { $description "Outputs an output stream for writing to the specified pathname using the given encoding. The stream begins writing at the end of the file." }
35 { $errors "Throws an error if the file cannot be opened for writing." } ;
37 HELP: with-file-reader
38 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "quot" "a quotation" } }
39 { $description "Opens a file for reading and calls the quotation using " { $link with-input-stream } "." }
40 { $errors "Throws an error if the file is unreadable." } ;
42 HELP: with-file-writer
43 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "quot" "a quotation" } }
44 { $description "Opens a file for writing using the given encoding and calls the quotation using " { $link with-output-stream } "." }
45 { $errors "Throws an error if the file cannot be opened for writing." } ;
47 HELP: with-file-appender
48 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "quot" "a quotation" } }
49 { $description "Opens a file for appending using the given encoding and calls the quotation using " { $link with-output-stream } "." }
50 { $errors "Throws an error if the file cannot be opened for writing." } ;
53 { $values { "seq" "an array of strings" } { "path" "a pathname string" } { "encoding" "an encoding descriptor" } }
54 { $description "Sets the contents of a file to the strings with the given encoding." }
55 { $errors "Throws an error if the file cannot be opened for writing." } ;
58 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "seq" "an array of strings" } }
59 { $description "Opens the file at the given path using the given encoding, and returns a list of the lines in that file." }
60 { $errors "Throws an error if the file cannot be opened for reading." } ;
62 HELP: set-file-contents
63 { $values { "str" "a string" } { "path" "a pathname string" } { "encoding" "an encoding descriptor" } }
64 { $description "Sets the contents of a file to a string with the given encoding." }
65 { $errors "Throws an error if the file cannot be opened for writing." } ;
68 { $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "str" "a string" } }
69 { $description "Opens the file at the given path using the given encoding, and the contents of that file as a string." }
70 { $errors "Throws an error if the file cannot be opened for reading." } ;
72 { set-file-lines file-lines set-file-contents file-contents } related-words
75 { $values { "path" "a pathname string" } { "?" "a boolean" } }
76 { $description "Tests if the file named by " { $snippet "path" } " exists." } ;