Class: Zlib::GzipFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pr/zlib.rb

Direct Known Subclasses

GzipReader, GzipWriter

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
GZ_FLAG_EXTRA =
0x4
GZ_FLAG_ORIG_NAME =
0x8
GZ_FLAG_COMMENT =
0x10
GZ_FLAG_ENCRYPT =
0x20
GZ_FLAG_UNKNOWN_MASK =
0xc0
GZ_EXTRAFLAG_FAST =
0x4
GZ_EXTRAFLAG_SLOW =
0x2
OS_CODE =
OS_UNIX
GZFILE_FLAG_SYNC =
ZSTREAM_FLAG_UNUSED
GZFILE_FLAG_HEADER_FINISHED =
(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



848
849
850
851
# File 'lib/pr/zlib.rb', line 848

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



769
770
771
772
773
774
775
776
777
778
779
780
# File 'lib/pr/zlib.rb', line 769

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

#closeObject

Raises:



817
818
819
820
821
# File 'lib/pr/zlib.rb', line 817

def close
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  gzfile_close(true)
  @gz.io
end

#closed?Boolean

Returns:

  • (Boolean)


829
830
831
# File 'lib/pr/zlib.rb', line 829

def closed?
  @gz.io.nil?
end

#commentObject

Raises:



812
813
814
815
# File 'lib/pr/zlib.rb', line 812

def comment
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  @gz.comment ? @gz.comment.dup : nil
end

#crcObject

Raises:



787
788
789
790
# File 'lib/pr/zlib.rb', line 787

def crc
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  @gz.crc
end

#finishObject

Raises:



823
824
825
826
827
# File 'lib/pr/zlib.rb', line 823

def finish
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  gzfile_close(false)
  @gz.io
end

#gzfile_close(closeflag) ⇒ Object



749
750
751
752
753
754
755
756
757
758
759
760
# File 'lib/pr/zlib.rb', line 749

def gzfile_close(closeflag)
  io = @gz.io
  send(@gz.end)

  @gz.io = nil
  @gz.orig_name = nil
  @gz.comment = nil

  if closeflag && defined?(io.close)
    io.close
  end
end

#gzfile_ensure_closeObject



762
763
764
765
766
767
# File 'lib/pr/zlib.rb', line 762

def gzfile_ensure_close()
  if @gz.z.ZSTREAM_IS_READY()
    gzfile_close(true)
  end
  nil
end

#GZFILE_IS_FINISHED(gz) ⇒ Object



729
730
731
# File 'lib/pr/zlib.rb', line 729

def GZFILE_IS_FINISHED(gz)
  gz.z.ZSTREAM_IS_FINISHED() && (gz.z.buf.nil? || gz.z.buf.offset.zero?)
end

#levelObject

Raises:



797
798
799
800
# File 'lib/pr/zlib.rb', line 797

def level
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  @gz.level
end

#mtimeObject

Raises:



792
793
794
795
# File 'lib/pr/zlib.rb', line 792

def mtime
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  Time.at(@gz.mtime)
end

#orig_nameObject

Raises:



807
808
809
810
# File 'lib/pr/zlib.rb', line 807

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_codeObject

Raises:



802
803
804
805
# File 'lib/pr/zlib.rb', line 802

def os_code
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  @gz.os_code
end

#syncObject

Raises:



833
834
835
836
# File 'lib/pr/zlib.rb', line 833

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

Raises:



838
839
840
841
842
843
844
845
846
# File 'lib/pr/zlib.rb', line 838

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_ioObject

Raises:



782
783
784
785
# File 'lib/pr/zlib.rb', line 782

def to_io
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  @gz.io
end