Vips.Dbuf

Fields

Name

Type

Access

Description

allocated_size

int

r

data

int

r

data_size

int

r

write_point

int

r

Methods

allocate (size)

destroy ()

get_write (size)

init ()

minimum_size (size)

read (data, size)

reset ()

seek (offset, whence)

steal (size)

string (size)

tell ()

truncate ()

write (data, size)

write_amp (str)

Details

class Vips.Dbuf
allocate(size)
Parameters:

size (int) – the size to allocate

Returns:

FALSE on out of memory, TRUE otherwise.

Return type:

bool

Make sure self has at least size bytes available after the write point.

destroy()

Destroy self. This frees any allocated memory. Useful for dbufs on the stack.

get_write(size)
Parameters:

size (int or None) – optionally return length in bytes here

Returns:

start of write area.

Return type:

int

Return a pointer to an area you can write to, return length of area in size. Use [method`Dbuf`.allocate] before this call to set a minimum amount of space to have available.

The write point moves to just beyond the returned block. Use [method`Dbuf`.seek] to move it back again.

init()

Initialize self. You can also just init to zero, eg. VipsDbuf buf = {0};.

Destroy with [method`Dbuf`.destroy].

minimum_size(size)
Parameters:

size (int) – the minimum size

Returns:

FALSE on out of memory, TRUE otherwise.

Return type:

bool

Make sure self is at least size bytes.

read(data, size)
Parameters:
  • data (int) – read to this area

  • size (int) – read up to this many bytes

Returns:

the number of bytes transferred.

Return type:

int

Up to size bytes are read from the buffer and copied to data. The number of bytes transferred is returned.

reset()

Reset the buffer to empty. No memory is freed, just the data size and write point are reset.

seek(offset, whence)
Parameters:
  • offset (int) – how to move the write point

  • whence (int) – from start, from end, from current

Return type:

bool

Move the write point. whence can be SEEK_SET, SEEK_CUR, SEEK_END, with the usual meaning.

steal(size)
Parameters:

size (int or None) – optionally return length in bytes here

Returns:

The pointer held by self.

Return type:

int

Destroy a buffer, but rather than freeing memory, a pointer is returned. This must be freed with [func`GLib`.free].

A \0 is appended, but not included in the character count. This is so the pointer can be safely treated as a C string.

string(size)
Parameters:

size (int or None) – optionally return length in bytes here

Returns:

The pointer held by self.

Return type:

int

Return a pointer to self's internal data.

A \0 is appended, but not included in the character count. This is so the pointer can be safely treated as a C string.

tell()
Returns:

the current write point

Return type:

int

truncate()

Truncate the data so that it ends at the write point. No memory is freed.

write(data, size)
Parameters:
  • data (int) – the data to write to the buffer

  • size (int) – the size of the len to write

Returns:

FALSE on out of memory, TRUE otherwise.

Return type:

bool

Append size bytes from data. self expands if necessary.

write_amp(str)
Parameters:

str (str) – string to write

Returns:

FALSE on out of memory, TRUE otherwise.

Return type:

bool

Write str to self, but escape stuff that xml hates in text. Our argument string is utf-8.

XML rules:

  • We must escape &<>

  • Don’t escape \n, \t, \r

  • Do escape the other ASCII codes.