Class: RIO::ZipFile::RootDir

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rio/ext/zipfile/rootdir.rb

Instance Method Summary collapse

Constructor Details

#initialize(zipfilepath) ⇒ RootDir

Returns a new instance of RootDir.



47
48
49
50
51
52
53
# File 'lib/rio/ext/zipfile/rootdir.rb', line 47

def initialize(zipfilepath)
  @zipfilepath = zipfilepath
  @zipfile = Zip::ZipFile.new(@zipfilepath)
  #puts @zipfile.methods.sort
  @topents = get_topents_
  @entidx = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



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

def method_missing(sym,*args,&block)
  @zipfile.__send__(sym,*args,&block)
end

Instance Method Details

#closeObject



80
81
# File 'lib/rio/ext/zipfile/rootdir.rb', line 80

def close
end

#commitObject



63
64
65
66
# File 'lib/rio/ext/zipfile/rootdir.rb', line 63

def commit
  @zipfile.commit
  @topents = get_topents_
end

#each(&block) ⇒ Object



75
76
77
78
79
# File 'lib/rio/ext/zipfile/rootdir.rb', line 75

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

#get_topents_Object



54
55
56
57
58
59
60
61
62
# File 'lib/rio/ext/zipfile/rootdir.rb', line 54

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

#readObject



67
68
69
70
71
# File 'lib/rio/ext/zipfile/rootdir.rb', line 67

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

#rewindObject



72
73
74
# File 'lib/rio/ext/zipfile/rootdir.rb', line 72

def rewind
  @entidx = 0
end