Vips.Source¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w |
Blob to load from |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
blob |
r |
||
data |
r |
||
have_tested_seek |
r |
||
header_bytes |
r |
||
is_pipe |
r |
||
mmap_baseaddr |
r |
||
mmap_length |
r |
||
parent_object |
r |
||
read_position |
r |
Class Details¶
- class Vips.Source(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A [class`Source`] provides a unified interface for reading, seeking, and mapping data, regardless of the underlying source type.
This source can originate from something like a socket, file or memory area.
During the header phase, we save data from unseekable sources in a buffer so readers can rewind and read again. We don’t buffer data during the decode stage.
- classmethod new_from_blob(blob)¶
- Parameters:
blob (
Vips.Blob) – memory area to load- Returns:
a new source.
- Return type:
Create a source attached to an area of memory.
- classmethod new_from_descriptor(descriptor)¶
- Parameters:
descriptor (
int) – read from this file descriptor- Returns:
a new source.
- Return type:
Create an source attached to a file descriptor. descriptor is closed with close()) when source is finalized.
- classmethod new_from_file(filename)¶
- Parameters:
filename (
str) – read from this filename- Returns:
a new source.
- Return type:
Create a source attached to a file.
If this descriptor does not support mmap and the source is used with a loader that can only work from memory, then the data will be automatically read into memory to EOF before the loader starts. This can produce high memory use if the descriptor represents a large object.
Use [func`pipe_read_limit_set`] to limit the size of object that will be read in this way. The default is 1GB.
- classmethod new_from_memory(data, length)¶
- Parameters:
- Returns:
a new source.
- Return type:
Create a source attached to an area of memory.
You must not free data while the source is active.
- classmethod new_from_options(options)¶
- Parameters:
options (
str) – option string- Returns:
a new source.
- Return type:
Create a source from an option string.
- classmethod new_from_target(target)¶
- Parameters:
target (
Vips.Target) – build the source from this target- Returns:
a new source.
- Return type:
Create a source from a temp target that has been written to.
- decode()¶
- Returns:
0 on success, -1 on error.
- Return type:
Signal the end of header read and the start of the pixel decode phase. After this, you can no longer seek on this source.
Loaders should call this at the end of header read.
::: seealso [method`Source`.unminimise].
- is_file()¶
- Returns:
TRUEif the source is a simple file.- Return type:
Test if this source is a simple file with support for seek. Named pipes, for example, will fail this test. If
TRUE, you can use [method`Connection`.filename] to find the filename.Use this to add basic source support for older loaders which can only work on files.
- is_mappable()¶
- Returns:
TRUEif the source can be efficiently mapped into memory.- Return type:
Some sources can be efficiently mapped into memory. You can still use [method`Source`.map] if this function returns
FALSE, but it will be slow.
- length()¶
- Returns:
number of bytes in source, or -1 on error.
- Return type:
Return the length in bytes of the source. Unseekable sources, for example pipes, will have to be read entirely into memory before the length can be found, so this operation can take a long time.
- map(length)¶
- Parameters:
length (
int) – return the file length here, orNULL- Returns:
a pointer to the start of the file contents, or
NULLon error.- Return type:
Map the source entirely into memory and return a pointer to the start. If length is non-
None, the source size is written to it.This operation can take a long time. Use [method`Source`.is_mappable] to check if a source can be mapped efficiently.
The pointer is valid for as long as self is alive.
- map_blob()¶
- Returns:
a new [struct`Blob`] containing the data, or
NULLon error.- Return type:
Just like [method`Source`.map], but return a [struct`Blob`] containing the pointer. self will stay alive as long as the result is alive.
- minimise()¶
Minimise the source. As many resources as can be safely removed are removed. Use [method`Source`.unminimise] to restore the source if you wish to use it again.
Loaders should call this in response to the minimise signal on their output image.
- read(buffer, length)¶
- Parameters:
- Returns:
the number of bytes read, 0 on end of file, -1 on error.
- Return type:
Read up to length bytes from self and store the bytes in buffer. Return the number of bytes actually read. If all bytes have been read from the file, return 0.
Arguments exactly as read()).
- rewind()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Rewind the source to the start.
You can’t always do this after the pixel decode phase starts – for example, pipe-like sources can’t be rewound.
- seek(offset, whence)¶
- Parameters:
- Returns:
the new file position, or -1 on error.
- Return type:
Move the file read position. You can’t call this after pixel decode starts. The arguments are exactly as lseek()).
- sniff(length)¶
- Parameters:
length (
int) – number of bytes to sniff- Returns:
a pointer to the bytes at the start of the file, or
NULLon error.- Return type:
Return a pointer to the first few bytes of the file. If the file is too short, return
NULL.
- sniff_at_most(data, length)¶
- Parameters:
- Returns:
number of bytes read, or -1 on error.
- Return type:
Attempt to sniff at most length bytes from the start of the source. A pointer to the bytes is returned in data. The number of bytes actually read is returned – it may be less than length if the file is shorter than length. A negative number indicates a read error.
- unminimise()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Restore the source after minimisation. This is called at the start of every source method, so loaders should not usually need this.
::: seealso [method`Source`.minimise].
- do_read(buffer, length) virtual¶
- Parameters:
- Returns:
the number of bytes read, 0 on end of file, -1 on error.
- Return type:
Read up to length bytes from source and store the bytes in buffer. Return the number of bytes actually read. If all bytes have been read from the file, return 0.
Arguments exactly as read()).