]> gitweb.factorcode.org Git - factor.git/blob - core/io/files/files-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / core / io / files / files-docs.factor
1 USING: help.markup help.syntax io strings arrays io.backend
2 io.files.private quotations ;
3 IN: io.files
4
5 ARTICLE: "io.files" "Reading and writing files"
6 "File streams:"
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 } ;
19
20 ABOUT: "io.files"
21
22 HELP: <file-reader>
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." } ;
26
27 HELP: <file-writer>
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." } ;
31
32 HELP: <file-appender>
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." } ;
36
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." } ;
41
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." } ;
46
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." } ;
51
52 HELP: set-file-lines
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." } ;
56
57 HELP: file-lines
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." } ;
61
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." } ;
66
67 HELP: file-contents
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." } ;
71
72 { set-file-lines file-lines set-file-contents file-contents } related-words
73
74 HELP: exists?
75 { $values { "path" "a pathname string" } { "?" "a boolean" } }
76 { $description "Tests if the file named by " { $snippet "path" } " exists." } ;