Class: Vips::TargetCustom
- Inherits:
-
Target
- Object
- GObject::GObject
- Object
- Connection
- Target
- Vips::TargetCustom
- Defined in:
- lib/vips/targetcustom.rb
Overview
A target you can attach action signal handlers to to implememt custom output types.
For example:
file = File.open "some/file/name", "wb"
target = Vips::TargetCustom.new
target.on_write { |bytes| file.write bytes }
image.write_to_target target, ".png"
(just an example -- of course in practice you'd use Vips::Target.new_to_file to write to a named file)
Defined Under Namespace
Modules: TargetCustomLayout Classes: ManagedStruct, Struct
Instance Method Summary collapse
-
#initialize ⇒ TargetCustom
constructor
A new instance of TargetCustom.
-
#on_finish(&block) ⇒ Object
The block is executed at the end of write.
-
#on_write {|bytes| ... } ⇒ Object
The block is executed to write data to the source.
Methods inherited from Target
new_to_descriptor, new_to_file, new_to_memory
Methods inherited from Connection
Methods inherited from Object
#get, #get_pspec, #get_typeof, #get_typeof_error, print_all, #set, #signal_connect
Methods inherited from GObject::GObject
#ffi_managed_struct, ffi_managed_struct, ffi_struct, #ffi_struct
Constructor Details
#initialize ⇒ TargetCustom
Returns a new instance of TargetCustom.
46 47 48 49 50 51 |
# File 'lib/vips/targetcustom.rb', line 46 def initialize pointer = Vips::vips_target_custom_new raise Vips::Error if pointer.null? super pointer end |
Instance Method Details
#on_finish(&block) ⇒ Object
The block is executed at the end of write. It should do any necessary finishing action, such as closing a file.
71 72 73 74 75 |
# File 'lib/vips/targetcustom.rb', line 71 def on_finish &block signal_connect "finish" do block.call() end end |
#on_write {|bytes| ... } ⇒ Object
The block is executed to write data to the source. The interface is exactly as IO::write, ie. it should write the string and return the number of bytes written.
59 60 61 62 63 64 65 66 67 |
# File 'lib/vips/targetcustom.rb', line 59 def on_write &block signal_connect "write" do |p, len| chunk = p.get_bytes(0, len) bytes_written = block.call chunk chunk.clear bytes_written end end |