diff --git a/lib/vips/sourcecustom.rb b/lib/vips/sourcecustom.rb index 9e1c5e7..2002ada 100644 --- a/lib/vips/sourcecustom.rb +++ b/lib/vips/sourcecustom.rb @@ -60,7 +60,7 @@ def initialize def on_read &block signal_connect "read" do |buf, len| chunk = block.call len - return 0 if chunk.nil? + next 0 if chunk.nil? bytes_read = chunk.bytesize buf.put_bytes(0, chunk, 0, bytes_read) chunk.clear diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index 35f3c25..85fe551 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -124,6 +124,17 @@ expect(image.avg).to be_within(0.001).of(109.789) end + it "doesn't print anything when on_read reaches the end" do + file = File.open simg("alpha.png"), "rb" + source = Vips::SourceCustom.new + source.on_read { |length| file.read length } + + expect { + image = Vips::Image.new_from_source source, "" + image.avg + }.not_to output.to_stdout + end + it "on_seek is optional" do file = File.open simg("wagon.jpg"), "rb" source = Vips::SourceCustom.new