Class: Zip::ZipInputStream

Inherits:
Object show all
Includes:
IOExtras::AbstractInputStream
Defined in:
lib/zip/zip.rb

Instance Attribute Summary

Attributes included from IOExtras::AbstractInputStream

#lineno

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IOExtras::AbstractInputStream

#each_line, #flush, #gets, #readline, #readlines

Methods included from IOExtras::FakeIO

#kind_of?

Methods included from Enumerable

#deep_clone, #deep_dup, #inject, #select_map

Constructor Details

#initialize(filename, offset = 0) ⇒ ZipInputStream

Returns a new instance of ZipInputStream.



34
35
36
37
38
39
40
# File 'lib/zip/zip.rb', line 34

def initialize(filename, offset = 0)
  super()
  @archiveIO = File.open(filename, "rb")
  @archiveIO.seek(offset, IO::SEEK_SET)
  @decompressor = NullDecompressor.instance
  @currentEntry = nil
end

Class Method Details

.open(filename) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/zip/zip.rb', line 46

def ZipInputStream.open(filename)
  return new(filename) unless block_given?
  
  zio = new(filename)
  yield zio
ensure
  zio.close if zio
end

Instance Method Details

#closeObject



42
43
44
# File 'lib/zip/zip.rb', line 42

def close
  @archiveIO.close
end

#get_next_entryObject



55
56
57
58
59
# File 'lib/zip/zip.rb', line 55

def get_next_entry
  @archiveIO.seek(@currentEntry.next_header_offset, 
    IO::SEEK_SET) if @currentEntry
  open_entry
end

#open_entryObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/zip/zip.rb', line 69

def open_entry
  @currentEntry = ZipEntry.read_local_entry(@archiveIO)
  if (@currentEntry == nil) 
	@decompressor = NullDecompressor.instance
  elsif @currentEntry.compression_method == ZipEntry::STORED
	@decompressor = PassThruDecompressor.new(@archiveIO, 
		 @currentEntry.size)
  elsif @currentEntry.compression_method == ZipEntry::DEFLATED
	@decompressor = Inflater.new(@archiveIO)
  else
	raise ZipCompressionMethodError,
	  "Unsupported compression method #{@currentEntry.compression_method}"
  end
  flush
  return @currentEntry
end

#read(numberOfBytes = nil) ⇒ Object



86
87
88
# File 'lib/zip/zip.rb', line 86

def read(numberOfBytes = nil)
  @decompressor.read(numberOfBytes)
end

#rewindObject



61
62
63
64
65
66
67
# File 'lib/zip/zip.rb', line 61

def rewind
  return if @currentEntry.nil?
  @lineno = 0
  @archiveIO.seek(@currentEntry.localHeaderOffset, 
    IO::SEEK_SET)
  open_entry
end