Last active
April 17, 2024 22:24
Zip example for #ruby IRC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# This is similar to your code to reproduce what it's doing | |
def export_similar_to_your_code | |
io = Zip::OutputStream.write_buffer do |stream| | |
'a'.upto 'z' do |char| | |
stream.put_next_entry "#{char}.txt" | |
stream << char * 42 | |
end | |
ensure | |
stream.close_buffer | |
end | |
io.rewind | |
io.read | |
ensure | |
io.close | |
end | |
## | |
# Compare to the following output | |
def export_suggestion | |
io = StringIO.new | |
stream = Zip::OutputStream.new(io, true) | |
'a'.upto 'z' do |char| | |
stream.put_next_entry "#{char}.txt" | |
stream << char * 42 | |
end | |
io.rewind | |
io.read | |
ensure | |
io.close | |
stream.close_buffer | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment