file_writer(path, @key options, buffer_mode, transcoder, permissions = 0o666)
Return a new output stream for the file identified by path
.
If present, options
must be a list of symbols that control aspects of file operations.
The options that are valid are 'create
,
'no_create
, 'maybe_create
,
'append
and 'truncate
.
The 'create
option requires that the file does not exist (otherwise an exception is raised) and
creates the file when it is opened.
The 'no_create
option requires that the file exist (otherwise an exception is raised).
The 'maybe_create
option will create the file if it does not exist. This is the default option.
The 'append
option controls whether output will be added to the end of the file.
This is useful for writing to log files that might be open by more than one process.
By default appending is turned-off.
The 'truncate
option controls whether the file will be truncated when it is opened.
This option is turned-on by default when no 'append
option is provided and turned-off
when 'append
is not provided.
Buffer_mode
is a symbol that controls buffering. Valid values are 'block
,
'line
and 'none
.
By default, buffering is turned off.
If transcoder
is present and is not false
, it must be a
transcoder object and
file_writer
will return a textual output stream that will be encoded with transcoder
.
Otherwise, a binary output stream is returned.
Permissions
control the UNIX permissions that will be attached to the file if it is created.
The default value of this setting is 0o666
.
// writing a utf-8 encoded text file:
let t = transcoder('UTF_8)
let f = file_writer("hello.txt", transcoder = t)
write_chars("hello, world", f)
close_writer(f)