|
140 | 140 |
|
141 | 141 | expect(target) |
142 | 142 | end |
| 143 | +end |
| 144 | + |
| 145 | +# 8.13 had a broken on_finish, so close ourselves before 8.14 |
| 146 | +RSpec.describe Vips::SourceCustom, version: [8, 9] do |
| 147 | + it "can write an image to a user output stream with explicit close" do |
| 148 | + image = Vips::Image.new_from_file simg("wagon.jpg") |
143 | 149 |
|
144 | | - it "can write an image to a user output stream" do |
145 | 150 | filename = timg("x5.png") |
146 | 151 | file = File.open filename, "wb" |
147 | 152 | target = Vips::TargetCustom.new |
148 | 153 | target.on_write { |chunk| file.write(chunk) } |
149 | | - target.on_finish { file.close } |
150 | | - image = Vips::Image.new_from_file simg("wagon.jpg") |
151 | 154 | image.write_to_target target, ".png" |
| 155 | + file.close |
152 | 156 |
|
153 | | - image = Vips::Image.new_from_file filename |
154 | | - expect(image) |
155 | | - expect(image.width).to eq(685) |
156 | | - expect(image.height).to eq(478) |
157 | | - expect(image.bands).to eq(3) |
158 | | - expect(image.avg).to be_within(0.001).of(109.789) |
| 157 | + image2 = Vips::Image.new_from_file filename |
| 158 | + expect(image2) |
| 159 | + expect(image2.width).to eq(685) |
| 160 | + expect(image2.height).to eq(478) |
| 161 | + expect(image2.bands).to eq(3) |
| 162 | + expect(image2.avg).to eq(image.avg) |
| 163 | + end |
| 164 | +end |
| 165 | + |
| 166 | +# on_finish started working again in 8.14 (and 8.13.4+, and 8.12 and earlier) |
| 167 | +RSpec.describe Vips::SourceCustom, version: [8, 14] do |
| 168 | + it "can write an image to a user output stream" do |
| 169 | + image = Vips::Image.new_from_file simg("wagon.jpg") |
| 170 | + |
| 171 | + filename = timg("x5.png") |
| 172 | + file = File.open filename, "wb" |
| 173 | + target = Vips::TargetCustom.new |
| 174 | + target.on_write { |chunk| file.write(chunk) } |
| 175 | + target.on_finish { file.close } |
| 176 | + image.write_to_target target, filename |
| 177 | + |
| 178 | + image2 = Vips::Image.new_from_file filename |
| 179 | + expect(image2) |
| 180 | + expect(image2.width).to eq(685) |
| 181 | + expect(image2.height).to eq(478) |
| 182 | + expect(image2.bands).to eq(3) |
| 183 | + expect(image2.avg).to eq(image.avg) |
159 | 184 | end |
160 | 185 | end |
0 commit comments