lib/rio/ext/zipfile/wrap.rb in rio-0.5.1 vs lib/rio/ext/zipfile/wrap.rb in rio-0.6.0

- old
+ new

@@ -1,8 +1,8 @@ #-- # =========================================================================== -# Copyright (c) 2005-2012 Christopher Kleckner +# Copyright (c) 2005-2017 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify @@ -46,23 +46,20 @@ @closed = false @zipstream = zipstream super end def close() - p "CLOSE: #{@zipstream.inspect}" - #p self.__getobj__.methods.sort super @closed = true end end class Dir < DelegateClass(::Zip::ZipFileSystem::ZipFsDirIterator) end class Root def initialize(zipfile) @zipfile = zipfile @infs = RIO::ZipFile::InFile::FS.new(@zipfile) - #puts @zipfile.methods.sort @topents = get_topents_ @entidx = 0 end def get_topents_ topents = {} @@ -81,11 +78,10 @@ get_topents_.each { |ent| yield ent } end def close - p "JERE" @zipfile.commit if @zipfile.commit_required? end end end class File < DelegateClass(::Zip::ZipFileSystem::ZipFsFile) @@ -108,86 +104,5 @@ end end end end __END__ - - - - class CentralDir - include Enumerable - - def initialize(zipfilepath) - @zipfilepath = zipfilepath - @zipfile = Zip::ZipFile.new(@zipfilepath) - #puts @zipfile.methods.sort - 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 = topents.values.map{ |v| rio(RIO::Path::RL.new(v.to_s,{:fs => fs})) } - @entidx = 0 - end -# def method_missing(sym,*args,&block) -# @zipfile.__send__(sym,*args,&block) -# end - def read - return nil if @entidx >= @topents.size - @entidx += 1 - @topents[@entidx-1] - end - def rewind - @entidx = 0 - end - def each(&block) - @topents.each { |ent| - yield ent - } - end - def close - end - end - module FS - class Base < RIO::FS::Base - end - class InFile < Base - attr_reader :file,:dir - def initialize(zipfile) - @zipfile = zipfile - @file = @zipfile.file - @dir = @zipfile.dir - @test = @zipfile.file - end - include RIO::FS::File - include RIO::FS::Dir - include RIO::FS::Test - include RIO::FS::Str - end - - class CentralDir < RIO::FS::Native - def initialize(zipfilepath) - @zipfilepath = zipfilepath - @zipfile = Zip::ZipFile.new(@zipfilepath) - super - end - def mkdir(path) - @zipfile.mkdir(path) - end - def rmdir(path) - @zipfile.remove(path) - end - def file() - self - end - def open(zipfilepath) - @zipfilepath = zipfilepath - @zipfile = Zip::ZipFile.new(@zipfilepath) - RIO::ZipFile::CentralDir.new(@zipfile) - end - - end - - end - end -end