Module: Zlib
- Defined in:
- lib/pr/zlib.rb,
lib/pr/zlib/errors.rb,
lib/pr/zlib/deflate.rb,
lib/pr/zlib/inflate.rb,
lib/pr/zlib/zstream.rb,
lib/pr/zlib/gzipfile.rb,
lib/pr/zlib/gzipreader.rb,
lib/pr/zlib/gzipwriter.rb,
lib/pr/zlib/gzipfile_errors.rb
Defined Under Namespace
Classes: BufError, DataError, Deflate, Error, GzipFile, GzipReader, GzipWriter, Inflate, MemError, NeedDict, StreamEnd, StreamError, VersionError, ZStream, ZStreamFuncs
Constant Summary
collapse
- RUBY_ZLIB_VERSION =
'0.6.0'.freeze
- PR_ZLIB_VERSION =
'1.1.0'.freeze
- VERSION =
RUBY_ZLIB_VERSION
- ZLIB_VERSION =
Rbzlib::ZLIB_VERSION
- BINARY =
Z_BINARY
- ASCII =
Z_ASCII
- UNKNOWN =
Z_UNKNOWN
- NO_COMPRESSION =
Z_NO_COMPRESSION
- BEST_SPEED =
Z_BEST_SPEED
- BEST_COMPRESSION =
Z_BEST_COMPRESSION
- DEFAULT_COMPRESSION =
Z_DEFAULT_COMPRESSION
- FILTERED =
Z_FILTERED
- HUFFMAN_ONLY =
Z_HUFFMAN_ONLY
- DEFAULT_STRATEGY =
Z_DEFAULT_STRATEGY
- MAX_WBITS =
Rbzlib::MAX_WBITS
- DEF_MEM_LEVEL =
Rbzlib::DEF_MEM_LEVEL
- MAX_MEM_LEVEL =
Rbzlib::MAX_MEM_LEVEL
- NO_FLUSH =
Z_NO_FLUSH
- SYNC_FLUSH =
Z_SYNC_FLUSH
- FULL_FLUSH =
Z_FULL_FLUSH
- FINISH =
Z_FINISH
- OS_CODE =
Rbzlib::OS_CODE
- OS_MSDOS =
0x00
- OS_AMIGA =
0x01
- OS_VMS =
0x02
- OS_UNIX =
0x03
- OS_ATARI =
0x05
- OS_OS2 =
0x06
- OS_MACOS =
0x07
- OS_TOPS20 =
0x0a
- OS_WIN32 =
0x0b
- ZSTREAM_FLAG_READY =
0x1
- ZSTREAM_FLAG_IN_STREAM =
0x2
- ZSTREAM_FLAG_FINISHED =
0x4
- ZSTREAM_FLAG_CLOSING =
0x8
- ZSTREAM_FLAG_UNUSED =
0x10
- ZSTREAM_INITIAL_BUFSIZE =
1024
- ZSTREAM_AVAIL_OUT_STEP_MAX =
16384
- ZSTREAM_AVAIL_OUT_STEP_MIN =
2048
- DeflateFuncs =
ZStreamFuncs.new(:deflateReset, :deflateEnd, :deflate)
- InflateFuncs =
ZStreamFuncs.new(:inflateReset, :inflateEnd, :inflate)
- @@final =
proc do |z|
proc do
if z && z.ZSTREAM_IS_READY()
err = send(z.func.end, z.stream)
if err == Z_STREAM_ERROR
warn('the stream state was inconsistent.')
end
if err == Z_DATA_ERROR
warn('the stream was freed prematurely.')
end
end
end
end
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#z ⇒ Object
Returns the value of attribute z.
317
318
319
|
# File 'lib/pr/zlib/zstream.rb', line 317
def z
@z
end
|
Class Method Details
.adler32(string = nil, adler = nil) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/pr/zlib.rb', line 78
def adler32(string = nil, adler = nil)
if adler
check_long_range adler
sum = adler
elsif string.nil?
sum = 0
else
sum = Rbzlib.adler32(0, nil)
end
if string.nil?
sum = Rbzlib.adler32(sum, nil)
else
sum = Rbzlib.adler32(sum, string, string.length)
end
sum
end
|
.crc32(string = nil, crc = nil) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/pr/zlib.rb', line 96
def crc32(string = nil, crc = nil)
if crc
check_long_range crc
sum = crc
elsif string.nil?
sum = 0
else
sum = Rbzlib.crc32(0, nil)
end
if string.nil?
sum = Rbzlib.crc32(sum, nil)
else
sum = Rbzlib.crc32(sum, string, string.length)
end
sum
end
|
.crc_table ⇒ Object
114
115
116
|
# File 'lib/pr/zlib.rb', line 114
def crc_table
get_crc_table
end
|
.zlib_version ⇒ Object
74
75
76
|
# File 'lib/pr/zlib.rb', line 74
def zlib_version
zlibVersion()
end
|
Instance Method Details
#adler ⇒ Object
355
356
357
|
# File 'lib/pr/zlib/zstream.rb', line 355
def adler
@z.stream.adler
end
|
#avail_in ⇒ Object
337
338
339
|
# File 'lib/pr/zlib/zstream.rb', line 337
def avail_in
@z.input.nil? ? 0 : @z.input.length
end
|
#avail_out ⇒ Object
319
320
321
|
# File 'lib/pr/zlib/zstream.rb', line 319
def avail_out
@z.stream.avail_out
end
|
#avail_out=(size) ⇒ Object
323
324
325
326
327
328
329
330
331
332
333
334
335
|
# File 'lib/pr/zlib/zstream.rb', line 323
def avail_out=(size)
if @z.buf.nil?
@z.buf = Bytef.new(0.chr * size)
@z.stream.next_out = Bytef.new(@z.buf)
@z.stream.avail_out = size
elsif @z.stream.avail_out != size
if @z.buf.offset + size > @z.buf.length
@z.buf.buffer << 0.chr * (@z.buf.offset + size - @z.buf.length)
end
@z.stream.next_out = Bytef.new(@z.buf, @z.buf.offset)
@z.stream.avail_out = size
end
end
|
#close ⇒ Object
Also known as:
end
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/pr/zlib/zstream.rb', line 369
def close
if !@z.ZSTREAM_IS_READY()
warn('attempt to close uninitialized zstream ignored.')
return nil
end
if (@z.flags & ZSTREAM_FLAG_IN_STREAM).nonzero?
warn('attempt to close unfinished zstream reset forced.')
@z.input = nil
end
@z.input = nil
err = send(@z.func.end, @z.stream)
if err != Z_OK
raise_zlib_error(err, @z.stream.msg)
end
@z.flags = 0
end
|
#closed? ⇒ Boolean
Also known as:
ended?
364
365
366
|
# File 'lib/pr/zlib/zstream.rb', line 364
def closed?
@z.ZSTREAM_IS_READY()
end
|
#data_type ⇒ Object
351
352
353
|
# File 'lib/pr/zlib/zstream.rb', line 351
def data_type
@z.stream.data_type
end
|
#finish ⇒ Object
400
401
402
403
|
# File 'lib/pr/zlib/zstream.rb', line 400
def finish
@z.zstream_run('', 0, Z_FINISH)
@z.zstream_detach_buffer()
end
|
#finished? ⇒ Boolean
Also known as:
stream_end?
359
360
361
|
# File 'lib/pr/zlib/zstream.rb', line 359
def finished?
@z.ZSTREAM_IS_FINISHED()
end
|
#flush_next_in ⇒ Object
405
406
407
|
# File 'lib/pr/zlib/zstream.rb', line 405
def flush_next_in
@z.zstream_detach_input
end
|
#flush_next_out ⇒ Object
409
410
411
|
# File 'lib/pr/zlib/zstream.rb', line 409
def flush_next_out
@z.zstream_detach_buffer
end
|
#initialize ⇒ Object
413
414
415
416
|
# File 'lib/pr/zlib/zstream.rb', line 413
def initialize
@z = nil
ObjectSpace.define_finalizer self, @@final.call(@z)
end
|
#reset ⇒ Object
388
389
390
391
392
393
394
395
396
397
398
|
# File 'lib/pr/zlib/zstream.rb', line 388
def reset
err = send(@z.func.reset, @z.stream)
if err != Z_OK
raise_zlib_error(err, @z.stream.msg)
end
@z.flags = ZSTREAM_FLAG_READY
@z.buf = nil
@z.stream.next_out = 0
@z.stream.avail_out = 0
@z.input = nil
end
|
#total_in ⇒ Object
341
342
343
344
|
# File 'lib/pr/zlib/zstream.rb', line 341
def total_in
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@z.stream.total_in
end
|
#total_out ⇒ Object
346
347
348
349
|
# File 'lib/pr/zlib/zstream.rb', line 346
def total_out
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@z.stream.total_out
end
|