class pyvips.vsourcecustom.SourceCustom[source]

Custom sources allow reading data from otherwise unsupported sources. Requires libvips >= 8.9.0.

To use, create a SourceCustom object, then provide callbacks to on_read() and on_seek().


Attach a read handler.

The interface is exactly as The handler is given a number of bytes to fetch, and should return a bytes-like object containing up to that number of bytes. If there is no more data available, it should return None.


Attach a seek handler.

The interface is the same as, so the handler is passed parameters for offset and whence with the same meanings.

However, the handler MUST return the new seek position. A simple way to do this is to call io.tell() and return that result.

Seek handlers are optional. If you do not set one, your source will be treated as unseekable and libvips will do extra caching.