Sha256: 58adf45cd28a09112059f98bbe0c392d2f6127f48a7363f1a10b25b9d643a5d0

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

#!ruby

require "zip/filesystem"
require_relative "../invfs"

using InVFS::Extensions

def InVFS.zip(*args)
  InVFS::Zip.new(*args)
end

module InVFS
  class Zip
    attr_reader :path, :zip, :zipfile

    def initialize(path)
      @path = String(path)
      @zip = ::Zip::File.open(@path)
      @zipfile = @zip.file
    end

    #
    # call-seq:
    #   to_path -> string
    #
    # REQUIRED method for VFS.
    #
    # This value MUST be not modifying in each objects.
    #
    def to_path
      path
    end

    #
    # call-seq:
    #   file?(path) -> true OR false (OR nil)
    #
    # REQUIRED method for VFS.
    #
    def file?(path)
      zipfile.file?(path)
    end

    #
    # call-seq:
    #   size(path) -> integer for file size
    #
    # REQUIRED method for VFS.
    #
    def size(path)
      zipfile.size(path)
    end

    #
    # call-seq:
    #   read(path) -> string
    #
    # REQUIRED method for VFS.
    #
    def read(path)
      zipfile.read(path)
    end

    #
    # optional method for VFS.
    #
    def to_s
      %(#{path} (#{self.class}))
    end

    def inspect
      %(#<#{self.class}:#{path}>)
    end

    def pretty_print(q)
      q.text inspect
    end
  end

  class Zip
    #
    # VFS Handler Methods
    ;

    #
    # call-seq:
    #   probe(file) -> true or false
    #
    # REQUIRED method for VFS Handler.
    #
    # Check available as VFS.
    #
    def Zip.probe(file)
      file.readat(0, 4) == "PK\x03\x04"
    end

    #
    # call-seq:
    #   open(file) -> VFS object
    #
    # REQUIRED method for VFS Handler.
    #
    # Open as VFS.
    #
    def Zip.open(file)
      new file
    end

    #
    # Regist handler as VFS.
    #
    InVFS.regist self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
invfs-0.3 lib/invfs/zip.rb