-
-
Save drbrain/1318552 to your computer and use it in GitHub Desktop.
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
buffer size: 1048576, reading 16348 |
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
require 'zlib' | |
class MyInflate | |
def initialize(input) | |
@z = Zlib::Inflate.new | |
@input = input | |
@buf = '' | |
end | |
def read(n) | |
while !@z.finished? && @buf.size < n | |
@buf << @z.inflate(@input.slice!(0, 1)) | |
end | |
return nil if @z.finished? and @buf.empty? | |
puts "buffer size: #{@buf.size}, reading #{n}" | |
@buf.slice!(0, n) | |
end | |
end | |
compressed = Zlib::Deflate.deflate("0" * 1024 * 1024) | |
z = MyInflate.new(compressed) | |
true while z.read(16348) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment