Difference between revisions of "Buffer to file"

From Kolmafia
Jump to navigation Jump to search
(Created page with "<onlyinclude>{{{{{format|Function2}}} |name=buffer_to_file |function1.return_type=boolean |function1.description=Saves a buffer to a text file. Returns <code>true</code> on su...")
 
m
 
Line 9: Line 9:
 
|function1.param2.type=string
 
|function1.param2.type=string
 
|function1.param2.description=Path to the text file to save
 
|function1.param2.description=Path to the text file to save
|description=<p>This function was added in [https://kolmafia.us/threads/19439-you-can-create-a-bottle-of-sea-wine-by-using-a-bunch-of-sea-grapes-add-some-a.24054/ r19439].</p>
+
|description=This function was added in [https://kolmafia.us/threads/19439-you-can-create-a-bottle-of-sea-wine-by-using-a-bunch-of-sea-grapes-add-some-a.24054/ r19439].
 
|code1={{CodeSample
 
|code1={{CodeSample
 
   |title=Code Samples
 
   |title=Code Samples

Latest revision as of 05:33, 21 December 2020

Function Syntax

boolean buffer_to_filebuffer data, string filepath )

Saves a buffer to a text file. Returns true on success, false on failure.
  • data: Buffer to save
  • filepath: Path to the text file to save

This function was added in r19439.

Code Samples

Saves a string (automatically converted to a buffer) to a text file.

string contents = "Hello, world!";
if (!buffer_to_file(contents, "mydata.txt")) {
   abort("Failed to save data to mydata.txt");
}

See Also

file_to_array() | file_to_buffer() | file_to_map() | map_to_file()