class TarReader::Entry
An entry in tar
Attributes
devmajor[R]
devminor[R]
gid[R]
linkname[R]
magic[R]
mode[R]
mtime[R]
name[R]
pos[R]
prefix[R]
size[R]
typeflag[R]
uid[R]
Public Class Methods
new(tar)
click to toggle source
# File lib/tarreader.rb, line 20 def initialize tar @tar = tar @pos = @tar.pos buf = @tar.read(512) if buf.unpack('A512').first.empty? then @pos = @tar.pos buf = @tar.read(512) throw(:TarReaderEof) if buf.nil? throw(:TarReaderEof) if buf.unpack('A512').first.empty? end throw(:TarReaderEof) if buf.nil? @name = buf.unpack('A100').first @mode = buf[100, 8].to_i(8) @uid = buf[108, 8].to_i(8) @gid = buf[116, 8].to_i(8) @size = buf[124, 12].to_i(8) @mtime = buf[136, 12].to_i(8) cksum = buf[148, 8].to_i(8) xbuf = buf.dup xbuf[148, 8] = ' ' * 8 s = 0 xbuf.each_byte{|c| s += c} raise Errno::EBADF, "checksum #{s} != #{cksum}" unless s == cksum @typeflag = buf[156, 1] @linkname = buf[157, 100].unpack('A100').first @magic = buf[257, 6] if /^ustar/ === @magic @uname, @gname = buf[265, 64].unpack('A32 A32') @devmajor = buf[329, 8].to_i(8) @devminor = buf[337, 8].to_i(8) @prefix = buf[345, 155].unpack('A155').first else @uname = @gname = @devmajor = @devminor = @prefix = nil end @blocksize = @size - 1 @blocksize -= @blocksize % 512 @blocksize += 512 end
Public Instance Methods
end_entry()
click to toggle source
# File lib/tarreader.rb, line 85 def end_entry @tar.pos = @pos + 512 + @blocksize end
gname()
click to toggle source
# File lib/tarreader.rb, line 66 def gname @gname || @gid.to_s end
mode_symbolic()
click to toggle source
# File lib/tarreader.rb, line 70 def mode_symbolic [ case @typeflag when '0', '1' then '-' when '2' then 'l' when '5' then 'd' else @typeflag end, (@mode & 0400).zero? ? '-' : 'r', (@mode & 0200).zero? ? '-' : 'w', (@mode & 0100).zero? ? '-' : 'x', (@mode & 0040).zero? ? '-' : 'r', (@mode & 0020).zero? ? '-' : 'w', (@mode & 0010).zero? ? '-' : 'x', (@mode & 0004).zero? ? '-' : 'r', (@mode & 0002).zero? ? '-' : 'w', (@mode & 0001).zero? ? '-' : 'x' ].join end
read()
click to toggle source
# File lib/tarreader.rb, line 89 def read # rewind to data head @tar.pos = @pos + 512 buf = @tar.read(@size) end_entry return buf end
uname()
click to toggle source
# File lib/tarreader.rb, line 62 def uname @uname || @uid.to_s end