class Minitar::Reader::EntryStream
EntryStreams are pseudo-streams on top of the main data stream.
Public Class Methods
Source
# File lib/minitar/reader.rb, line 34 def initialize(header, io) @io = io @name = header.name @mode = header.mode @uid = header.uid @gid = header.gid @size = header.size @mtime = header.mtime @checksum = header.checksum @typeflag = header.typeflag @linkname = header.linkname @magic = header.magic @version = header.version @uname = header.uname @gname = header.gname @devmajor = header.devmajor @devminor = header.devminor @prefix = header.prefix @read = 0 @orig_pos = if Minitar.seekable?(@io) @io.pos else 0 end end
Public Instance Methods
Source
# File lib/minitar/reader.rb, line 138 def closed? false end
Returns false if the entry stream is valid.
Source
# File lib/minitar/reader.rb, line 82 def directory? case @typeflag when "5" true when "0", "\0" # If the name ends with a slash, treat it as a directory. # This is what other major tar implementations do for # interoperability and compatibility with older tar variants # and some new ones. @name.end_with?("/") else false end end
Returns true
if the entry represents a directory.
Also aliased as: directory
Source
# File lib/minitar/reader.rb, line 106 def eof? @read >= @size end
Returns true
if the current read pointer is at the end of the EntryStream
data.
Source
# File lib/minitar/reader.rb, line 99 def file? (@typeflag == "0" || @typeflag == "\0") && !@name.end_with?("/") end
Returns true
if the entry represents a plain file.
Also aliased as: file
Source
# File lib/minitar/reader.rb, line 129 def full_name if @prefix != "" File.join(@prefix, @name) else @name end end
Returns the full and proper name of the entry.
Source
# File lib/minitar/reader.rb, line 74 def getc return nil if @read >= @size ret = @io.getc @read += 1 if ret ret end
Reads one byte from the entry. Returns nil
if there is no more data to read.
Source
# File lib/minitar/reader.rb, line 111 def pos @read end
Returns the current read pointer in the EntryStream
.
Source
# File lib/minitar/reader.rb, line 63 def read(len = nil) return nil if @read >= @size len ||= @size - @read max_read = [len, @size - @read].min ret = @io.read(max_read) @read += ret.bytesize ret end
Reads len
bytes (or all remaining data) from the entry. Returns nil
if there is no more data to read.
Source
# File lib/minitar/reader.rb, line 116 def rewind unless Minitar.seekable?(@io, :pos=) raise Minitar::NonSeekableStream end @io.pos = @orig_pos @read = 0 end
Sets the current read pointer to the beginning of the EntryStream
.
Private Instance Methods
Source
# File lib/minitar/reader.rb, line 149 def invalidate extend InvalidEntryStream end