Class: RIO::ZipFile::Wrap::Stream::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/rio/ext/zipfile/wrap.rb

Instance Method Summary collapse

Constructor Details

#initialize(zipfile) ⇒ Root

Returns a new instance of Root.



58
59
60
61
62
63
# File 'lib/rio/ext/zipfile/wrap.rb', line 58

def initialize(zipfile)
  @zipfile = zipfile
  @infs = RIO::ZipFile::InFile::FS.new(@zipfile)
  @topents = get_topents_
  @entidx = 0
end

Instance Method Details

#closeObject



82
83
84
# File 'lib/rio/ext/zipfile/wrap.rb', line 82

def close
  @zipfile.commit if @zipfile.commit_required?
end

#each(&block) ⇒ Object



77
78
79
80
81
# File 'lib/rio/ext/zipfile/wrap.rb', line 77

def each(&block)
  get_topents_.each { |ent|
    yield ent
  }
end

#get_topents_Object



64
65
66
67
68
69
70
71
# File 'lib/rio/ext/zipfile/wrap.rb', line 64

def get_topents_
  topents = {}
  @zipfile.entries.map{ |ent|
    top = ent.to_s.match(%r|^(/?[^/]+(/)?)|)[1]
    topents[top] = 1 unless topents.has_key?(top)
  }
  topents.keys.map{ |v| rio(RIO::Path::RL.new(v.to_s,{:fs => @infs})) }
end

#readObject



72
73
74
75
76
# File 'lib/rio/ext/zipfile/wrap.rb', line 72

def read
  return nil if @entidx >= @topents.size
  @entidx += 1
  @topents[@entidx-1]
end