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 an int 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 most nbytes 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.

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 the f->write(buf) API in it.