{ $subsections
file-contents
set-file-contents
+ change-file-contents
file-lines
set-file-lines
+ change-file-lines
}
"Utility combinators:"
{ $subsections
}
{ $errors "Throws an error if the file cannot be opened for reading." } ;
+HELP: change-file-lines
+{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "quot" quotation }
+{ $description "Reads the file lines, transforms the file lines, and writes them back to the same file name." }
+{ $errors "Throws an error if the file cannot be opened for writing." } ;
+
HELP: set-file-contents
{ $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: change-file-contents
+{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "quot" quotation }
+{ $description "Reads the file, transforms the file contents, and writes it back to the same file name." }
+{ $errors "Throws an error if the file cannot be opened for writing." } ;
+
HELP: file-contents
{ $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
+{ set-file-lines file-lines change-file-lines set-file-contents file-contents change-file-contents } related-words
HELP: exists?
{ $values { "path" "a pathname string" } { "?" boolean } }
: set-file-lines ( seq path encoding -- )
[ [ print ] each ] with-file-writer ;
+: change-file-lines ( path encoding quot -- )
+ [ [ file-lines ] dip call ]
+ [ drop set-file-lines ] 3bi ; inline
+
: set-file-contents ( seq path encoding -- )
[ write ] with-file-writer ;
+: change-file-contents ( path encoding quot -- )
+ [ [ file-contents ] dip call ]
+ [ drop set-file-contents ] 3bi ; inline
+
: with-file-appender ( path encoding quot -- )
[ <file-appender> ] dip with-output-stream ; inline