Skip to content

File Input/Output

file-get-size!

Type
(-> FileHandle Number)
Description
Function takes filehandle provided by file-open! and returns size of file
Parameters
FileHandle - Filehandle
Returns
Number Size of file

file-open!

Type
(-> String String FileHandle)
Description
Function takes path to the file and open options (r, w, c, a, t) both in form of string, creates filehandle and returns it
Parameters
String - Filepath (string atom)
String - Open options (string atom), r - read, w - write, c - create if file doesn't exist, a - append to file, t - truncate file
Returns
FileHandle Filehandle or error if combination of path and open options is wrong (e.g. file doesn't exist and no 'c' in options; or 'rc' option provided, since 'c' demands for 'w')

file-read-exact!

Type
(-> FileHandle Number String)
Description
Function takes filehandle provided by file-open! and desired number of bytes to read (number), reads content of file from current cursor position (number of read bytes <= input number of bytes to read) and returns it in form of string
Parameters
FileHandle - Filehandle
Number - Number of bytes to read
Returns
String File's content

file-read-to-string!

Type
(-> FileHandle String)
Description
Function takes filehandle provided by file-open! reads its content from current cursor place till the end of file and returns content in form of string.
Parameters
FileHandle - Filehandle
Returns
String File's content

file-seek!

Type
(-> FileHandle Number ())
Description
Function takes filehandle provided by file-open! and desired cursor position (number) and sets cursor to provided position
Parameters
FileHandle - Filehandle
Number - Desired cursor position (number)
Returns
() Unit atom

file-write!

Type
(-> FileHandle String ())
Description
Function takes filehandle provided by file-open!, content to be written (string atom) and puts content into file associated with filehandle
Parameters
FileHandle - Filehandle
String - Content (string atom)
Returns
() Unit atom