Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/vips/sourcecustom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down