8000 Support decompressor plugins by jspanjers · Pull Request #427 · rubyzip/rubyzip · GitHub
[go: up one dir, main page]

Skip to content

Support decompressor plugins #427

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

Merged
merged 21 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Mimic IO#read return values in Decompressor#read
  • Loading branch information
jspanjers committed Jan 26, 2020
commit 456bd4d92c995dd92cd74286bd6bdde7cc3057ef
11 changes: 2 additions & 9 deletions lib/zip/inflater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ def initialize(*args)

@buffer = ''.dup
@zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
@has_returned_empty_string = false
end

def read(length = nil, outbuf = '')
return ((length.nil? || length.zero?) ? "" : nil) if eof

while length.nil? || (@buffer.bytesize < length)
break if input_finished?
@buffer << produce_input
end

return value_when_finished if eof?

outbuf.replace(@buffer.slice!(0...(length || @buffer.bytesize)))
end

Expand Down Expand Up @@ -43,12 +42,6 @@ def produce_input
def input_finished?
@zlib_inflater.finished?
end

def value_when_finished # mimic behaviour of ruby File object.
return if @has_returned_empty_string
@has_returned_empty_string = true
''
end
end
end

Expand Down
8 changes: 1 addition & 7 deletions lib/zip/pass_thru_decompressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ class PassThruDecompressor < Decompressor #:nodoc:all
def initialize(*args)
super
@read_so_far = 0
@has_returned_empty_string = false
end

def read(length = nil, outbuf = '')
if eof?
has_returned_empty_string_val = @has_returned_empty_string
@has_returned_empty_string = true
return '' unless has_returned_empty_string_val
return
end
return ((length.nil? || length.zero?) ? "" : nil) if eof

if length.nil? || (@read_so_far + length) > decompressed_size
length = decompressed_size - @read_so_far
Expand Down
0