Soup.Buffer

Fields

Name

Type

Access

Description

data

object

r/w

the data

length

int

r/w

length of data

Methods

class

new (data)

class

new_with_owner (data, owner, owner_dnotify)

copy ()

free ()

get_as_bytes ()

get_data ()

get_owner ()

new_subbuffer (offset, length)

Details

class Soup.Buffer

A data buffer, generally used to represent a chunk of a Soup.MessageBody.

data is a str because that’s generally convenient; in some situations you may need to cast it to #guchar or another type.

classmethod new(data)
Parameters:

data (bytes) – data

Returns:

the new Soup.Buffer.

Return type:

Soup.Buffer

Creates a new Soup.Buffer containing length bytes from data.

This function is exactly equivalent to Soup.Buffer.new() with Soup.MemoryUse.TAKE as first argument; it exists mainly for convenience and simplifying language bindings.

New in version 2.32.

classmethod new_with_owner(data, owner, owner_dnotify)
Parameters:
  • data (bytes) – data

  • owner (object or None) – pointer to an object that owns data

  • owner_dnotify (GLib.DestroyNotify or None) – a function to free/unref owner when the buffer is freed

Returns:

the new Soup.Buffer.

Return type:

Soup.Buffer

Creates a new Soup.Buffer containing length bytes from data. When the Soup.Buffer is freed, it will call owner_dnotify, passing owner to it. You must ensure that data will remain valid until owner_dnotify is called.

For example, you could use this to create a buffer containing data returned from libxml without needing to do an extra copy:

<informalexample><programlisting> xmlDocDumpMemory (doc, &xmlbody, &len); return Soup.Buffer.new_with_owner (xmlbody, len, xmlbody, (GLib.DestroyNotify)xmlFree); </programlisting></informalexample>

In this example, data and owner are the same, but in other cases they would be different (eg, owner would be a object, and data would be a pointer to one of the object’s fields).

copy()
Returns:

the new (or newly-reffed) buffer

Return type:

Soup.Buffer

Makes a copy of self. In reality, Soup.Buffer is a refcounted type, and calling Soup.Buffer.copy() will normally just increment the refcount on self and return it. However, if self was created with Soup.MemoryUse.TEMPORARY memory, then Soup.Buffer.copy() will actually return a copy of it, so that the data in the copy will remain valid after the temporary buffer is freed.

free()

Frees self. (In reality, as described in the documentation for Soup.Buffer.copy(), this is actually an “unref” operation, and may or may not actually free self.)

get_as_bytes()
Returns:

a new GLib.Bytes which has the same content as the Soup.Buffer.

Return type:

GLib.Bytes

Creates a GLib.Bytes pointing to the same memory as self. The GLib.Bytes will hold a reference on self to ensure that it is not freed while the GLib.Bytes is still valid.

New in version 2.40.

get_data()
Returns:

the pointer to the buffer data is stored here

Return type:

data: bytes

This function exists for use by language bindings, because it’s not currently possible to get the right effect by annotating the fields of Soup.Buffer.

New in version 2.32.

get_owner()
Returns:

the owner pointer

Return type:

object or None

Gets the “owner” object for a buffer created with Soup.Buffer.new_with_owner().

new_subbuffer(offset, length)
Parameters:
  • offset (int) – offset within self to start at

  • length (int) – number of bytes to copy from self

Returns:

the new Soup.Buffer.

Return type:

Soup.Buffer

Creates a new Soup.Buffer containing length bytes “copied” from self starting at offset. (Normally this will not actually copy any data, but will instead simply reference the same data as self does.)