Skip to content

Instantly share code, notes, and snippets.

@drbrain
Forked from nahi/gist:1318550
Created October 27, 2011 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drbrain/1318552 to your computer and use it in GitHub Desktop.
Save drbrain/1318552 to your computer and use it in GitHub Desktop.
buffer size: 1048576, reading 16348
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