file-contents and set-file-contents deal in sequences, not strings
							parent
							
								
									d647209ca5
								
							
						
					
					
						commit
						d684e24ee8
					
				| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
USING: help.markup help.syntax io strings arrays io.backend
 | 
					USING: help.markup help.syntax io strings arrays io.backend
 | 
				
			||||||
io.files.private quotations ;
 | 
					io.files.private quotations sequences ;
 | 
				
			||||||
IN: io.files
 | 
					IN: io.files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ARTICLE: "io.files" "Reading and writing 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." } ;
 | 
					{ $errors "Throws an error if the file cannot be opened for reading." } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: set-file-contents
 | 
					HELP: set-file-contents
 | 
				
			||||||
{ $values { "str" "a string" } { "path" "a pathname string" } { "encoding" "an encoding descriptor" } }
 | 
					{ $values { "seq" sequence } { "path" "a pathname string" } { "encoding" "an encoding descriptor" } }
 | 
				
			||||||
{ $description "Sets the contents of a file to a string with the given encoding." }
 | 
					{ $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." } ;
 | 
					{ $errors "Throws an error if the file cannot be opened for writing." } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: file-contents
 | 
					HELP: file-contents
 | 
				
			||||||
{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "str" "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 string." }
 | 
					{ $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." } ;
 | 
					{ $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 set-file-contents file-contents } related-words
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,8 @@
 | 
				
			||||||
USING: tools.test io.files io.files.private io.files.temp
 | 
					USING: tools.test io.files io.files.private io.files.temp
 | 
				
			||||||
io.directories io.encodings.8-bit arrays make system
 | 
					io.directories io.encodings.8-bit arrays make system
 | 
				
			||||||
io.encodings.binary io
 | 
					io.encodings.binary io threads kernel continuations
 | 
				
			||||||
threads kernel continuations io.encodings.ascii sequences
 | 
					io.encodings.ascii sequences strings accessors
 | 
				
			||||||
strings accessors io.encodings.utf8 math destructors namespaces
 | 
					io.encodings.utf8 math destructors namespaces ;
 | 
				
			||||||
;
 | 
					 | 
				
			||||||
IN: io.files.tests
 | 
					IN: io.files.tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\ exists? must-infer
 | 
					\ exists? must-infer
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ HOOK: (file-appender) io-backend ( path -- stream )
 | 
				
			||||||
: with-file-reader ( path encoding quot -- )
 | 
					: with-file-reader ( path encoding quot -- )
 | 
				
			||||||
    [ <file-reader> ] dip with-input-stream ; inline
 | 
					    [ <file-reader> ] dip with-input-stream ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: file-contents ( path encoding -- str )
 | 
					: file-contents ( path encoding -- seq )
 | 
				
			||||||
    <file-reader> contents ;
 | 
					    <file-reader> contents ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: with-file-writer ( path encoding quot -- )
 | 
					: with-file-writer ( path encoding quot -- )
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,7 @@ HOOK: (file-appender) io-backend ( path -- stream )
 | 
				
			||||||
: set-file-lines ( seq path encoding -- )
 | 
					: set-file-lines ( seq path encoding -- )
 | 
				
			||||||
    [ [ print ] each ] with-file-writer ;
 | 
					    [ [ print ] each ] with-file-writer ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: set-file-contents ( str path encoding -- )
 | 
					: set-file-contents ( seq path encoding -- )
 | 
				
			||||||
    [ write ] with-file-writer ;
 | 
					    [ write ] with-file-writer ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: with-file-appender ( path encoding quot -- )
 | 
					: with-file-appender ( path encoding quot -- )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue