Top | Description | Object Hierarchy | Properties | Signals | ![]() | ![]() | ![]() | ![]() |
GObject├── GInputStream│╰── VipsGInputStream╰──VipsObject╰── VipsConnection├── VipsSource│╰── VipsSourceCustom╰── VipsTarget╰── VipsTargetCustom
AVipsConnection is a source or sink of bytes for something like jpegloading, see for examplevips_jpegload_source()
.
It can be connected to a network socket, for example, or perhapsa node.js stream, or to an area of memory.
Subclass to add other input sources. UseVipsSourceCustom andVipsTargetCustom to make a source or target with action signals for::read, ::write and ::seek.
voidvips_pipe_read_limit_set (gint64 limit
);
If a source does not support mmap or seek and the source isused with a loader that can only work from memory, then the data will beautomatically read into memory to EOF before the loader starts. This canproduce high memory use if the descriptor represents a large object.
Usevips_pipe_read_limit_set()
to limit the size of object thatwill be read in this way. The default is 1GB.
Set a value of -1 to mean no limit.
See also:--vips-pipe-read-limit
and the environment variableVIPS_PIPE_READ_LIMIT
.
VipsSource *vips_source_new_from_descriptor (int descriptor
);
Create an source attached to a file descriptor.descriptor
isclosed withclose()
when source is finalized.
VipsSource *vips_source_new_from_file (constchar *filename
);
Create an source attached to a file.
If this descriptor does not support mmap and the source isused with a loader that can only work from memory, then the data will beautomatically read into memory to EOF before the loader starts. This canproduce high memory use if the descriptor represents a large object.
Usevips_pipe_read_limit_set()
to limit the size of object thatwill be read in this way. The default is 1GB.
VipsSource *vips_source_new_from_blob (VipsBlob *blob
);
Create a source attached to an area of memory.
VipsSource *vips_source_new_from_target (VipsTarget *target
);
Create a source from a temp target that has been written to.
VipsSource *vips_source_new_from_memory (constvoid *data
,size_t size
);
Create a source attached to an area of memory.
You must not freedata
while the source is active.
VipsSource *vips_source_new_from_options (constchar *options
);
Create a source from an option string.
voidvips_source_minimise (VipsSource *source
);
Minimise the source. As many resources as can be safely removed areremoved. Usevips_source_unminimise()
to restore the source if you wish touse it again.
Loaders should call this in response to the minimise signal on their outputimage.
intvips_source_unminimise (VipsSource *source
);
Restore the source after minimisation. This is called at the startof every source method, so loaders should not usually need this.
See also:vips_source_minimise()
.
intvips_source_decode (VipsSource *source
);
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.
See also:vips_source_unminimise()
.
gint64vips_source_read (VipsSource *source
,void *data
,size_t length
);
Read up tolength
bytes fromsource
and store the bytes inbuffer
.Return the number of bytes actually read. If all bytes have been read fromthe file, return 0.
Arguments exactly as read(2).
gbooleanvips_source_is_mappable (VipsSource *source
);
Some sources can be efficiently mapped into memory.You can still usevips_source_map()
if this function returnsFALSE
,but it will be slow.
gbooleanvips_source_is_file (VipsSource *source
);
Test if this source is a simple file with support for seek. Named pipes,for example, will fail this test. If TRUE, you can usevips_connection_filename()
to find the filename.
Use this to add basic source support for older loaders which can only workon files.
constvoid *vips_source_map (VipsSource *source
,size_t *length
);
Map the source entirely into memory and return a pointer to thestart. Iflength_out
is non-NULL, the source size is written to it.
This operation can take a long time. Usevips_source_is_mappable()
tocheck if a source can be mapped efficiently.
The pointer is valid for as long assource
is alive.
VipsBlob *vips_source_map_blob (VipsSource *source
);
Just likevips_source_map()
, but return aVipsBlob containing thepointer.source
will stay alive as long as the result is alive.
gint64vips_source_seek (VipsSource *source
,gint64 offset
,int whence
);
Move the file read position. You can't call this after pixel decode starts.The arguments are exactly as lseek(2).
intvips_source_rewind (VipsSource *source
);
Rewind the source to the start.
You can't always do this after the pixel decode phase starts -- forexample, pipe-like sources can't be rewound.
gint64vips_source_sniff_at_most (VipsSource *source
,unsignedchar **data
,size_t length
);
Attempt to sniff at mostlength
bytes from the start of the source. Apointer to the bytes is returned indata
. The number of bytes actuallyread is returned -- it may be less thanlength
if the file is shorter thanlength
. A negative number indicates a read error.
unsignedchar *vips_source_sniff (VipsSource *source
,size_t length
);
Return a pointer to the first few bytes of the file. If the file is tooshort, return NULL.
gint64vips_source_length (VipsSource *source
);
Return the length in bytes of the source. Unseekable sources, forexample pipes, will have to be read entirely into memory before the lengthcan be found, so this operation can take a long time.
VipsSourceCustom *vips_source_custom_new (void
);
Create aVipsSourceCustom. Attach signals to implement read and seek.
GInputStream *vips_g_input_stream_new_from_source (VipsSource *source
);
Create a newGInputStream wrapping aVipsSource. This is useful forloaders like SVG and PDF which support GInput methods.
VipsSourceGInputStream *vips_source_g_input_stream_new (GInputStream *stream
);
Create aVipsSourceGInputStream which wrapsstream
.
VipsTarget *vips_target_new_to_descriptor (int descriptor
);
Create a target attached to a file descriptor.descriptor
is kept open until the target is finalized.
See also:vips_target_new_to_file()
.
VipsTarget *vips_target_new_to_file (constchar *filename
);
Create a target attached to a file.
VipsTarget *vips_target_new_to_memory (void
);
Create a target which will write to a memory area. Read fromblob
to getmemory.
See also:vips_target_new_to_file()
.
VipsTarget *vips_target_new_temp (VipsTarget *target
);
Create a temporary target -- either a temporary file on disc, or an area inmemory, depending on what sort of targetbased_on
is.
See also:vips_target_new_to_file()
.
intvips_target_write (VipsTarget *target
,constvoid *data
,size_t length
);
Writelength
bytes frombuffer
to the output.
gint64vips_target_read (VipsTarget *target
,void *buffer
,size_t length
);
Read up tolength
bytes fromtarget
and store the bytes inbuffer
.Return the number of bytes actually read. If all bytes have been read fromthe file, return 0.
Arguments exactly as read(2).
Reading from a target sounds weird, but libtiff needs this formulti-page writes. This method will fail for targets like pipes.
gint64vips_target_seek (VipsTarget *target
,gint64 offset
,int whence
);
Seek the target. This behaves exactly as lseek(2).
Seeking a target sounds weird, but libtiff needs this. This method willfail for targets like pipes.
intvips_target_end (VipsTarget *target
);
Call this at the end of write to make the target do any cleaning up. Youcan call it many times.
After a target has been ended, further writes will do nothing.
unsignedchar *vips_target_steal (VipsTarget *target
,size_t *length
);
Memory targets only (seevips_target_new_to_memory()
). Steal all datawritten to the target so far, and callvips_target_end()
.
You must free the returned pointer withg_free()
.
The data is NOT automatically null-terminated.vips_target_putc()
a '\0'before calling this to get a null-terminated string.
You can't call this aftervips_target_end()
, since that moves the data to ablob, and we can't steal from that in case the pointer has been be shared.
You can't call this function more than once.
char *vips_target_steal_text (VipsTarget *target
);
Asvips_target_steal_text()
, but return a null-terminated string.
intvips_target_putc (VipsTarget *target
,int ch
);
Write a single characterch
totarget
. See the macroVIPS_TARGET_PUTC()
for a faster way to do this.
intvips_target_writes (VipsTarget *target
,constchar *str
);
Write a null-terminated string totarget
.
intvips_target_writef (VipsTarget *target
,constchar *fmt
,...
);
Format the string and write totarget
.
intvips_target_write_amp (VipsTarget *target
,constchar *str
);
Writestr
totarget
, but escape stuff that xml hates in text. Ourargument string is utf-8.
XML rules:
We must escape &<>
Don't escape \n, \t, \r
Do escape the other ASCII codes.
VipsTargetCustom *vips_target_custom_new (void
);
Create aVipsTargetCustom. Attach signals to implement write and finish.
typedef struct {VipsSourceClass parent_class;} VipsSourceGInputStreamClass;
“descriptor”
property “descriptor”int
File descriptor for read or write.
Owner: VipsConnection
Flags: Read / Write
Allowed values: [-1,1000000000]
Default value: 0
“filename”
property “filename”char *
Name of file to open.
Owner: VipsConnection
Flags: Read / Write
Default value: NULL
“read”
signalgint64user_function (VipsSourceCustom *source_custom,gpointer buffer,gint64 size,gpointer user_data)
This signal is emitted to read bytes from the source intobuffer
.
source_custom | the source being operated on | |
buffer |
| |
size |
| |
user_data | user data set when the signal handler was connected. |
Flags: Action
“seek”
signalgint64user_function (VipsSourceCustom *source_custom,gint64 offset,int whence,gpointer user_data)
This signal is emitted to seek the source. The handler shouldchange the source position appropriately.
The handler for an unseekable source should always return -1.
source_custom | the source being operated on | |
offset |
| |
whence |
| |
user_data | user data set when the signal handler was connected. |
Flags: Action
“end”
signalintuser_function (VipsTargetCustom *target_custom,gpointer user_data)
This signal is emitted at the end of write. The target should doany finishing necessary.
target_custom | the target being operated on | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“finish”
signalvoiduser_function (VipsTargetCustom *target_custom,gpointer user_data)
Deprecated for VipsTargetCustom::end.
target_custom | the target being operated on | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“read”
signalgint64user_function (VipsTargetCustom *target_custom,gpointer buffer,gint64 size,gpointer user_data)
This signal is emitted to read bytes from the target intobuffer
.
The handler for an unreadable target should always return -1.
target_custom | the target being operated on | |
buffer |
| |
size |
| |
user_data | user data set when the signal handler was connected. |
Flags: Action
“seek”
signalgint64user_function (VipsTargetCustom *target_custom,gint64 offset,int whence,gpointer user_data)
This signal is emitted to seek the target. The handler shouldchange the target position appropriately.
The handler for an unseekable target should always return -1.
target_custom | the target being operated on | |
offset |
| |
whence |
| |
user_data | user data set when the signal handler was connected. |
Flags: Action
“write”
signalgint64user_function (VipsTargetCustom *target_custom,gpointer data,gint64 length,gpointer user_data)
This signal is emitted to write bytes to the target.
target_custom | the target being operated on | |
data |
| |
length |
| |
user_data | user data set when the signal handler was connected. |
Flags: Action