Vips.Sbuf

g GObject.Object GObject.Object Vips.Object Vips.Object GObject.Object->Vips.Object Vips.Sbuf Vips.Sbuf Vips.Object->Vips.Sbuf

Subclasses:

None

Methods

Inherited:

Vips.Object (27), GObject.Object (37)

Structs:

Vips.ObjectClass (1), GObject.ObjectClass (5)

class

new_from_source (source)

get_line ()

get_line_copy ()

get_non_whitespace ()

getc ()

require (require)

skip_whitespace ()

unbuffer ()

ungetc ()

Virtual Methods

Inherited:

Vips.Object (9), GObject.Object (7)

Properties

Inherited:

Vips.Object (2)

Name

Type

Flags

Short Description

input

Vips.Source

r/w

Source to load from

Signals

Inherited:

Vips.Object (4), GObject.Object (1)

Fields

Inherited:

Vips.Object (4), GObject.Object (1)

Name

Type

Access

Description

chars_in_buffer

int

r

input_buffer

bytes

r

line

bytes

r

parent_object

Vips.Object

r

read_point

int

r

source

Vips.Source

r

Class Details

class Vips.Sbuf(**kwargs)
Bases:

Vips.Object

Abstract:

No

Structure:

Vips.SbufClass

A [class`Sbuf`] provides a buffered reading interface for a [class`Source`].

You can fetch lines of text, skip whitespace, and so on.

It is useful for implementing things like CSV readers, for example.

classmethod new_from_source(source)
Parameters:

source (Vips.Source) – source to operate on

Returns:

a new [class`Sbuf`]

Return type:

Vips.Sbuf

Create a [class`Sbuf`] wrapping a source.

get_line()
Returns:

the next line of text, or NULL on EOF or read error.

Return type:

str

Fetch the next line of text from self and return it. The end of line character (or characters, for DOS files) are removed, and the string is terminated with a null (\0 character).

Returns NULL on end of file or read error.

If the line is longer than some arbitrary (but large) limit, it is truncated. If you need to be able to read very long lines, use the slower [method`Sbuf`.get_line_copy].

The return value is owned by self and must not be freed. It is valid until the next get call to self.

get_line_copy()
Returns:

the next line of text, or NULL on EOF or read error.

Return type:

str

Fetch the next line of text from self and return it. The end of line character (or characters, for DOS files) are removed, and the string is terminated with a null (\0 character).

The return result must be freed with [func`GLib`.free].

This is slower than [method`Sbuf`.get_line], but can work with lines of any length.

get_non_whitespace()
Returns:

the next block of non-whitespace, or NULL on EOF or read error.

Return type:

str

Fetch the next chunk of non-whitespace text from the source, and null-terminate it.

After this, the next getc will be the first str of the next block of whitespace (or EOF).

If the first getc is whitespace, stop instantly and return the empty string.

If the item is longer than some arbitrary (but large) limit, it is truncated.

The return value is owned by self and must not be freed. It is valid until the next get call to self.

getc()
Returns:

the next str from self, -1 on read error or EOF.

Return type:

int

Fetch the next character from the source.

If you can, use the macro [funcSBUF_GETC] instead for speed.

require(require)
Parameters:

require (int) – make sure we have at least this many chars available

Returns:

0 on success, -1 on error or EOF.

Return type:

int

Make sure there are at least require bytes of readahead available.

skip_whitespace()
Returns:

0 on success, or -1 on EOF.

Return type:

int

After this, the next getc will be the first str of the next block of non-whitespace (or EOF).

Also skip comments, ie. from any ‘#’ character to the end of the line.

unbuffer()

Discard the input buffer and reset the read point. You must call this before using read or seek on the underlying [class`Source`] class.

ungetc()

The opposite of [method`Sbuf`.getc]: undo the previous getc.

unget more than one character is undefined. Unget at the start of the file does nothing.

If you can, use the macro [funcSBUF_UNGETC] instead for speed.

Property Details

Vips.Sbuf.props.input
Name:

input

Type:

Vips.Source

Default Value:

None

Flags:

READABLE, WRITABLE

Source to load from