Vips.Buf

Fields

Name

Type

Access

Description

base

str

r

dynamic

bool

r

full

bool

r

i

int

r

lasti

int

r

mx

int

r

Methods

all ()

append_size (n)

appendc (ch)

appendd (d)

appendg (g)

appendgv (value)

appendns (str, sz)

appends (str)

change (o, n)

destroy ()

firstline ()

init ()

init_dynamic (mx)

init_static (base, mx)

is_empty ()

is_full ()

len ()

removec (ch)

rewind ()

set_dynamic (mx)

set_static (base, mx)

Details

class Vips.Buf

A message buffer you can append stuff to safely and quickly. If the message gets too long, you get “…” and truncation. Message buffers can be on the stack or heap.

For example:

```c str txt[256]; Vips.Buf buf = VIPS_BUF_STATIC(txt); int i;

Vips.Buf.appends(&buf, “Numbers are: “); for (i = 0; i < array_length; i++) { if (i > 0) Vips.Buf.appends(&buf, “, “); Vips.Buf.appendg(&buf, array[i]); } printf(“%s”, Vips.Buf.all(&buf)); ```

all()
Returns:

the NULL-terminated contents of the buffer. This is a pointer to the memory managed by the buffer and must not be freed.

Return type:

str

Return the contents of the buffer as a C string.

append_size(n)
Parameters:

n (int) – the number of bytes

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Turn a number of bytes into a sensible string … eg “12”, “12KB”, “12MB”, “12GB” etc.

appendc(ch)
Parameters:

ch (int) – the character to append to the buffer

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Append a single character ch to self.

appendd(d)
Parameters:

d (int) – value to format and append

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Append a number. If the number is -ve, add brackets. Needed for building function arguments.

appendg(g)
Parameters:

g (float) – value to format and append

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Append a double, non-localised. Useful for config files etc.

appendgv(value)
Parameters:

value (GObject.Value) – [struct`GObject`.Value] to format and append

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Format and append a [struct`GObject`.Value] as a printable thing. We display text like “3144 bytes of binary data” for BLOBs like icc-profile-data.

Use [method`Image`.get_as_string] to make a text representation of a field. That will base64-encode blobs, for example.

appendns(str, sz)
Parameters:
  • str (str) – the string to append to the buffer

  • sz (int) – the size of the string to append

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Append at most sz chars from str to self. sz < 0 means unlimited. This is the low-level append operation: functions like [method`Buf`.appendf] build on top of this.

appends(str)
Parameters:

str (str) – the string to append to the buffer

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Append the whole of str to self.

change(o, n)
Parameters:
  • o (str) – the string to search for

  • n (str) – the string to substitute

Returns:

FALSE on overflow, TRUE otherwise.

Return type:

bool

Swap the rightmost occurrence of o for n.

destroy()

Destroy a buffer. Only needed for heap buffers. Leaves the buffer in the _init state.

firstline()
Returns:

the NULL-terminated contents of the buffer. This is a pointer to the memory managed by the buffer and must not be freed.

Return type:

str

Trim to just the first line (excluding “\n”).

init()

Initialize a buffer.

init_dynamic(mx)
Parameters:

mx (int) – the size of the storage area

Initialise and attach to a heap memory area. The memory area needs to be at least 4 bytes long.

```c Vips.Buf buf;

Vips.Buf.init_dynamic(&buf, 256); ```

Dynamic buffers must be freed with [method`Buf`.destroy], but their size can be set at runtime.

init_static(base, mx)
Parameters:
  • base (str) – the start of the memory area to use for storage

  • mx (int) – the size of the storage area

Initialise and attach to a static memory area. [funcBUF_STATIC] is usually more convenient.

For example:

```c str txt[256]; Vips.Buf buf;

Vips.Buf.init_static(&buf, txt, 256); ```

Static buffers don’t need to be freed when they go out of scope, but their size must be set at compile-time.

is_empty()
Returns:

TRUE if the buffer is empty.

Return type:

bool

is_full()
Returns:

TRUE if the buffer is full.

Return type:

bool

len()
Returns:

the number of characters currently in the buffer.

Return type:

int

removec(ch)
Parameters:

ch (int) – the character to remove

Returns:

TRUE if a character was removed, FALSE otherwise.

Return type:

bool

Remove the last character, if it’s ch.

rewind()

Reset the buffer to the empty string.

set_dynamic(mx)
Parameters:

mx (int) – the size of the storage area

Attach the buffer to a heap memory area. The buffer needs to have been initialised. The memory area needs to be at least 4 bytes long.

set_static(base, mx)
Parameters:
  • base (str) – the start of the memory area to use for storage

  • mx (int) – the size of the storage area

Attach the buffer to a static memory area. The buffer needs to have been initialised. The memory area needs to be at least 4 bytes long.