Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from jspanjers/refactor-decompressor
Support decompressor plugins
- Loading branch information
Showing
23 changed files
with
324 additions
and
111 deletions.
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Zip | ||
class DecryptedIo #:nodoc:all | ||
CHUNK_SIZE = 32_768 | ||
|
||
def initialize(io, decrypter) | ||
@io = io | ||
@decrypter = decrypter | ||
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 | ||
|
||
outbuf.replace(buffer.slice!(0...(length || output_buffer.bytesize))) | ||
end | ||
|
||
private | ||
|
||
def eof | ||
buffer.empty? && input_finished? | ||
end | ||
|
||
def buffer | ||
@buffer ||= ''.dup | ||
end | ||
|
||
def input_finished? | ||
@io.eof | ||
end | ||
|
||
def produce_input | ||
@decrypter.decrypt(@io.read(CHUNK_SIZE)) | ||
end | ||
end | ||
end |
This file contains 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 file contains 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 file contains 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 file contains 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 file contains 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 file contains 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 file contains 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 file contains 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
Oops, something went wrong.