Class: Zlib::GzipFile
- Inherits:
-
Object
show all
- Defined in:
- lib/pr/zlib.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 =
OS_UNIX
- GZFILE_FLAG_SYNC =
ZSTREAM_FLAG_UNUSED
(ZSTREAM_FLAG_UNUSED << 1)
(ZSTREAM_FLAG_UNUSED << 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
844
845
846
847
|
# File 'lib/pr/zlib.rb', line 844
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 = Z_DEFAULT_COMPRESSION, strategy = Z_DEFAULT_STRATEGY) ⇒ Object
765
766
767
768
769
770
771
772
773
774
775
776
|
# File 'lib/pr/zlib.rb', line 765
def self.wrap(io, level=Z_DEFAULT_COMPRESSION, strategy=Z_DEFAULT_STRATEGY)
obj = new(io,level,strategy)
if block_given?
begin
yield(obj)
ensure
obj.gzfile_ensure_close()
end
else
return obj
end
end
|
Instance Method Details
#close ⇒ Object
813
814
815
816
817
|
# File 'lib/pr/zlib.rb', line 813
def close
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
gzfile_close(true)
@gz.io
end
|
#closed? ⇒ Boolean
825
826
827
|
# File 'lib/pr/zlib.rb', line 825
def closed?
@gz.io.nil?
end
|
808
809
810
811
|
# File 'lib/pr/zlib.rb', line 808
def
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
@gz. ? @gz..dup : nil
end
|
#crc ⇒ Object
783
784
785
786
|
# File 'lib/pr/zlib.rb', line 783
def crc
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
@gz.crc
end
|
#finish ⇒ Object
819
820
821
822
823
|
# File 'lib/pr/zlib.rb', line 819
def finish
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
gzfile_close(false)
@gz.io
end
|
#gzfile_close(closeflag) ⇒ Object
745
746
747
748
749
750
751
752
753
754
755
756
|
# File 'lib/pr/zlib.rb', line 745
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
758
759
760
761
762
763
|
# File 'lib/pr/zlib.rb', line 758
def gzfile_ensure_close()
if @gz.z.ZSTREAM_IS_READY()
gzfile_close(true)
end
nil
end
|
#GZFILE_IS_FINISHED(gz) ⇒ Object
725
726
727
|
# File 'lib/pr/zlib.rb', line 725
def GZFILE_IS_FINISHED(gz)
gz.z.ZSTREAM_IS_FINISHED() && (gz.z.buf.nil? || gz.z.buf.offset.zero?)
end
|
#level ⇒ Object
793
794
795
796
|
# File 'lib/pr/zlib.rb', line 793
def level
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
@gz.level
end
|
#mtime ⇒ Object
788
789
790
791
|
# File 'lib/pr/zlib.rb', line 788
def mtime
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
Time.at(@gz.mtime)
end
|
#orig_name ⇒ Object
803
804
805
806
|
# File 'lib/pr/zlib.rb', line 803
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
798
799
800
801
|
# File 'lib/pr/zlib.rb', line 798
def os_code
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
@gz.os_code
end
|
#sync ⇒ Object
829
830
831
832
|
# File 'lib/pr/zlib.rb', line 829
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
834
835
836
837
838
839
840
841
842
|
# File 'lib/pr/zlib.rb', line 834
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
778
779
780
781
|
# File 'lib/pr/zlib.rb', line 778
def to_io
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
@gz.io
end
|