read


Description:

[ CCode ( cname = "fread" , instance_pos = -1 ) ]
public size_t read (uint8[] buf, size_t size = 1)

Reads specified number of objects in the array buffer from the given input stream stream.

Example: Read n bytes:

public static int main (string[] args) {
// open file stream:
FileStream stream = FileStream.open ("GLib.FileStream.read.vala", "r");
assert (stream != null);

// get file size:
stream.seek (0, FileSeek.END);
long size = stream.tell ();
stream.rewind ();

// load content:
uint8[] buf = new uint8[size];
size_t read = stream.read (buf);
assert (size == read);

// display content:
print ((string) buf);

return 0;
}

valac --pkg glib-2.0 GLib.FileStream.read.vala

Parameters:

buf

pointer to the first object object in the array to be read

size

the element's size, this is always sizeof(uint8) or 1

Returns:

number of objects read successfully