Method _Stdio.Buffer()->output_to()
- Method
output_to
int(-1..)
output_to(Stdio.Stream
|function
(string(8bit)
:int
)fun
,int(0..)
|void
nbytes
)- Description
Write data from the buffer to the indicated file.
- Parameter
fun
Write function. Either one of:
Stdio.Stream
A file object in which the function
write()
will be called.function
(string(8bit)
:int
)A function which will be called with a
string(8bit)
to write and is expected to return anint
indicating the number of bytes successfully written or-1
on failure.- Parameter
nbytes
If
nbytes
is not specified the whole buffer will be written if possible. Otherwise at mostnbytes
will be written.- Returns
Will return the number of bytes that have been written successfully.
If no bytes have been written successfully and
fun()
failed with an error,-1
will be returned.This function is similar to
int(-1..) output_to(Stdio.Stream|function(string(8bit):int) fun, int(0..)|void nbytes) { if (objectp(fun)) fun = ([object]fun)->write; int (0..) total; while (sizeof(this)) { int(0..) bytes = undefinedp(nbytes)?sizeof(this):nbytes; if (bytes > 0x8000) bytes = 0x8000; string(8bit) chunk = read(bytes); int(-1..) written = ([function]fun)(chunk); if (written <= 0) { return total || written; } total += written; if (written < sizeof(chunk)) { unread(sizeof(chunk) - written); } if (!undefinedp(nbytes)) { nbytes -= written; if (!nbytes) { break; } } } return total; }
- Deprecated
This function is going to get deprecated. In case you want to use it against an Stdio.File like object, please consider using the
f->write(buf)
API. If you want to use it against a custom write function, please consider supporting thef->write(buf)
API in it.