Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Roo::Excelx to open streams, correctly this time #222

Merged
merged 1 commit into from
Jun 3, 2015
Merged
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
16 changes: 5 additions & 11 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,13 @@ def process_zipfile(zipfilename_or_stream)
@sheet_files = []

unless is_stream?(zipfilename_or_stream)
process_zipfile_entries Zip::File.open(zipfilename_or_stream).to_a.sort_by(&:name)
zip_file = Zip::File.open(zipfilename_or_stream)
else
stream = Zip::InputStream.open zipfilename_or_stream
begin
entries = []
while (entry = stream.get_next_entry)
entries << entry
end
process_zipfile_entries entries
ensure
stream.close
end
zip_file = Zip::CentralDirectory.new
zip_file.read_from_stream zipfilename_or_stream
end

process_zipfile_entries zip_file.to_a.sort_by(&:name)
end

def process_zipfile_entries(entries)
Expand Down
2 changes: 1 addition & 1 deletion test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ def test_noexpand_merged_range

def test_open_stream
return unless EXCELX
file_contents = File.read File.join(TESTDIR, fixture_filename(:numbers1, :excelx))
file_contents = File.read File.join(TESTDIR, fixture_filename(:numbers1, :excelx)), encoding: 'BINARY'
stream = StringIO.new(file_contents)
xlsx = Roo::Excelx.new(stream)
assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], xlsx.sheets
Expand Down