Vips.Buf¶
Fields¶
Name |
Type |
Access |
Description |
|---|---|---|---|
base |
r |
||
dynamic |
r |
||
full |
r |
||
i |
r |
||
lasti |
r |
||
mx |
r |
Methods¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
strtxt[256];Vips.Bufbuf = 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:
Return the contents of the buffer as a C string.
- append_size(n)¶
- Parameters:
n (
int) – the number of bytes- Returns:
FALSEon overflow,TRUEotherwise.- Return type:
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:
FALSEon overflow,TRUEotherwise.- Return type:
Append a single character ch to self.
- appendd(d)¶
- Parameters:
d (
int) – value to format and append- Returns:
FALSEon overflow,TRUEotherwise.- Return type:
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:
FALSEon overflow,TRUEotherwise.- Return type:
Append a double, non-localised. Useful for config files etc.
- appendgv(value)¶
- Parameters:
value (
GObject.Value) – [struct`GObject`.Value] to format and append- Returns:
FALSEon overflow,TRUEotherwise.- Return type:
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:
- Returns:
FALSEon overflow,TRUEotherwise.- Return type:
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:
FALSEon overflow,TRUEotherwise.- Return type:
Append the whole of str to self.
- change(o, n)¶
- Parameters:
- Returns:
FALSEon overflow,TRUEotherwise.- Return type:
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:
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.Bufbuf;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:
Initialise and attach to a static memory area. [funcBUF_STATIC] is usually more convenient.
For example:
```c
strtxt[256];Vips.Bufbuf;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.
- removec(ch)¶
- Parameters:
ch (
int) – the character to remove- Returns:
TRUEif a character was removed,FALSEotherwise.- Return type:
Remove the last character, if it’s ch.
- rewind()¶
Reset the buffer to the empty string.