Vips.Target

g GObject.Object GObject.Object Vips.Object Vips.Object GObject.Object->Vips.Object Vips.Connection Vips.Connection Vips.Target Vips.Target Vips.Connection->Vips.Target Vips.Object->Vips.Connection

Subclasses:

Vips.TargetCustom

Methods

Inherited:

Vips.Connection (2), Vips.Object (27), GObject.Object (37)

Structs:

Vips.ObjectClass (1), GObject.ObjectClass (5)

class

new_temp (based_on)

class

new_to_descriptor (descriptor)

class

new_to_file (filename)

class

new_to_memory ()

end ()

putc (ch)

read (buffer, length)

seek (offset, whence)

steal ()

steal_text ()

write (data, length)

write_amp (str)

writes (str)

Virtual Methods

Inherited:

Vips.Object (9), GObject.Object (7)

do_end ()

do_finish ()

do_read (buffer, length)

do_seek (offset, whence)

do_write (data, length)

Properties

Inherited:

Vips.Connection (2), Vips.Object (2)

Name

Type

Flags

Short Description

blob

Vips.Blob

r/w

Blob to save to

memory

bool

r/w

File descriptor should output to memory

Signals

Inherited:

Vips.Object (4), GObject.Object (1)

Fields

Inherited:

Vips.Object (4), GObject.Object (1)

Name

Type

Access

Description

blob

Vips.Blob

r

delete_on_close

bool

r

delete_on_close_filename

str

r

ended

bool

r

memory

bool

r

memory_buffer

GLib.String

r

output_buffer

bytes

r

parent_object

Vips.Connection

r

position

int

r

write_point

int

r

Class Details

class Vips.Target(**kwargs)
Bases:

Vips.Connection

Abstract:

No

Structure:

Vips.TargetClass

A [class`Target`] provides a unified interface for writing data to various output destinations.

This target could be a socket, file, memory area, or any other destination that accepts byte data.

classmethod new_temp(based_on)
Parameters:

based_on (Vips.Target) – base the temporary target on this target

Returns:

a new target.

Return type:

Vips.Target

Create a temporary target – either a temporary file on disc, or an area in memory, depending on what sort of target based_on is.

::: seealso [ctor`Target`.new_to_file].

classmethod new_to_descriptor(descriptor)
Parameters:

descriptor (int) – write to this file descriptor

Returns:

a new target.

Return type:

Vips.Target

Create a target attached to a file descriptor. descriptor is kept open until the target is finalized.

::: seealso [ctor`Target`.new_to_file].

classmethod new_to_file(filename)
Parameters:

filename (str) – write to this file

Returns:

a new target.

Return type:

Vips.Target

Create a target attached to a file.

classmethod new_to_memory()
Returns:

a new target.

Return type:

Vips.Target

Create a target which will write to a memory area. Read from blob to get memory.

::: seealso [ctor`Target`.new_to_file].

end()
Returns:

0 on success, -1 on error.

Return type:

int

Call this at the end of write to make the target do any cleaning up. You can call it many times.

After a target has been ended, further writes will do nothing.

putc(ch)
Parameters:

ch (int) – character to write

Returns:

0 on success, -1 on error.

Return type:

int

Write a single character ch to self. See the macro [funcTARGET_PUTC] for a faster way to do this.

read(buffer, length)
Parameters:
  • buffer (object or None) – store bytes here

  • length (int) – length of buffer in bytes

Returns:

the number of bytes read, 0 on end of file, -1 on error.

Return type:

int

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()).

Reading from a target sounds weird, but libtiff needs this for multi-page writes. This method will fail for targets like pipes.

seek(offset, whence)
Parameters:
  • offset (int) – offset to seek to

  • whence (int) – seek relative to beginning, offset, or end

Returns:

the new offset, -1 on error.

Return type:

int

Seek the target. This behaves exactly as lseek()).

Seeking a target sounds weird, but libtiff needs this. This method will fail for targets like pipes.

steal()
Returns:

the data

Return type:

bytes

Memory targets only (see [ctor`Target`.new_to_memory]). Steal all data written to the target so far, and call [method`Target`.end].

You must free the returned pointer with [func`GLib`.free].

The data is NOT automatically null-terminated. Use [method`Target`.putc] with a ‘\0’ before calling this to get a null-terminated string.

You can’t call this after [method`Target`.end], since that moves the data to a blob, and we can’t steal from that in case the pointer has been shared.

You can’t call this function more than once.

steal_text()
Returns:

target contents as a null-terminated string.

Return type:

str

As [method`Target`.steal], but return a null-terminated string.

write(data, length)
Parameters:
  • data (object or None) – data to write

  • length (int) – length of data in bytes

Returns:

0 on success, -1 on error.

Return type:

int

Write length bytes from data to the output.

write_amp(str)
Parameters:

str (str) – string to write

Returns:

0 on success, -1 on error.

Return type:

int

Write str to self, but escape stuff that xml hates in text. Our argument string is utf-8.

XML rules:

  • We must escape &<>

  • Don’t escape \n, \t, \r

  • Do escape the other ASCII codes.

writes(str)
Parameters:

str (str) – string to write

Returns:

0 on success, and -1 on error.

Return type:

int

Write a null-terminated string to self.

do_end() virtual
Returns:

0 on success, -1 on error.

Return type:

int

Call this at the end of write to make the target do any cleaning up. You can call it many times.

After a target has been ended, further writes will do nothing.

do_finish() virtual
do_read(buffer, length) virtual
Parameters:
  • buffer (object or None) – store bytes here

  • length (int) – length of buffer in bytes

Returns:

the number of bytes read, 0 on end of file, -1 on error.

Return type:

int

Read up to length bytes from target 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()).

Reading from a target sounds weird, but libtiff needs this for multi-page writes. This method will fail for targets like pipes.

do_seek(offset, whence) virtual
Parameters:
  • offset (int) – offset to seek to

  • whence (int) – seek relative to beginning, offset, or end

Returns:

the new offset, -1 on error.

Return type:

int

Seek the target. This behaves exactly as lseek()).

Seeking a target sounds weird, but libtiff needs this. This method will fail for targets like pipes.

do_write(data, length) virtual
Parameters:
Return type:

int

Property Details

Vips.Target.props.blob
Name:

blob

Type:

Vips.Blob

Default Value:

None

Flags:

READABLE, WRITABLE

Blob to save to

Vips.Target.props.memory
Name:

memory

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

File descriptor should output to memory