Soup.Buffer¶
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 - strbecause 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.Buffercontaining length bytes from data.- This function is exactly equivalent to - Soup.Buffer.new() with- Soup.MemoryUse.TAKEas 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 (objectorNone) – pointer to an object that owns data
- owner_dnotify (GLib.DestroyNotifyorNone) – a function to free/unref owner when the buffer is freed
 - Returns: - the new - Soup.Buffer.- Return type: - Creates a new - Soup.Buffercontaining length bytes from data. When the- Soup.Bufferis 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). 
- data (
 - 
copy()¶
- Returns: - the new (or newly-reffed) buffer - Return type: - Soup.Buffer- Makes a copy of self. In reality, - Soup.Bufferis 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.TEMPORARYmemory, 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.Byteswhich has the same content as the- Soup.Buffer.- Return type: - GLib.Bytes- Creates a - GLib.Bytespointing to the same memory as self. The- GLib.Byteswill hold a reference on self to ensure that it is not freed while the- GLib.Bytesis 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: - objector- None- Gets the “owner” object for a buffer created with - Soup.Buffer.new_with_owner().
 - 
new_subbuffer(offset, length)¶
- Parameters: - Returns: - the new - Soup.Buffer.- Return type: - Creates a new - Soup.Buffercontaining 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.)
 
- 
classmethod