class Archiverb::File

Attributes

bytes[R]
dir[R]

the directory path leading to the file

gid[R]

The user id and group id of the file. Set stat.uname and stat.gname to force ownership by name rather than id.

io[R]

the raw io object, you can add to it prior to calling read

mode[RW]

octal mode

mtime[R]

@return [Time] modification time

name[R]

the basename of the file

path[R]

the path and name of the file

size[R]
stat[R]
uid[R]

The user id and group id of the file. Set stat.uname and stat.gname to force ownership by name rather than id.

Public Class Methods

new(name, io, buff=io, stat=nil, &blk) click to toggle source
# File lib/archiverb/file.rb, line 27
def initialize(name, io, buff=io, stat=nil, &blk)
  buff,stat = stat, buff if buff.is_a?(Stat) || buff.is_a?(::File::Stat)
  stat = Stat.new(io) if stat.nil?

  @name  = ::File.basename(name)
  @dir   = ::File.dirname(name)
  @path  = name
  @mtime = stat.mtime.is_a?(Fixnum) ? Time.at(stat.mtime) : stat.mtime
  @uid   = stat.uid
  @gid   = stat.gid
  @mode  = stat.mode
  @size = stat.size

  @readbuff = buff
  @readback = blk unless blk.nil?
  @io       = io.is_a?(String) ? StringIO.new(io) : io
  @io.binmode
  if @io.respond_to?(:path) && ::File.directory?(@io.path)
    @size     = 0
  end
  @stat     = stat
end

Public Instance Methods

close() click to toggle source

Prevents future access to the contents of the file and hopefully frees up memory.

# File lib/archiverb/file.rb, line 71
def close
  @raw = nil
end
read() click to toggle source
# File lib/archiverb/file.rb, line 50
def read
  return @raw if @raw

  if @readback && @readbuff
    @readback.call(@readbuff)
    @readbuff.close_write
  end

  @io.rewind unless @stat.pipe?

  if @io.respond_to?(:path) && ::File.directory?(@io.path)
    @raw  = ""
  else
    @raw    = @io.read
    @size  = @raw.length
  end
  @io.close
  @raw
end