class Zlib::Deflate

Public Class Methods

deflate(src,level=Z_DEFAULT_COMPRESSION) click to toggle source
# File lib/pr/zlib.rb, line 513
def self.deflate(src,level=Z_DEFAULT_COMPRESSION)
  @z = ZStream.new
  @z.zstream_init(DeflateFuncs)
  err = deflateInit(@z.stream, level)
  if (err != Z_OK)
   raise_zlib_error(err, @z.stream.msg)
  end
  @z.ZSTREAM_READY()

  begin
    dst = deflate_run(src)
  ensure
    @z.zstream_end()
  end
  dst
end
deflate_run(src) click to toggle source
# File lib/pr/zlib.rb, line 508
def self.deflate_run(src)
  @z.zstream_run(src,src.length,Z_FINISH)
  return @z.zstream_detach_buffer()
end
new(level=Z_DEFAULT_COMPRESSION,wbits=MAX_WBITS,memlevel=DEF_MEM_LEVEL,strategy=Z_DEFAULT_STRATEGY) click to toggle source
# File lib/pr/zlib.rb, line 530
def initialize(level=Z_DEFAULT_COMPRESSION,wbits=MAX_WBITS,memlevel=DEF_MEM_LEVEL,strategy=Z_DEFAULT_STRATEGY)
  @z = ZStream.new
  @z.zstream_init(DeflateFuncs)
  err = deflateInit2(@z.stream,level,Z_DEFLATED,wbits,memlevel,strategy)
  if (err != Z_OK)
   raise_zlib_error(err, @z.stream.msg)
  end
  @z.ZSTREAM_READY()
end

Public Instance Methods

<<(src) click to toggle source
# File lib/pr/zlib.rb, line 566
def <<(src)
  do_deflate(src,Z_NO_FLUSH)
  self
end
deflate(src,flush=Z_NO_FLUSH) click to toggle source
# File lib/pr/zlib.rb, line 561
def deflate(src,flush=Z_NO_FLUSH)
  do_deflate(src,flush)
  @z.zstream_detach_buffer
end
flush(v_flush) click to toggle source
# File lib/pr/zlib.rb, line 571
def flush(v_flush)
  if(v_flush != Z_NO_FLUSH)
    @z.zstream_run("", 0, flush)
  end
  @z.zstream_detach_buffer()
end
initialize_copy(orig) click to toggle source
# File lib/pr/zlib.rb, line 540
def initialize_copy(orig)
  z1 = @z
  z2 = orig.z
  err = deflateCopy(z1.stream, z2.stream)
  if (err != Z_OK)
    raise_zlib_error(err, 0)
  end
  z1.flags = z2.flags
end
params(level=Z_DEFAULT_COMPRESSION,strategy=Z_DEFAULT_STRATEGY) click to toggle source
# File lib/pr/zlib.rb, line 578
def params(level=Z_DEFAULT_COMPRESSION,strategy=Z_DEFAULT_STRATEGY)
  err = deflateParams(@z.stream, level, strategy)
  while (err == Z_BUF_ERROR)
    warn("deflateParams() returned Z_BUF_ERROR")
     @z.zstream_expand_buffer()
     err = deflateParams(@z.stream, level, strategy)
  end
  if (err != Z_OK)
     raise_zlib_error(err, @z.stream.msg)
  end

  nil
end
set_dictionary(dic) click to toggle source
# File lib/pr/zlib.rb, line 592
def set_dictionary(dic)
  err = deflateSetDictionary(@z.stream,dic,dic.length)
  if (err != Z_OK)
    raise_zlib_error(err, @z.stream.msg)
  end
end

Private Instance Methods

do_deflate(src,flush) click to toggle source
# File lib/pr/zlib.rb, line 550
def do_deflate(src,flush)
  if src.nil?
    @z.zstream_run('',0,Z_FINISH)
    return
  end
  if (flush != Z_NO_FLUSH || (src && src.length>0))
    @z.zstream_run(src,src.length,flush)
  end
end