Class: Zlib::GzipFile
- Inherits:
-
Object
show all
- Defined in:
- lib/pr/zlib/gzipfile.rb,
lib/pr/zlib/gzipfile_errors.rb
Defined Under Namespace
Classes: CRCError, Error, Gzfile, LengthError, NoFooter
Constant Summary
collapse
- GZ_MAGIC1 =
0x1f
- GZ_MAGIC2 =
0x8b
- GZ_METHOD_DEFLATE =
8
- GZ_FLAG_MULTIPART =
0x2
0x4
- GZ_FLAG_ORIG_NAME =
0x8
0x10
- GZ_FLAG_ENCRYPT =
0x20
- GZ_FLAG_UNKNOWN_MASK =
0xc0
0x4
0x2
- OS_CODE =
0x03
- GZFILE_FLAG_SYNC =
0x10
(0x10 << 1)
(0x10 << 2)
- GZFILE_READ_SIZE =
2048
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.gzfile_s_open(filename, mode, level, strategy, &blk) ⇒ Object
134
135
136
137
|
# File 'lib/pr/zlib/gzipfile.rb', line 134
def self.gzfile_s_open(filename, mode, level, strategy, &blk)
io = File.open(filename, mode)
self.wrap(io, level, strategy, &blk)
end
|
.wrap(io, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/pr/zlib/gzipfile.rb', line 55
def self.wrap(io, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY)
obj = new(io, level, strategy)
if block_given?
begin
yield(obj)
ensure
obj.gzfile_ensure_close()
end
else
obj
end
end
|
Instance Method Details
#close ⇒ Object
103
104
105
106
107
|
# File 'lib/pr/zlib/gzipfile.rb', line 103
def close
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
gzfile_close(true)
@gz.io
end
|
#closed? ⇒ Boolean
115
116
117
|
# File 'lib/pr/zlib/gzipfile.rb', line 115
def closed?
@gz.io.nil?
end
|
98
99
100
101
|
# File 'lib/pr/zlib/gzipfile.rb', line 98
def
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz. ? @gz..dup : nil
end
|
#crc ⇒ Object
73
74
75
76
|
# File 'lib/pr/zlib/gzipfile.rb', line 73
def crc
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz.crc
end
|
#finish ⇒ Object
109
110
111
112
113
|
# File 'lib/pr/zlib/gzipfile.rb', line 109
def finish
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
gzfile_close(false)
@gz.io
end
|
#gzfile_close(closeflag) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pr/zlib/gzipfile.rb', line 35
def gzfile_close(closeflag)
io = @gz.io
send(@gz.end)
@gz.io = nil
@gz.orig_name = nil
@gz. = nil
if closeflag && defined?(io.close)
io.close
end
end
|
#gzfile_ensure_close ⇒ Object
48
49
50
51
52
53
|
# File 'lib/pr/zlib/gzipfile.rb', line 48
def gzfile_ensure_close
if @gz.z.ZSTREAM_IS_READY()
gzfile_close(true)
end
nil
end
|
#GZFILE_IS_FINISHED(gz) ⇒ Object
27
28
29
|
# File 'lib/pr/zlib/gzipfile.rb', line 27
def GZFILE_IS_FINISHED(gz)
gz.z.ZSTREAM_IS_FINISHED() && (gz.z.buf.nil? || gz.z.buf.offset.zero?)
end
|
#level ⇒ Object
83
84
85
86
|
# File 'lib/pr/zlib/gzipfile.rb', line 83
def level
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz.level
end
|
#mtime ⇒ Object
78
79
80
81
|
# File 'lib/pr/zlib/gzipfile.rb', line 78
def mtime
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
Time.at(@gz.mtime)
end
|
#orig_name ⇒ Object
93
94
95
96
|
# File 'lib/pr/zlib/gzipfile.rb', line 93
def orig_name
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz.orig_name ? @gz.orig_name.dup : nil
end
|
#os_code ⇒ Object
88
89
90
91
|
# File 'lib/pr/zlib/gzipfile.rb', line 88
def os_code
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz.os_code
end
|
#sync ⇒ Object
119
120
121
122
|
# File 'lib/pr/zlib/gzipfile.rb', line 119
def sync
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
!(@gz.z.flags & GZFILE_FLAG_SYNC).zero?
end
|
#sync=(mode) ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'lib/pr/zlib/gzipfile.rb', line 124
def sync=(mode)
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
if mode
@gz.z.flags |= GZFILE_FLAG_SYNC
else
@gz.z.flags &= ~GZFILE_FLAG_SYNC
end
mode
end
|
#to_io ⇒ Object
68
69
70
71
|
# File 'lib/pr/zlib/gzipfile.rb', line 68
def to_io
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz.io
end
|