Prefer block forms to close opened files
This commit is contained in:
parent
d05a268adc
commit
b4eba8dfee
@ -510,22 +510,24 @@ if defined? Zlib
|
|||||||
gz = Zlib::GzipWriter.new(t)
|
gz = Zlib::GzipWriter.new(t)
|
||||||
gz.print("foo")
|
gz.print("foo")
|
||||||
gz.close
|
gz.close
|
||||||
t = File.open(t.path, 'ab')
|
File.open(t.path, 'ab') do |f|
|
||||||
gz = Zlib::GzipWriter.new(t)
|
gz = Zlib::GzipWriter.new(f)
|
||||||
gz.print("bar")
|
gz.print("bar")
|
||||||
gz.close
|
gz.close
|
||||||
|
end
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
t = File.open(t.path, 'rb')
|
File.open(t.path, 'rb') do |f|
|
||||||
Zlib::GzipReader.zcat(t) do |str|
|
Zlib::GzipReader.zcat(f) do |str|
|
||||||
results << str
|
results << str
|
||||||
end
|
end
|
||||||
|
end
|
||||||
assert_equal(["foo", "bar"], results)
|
assert_equal(["foo", "bar"], results)
|
||||||
t.close
|
|
||||||
|
|
||||||
t = File.open(t.path, 'rb')
|
results = File.open(t.path, 'rb') do |f|
|
||||||
assert_equal("foobar", Zlib::GzipReader.zcat(t))
|
Zlib::GzipReader.zcat(f)
|
||||||
t.close
|
end
|
||||||
|
assert_equal("foobar", results)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user