Skip to content

Commit

Permalink
Merge pull request #139 from artygus/ag/improve-zip-reading
Browse files Browse the repository at this point in the history
Improve zip reading
  • Loading branch information
skoji authored Apr 26, 2024
2 parents 049f5d7 + b754b63 commit 12bc19d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/gepub/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def self.parse(io)
package = nil
package_path = nil
book = nil
Zip::InputStream::open(io) {
|zis|
package, package_path = parse_container(zis, files)
Zip::File.open_buffer(io) {
|zip_file|
package, package_path = parse_container(zip_file, files)
check_consistency_of_package(package, package_path)
parse_files_into_package(files, package)
book = Book.new(package.path)
Expand Down Expand Up @@ -379,12 +379,12 @@ def ncx_xml
end

private
def self.parse_container(zis, files)
def self.parse_container(zip_file, files)
package_path = nil
package = nil
while entry = zis.get_next_entry
zip_file.each do |entry|
if !entry.directory?
files[entry.name] = zis.read
files[entry.name] = zip_file.read(entry)
case entry.name
when MIMETYPE then
if files[MIMETYPE] != MIMETYPE_CONTENTS
Expand Down
6 changes: 6 additions & 0 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@
expect(book.items['p-001'].href).to eq 'xhtml/p-001.xhtml'
expect(book.items['p-001'].content.encoding).to eq Encoding::UTF_8
end
it 'reads EPUB with streamed entries' do
filehandle = File.new(File.dirname(__FILE__) + '/fixtures/testdata/streamed_item.epub')
book = GEPUB::Book.parse(filehandle)
expect(book).to be_instance_of GEPUB::Book
expect(book.items.size).to eq 3
end
end
end
end
Expand Down
Binary file added spec/fixtures/testdata/streamed_item.epub
Binary file not shown.

0 comments on commit 12bc19d

Please sign in to comment.