Method: Vips::SourceCustom#on_read

Defined in:
lib/vips/sourcecustom.rb

#on_read {|length| ... } ⇒ Object

The block is executed to read data from the source. The interface is exactly as IO::read, ie. it takes a maximum number of bytes to read and returns a string of bytes from the source, or nil if the source is already at end of file.

Yield Parameters:

  • length (Integer)

    Read and return up to this many bytes

Yield Returns:

  • (String)

    Up to length bytes of data, or nil for EOF



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vips/sourcecustom.rb', line 60

def on_read &block
  signal_connect "read" do |buf, len|
    chunk = block.call len
    return 0 if chunk == nil
    bytes_read = chunk.bytesize
    buf.put_bytes(0, chunk, 0, bytes_read)
    chunk.clear

    bytes_read
  end
end