Class: Archive::Tar::Minitar::Reader::EntryStream

Inherits:
Object
  • Object
show all
Defined in:
lib/archive/tar/minitar.rb

Overview

EntryStreams are pseudo-streams on top of the main data stream.

Instance Method Summary collapse

Constructor Details

#initialize(header, anIO) ⇒ EntryStream

Returns a new instance of EntryStream.



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/archive/tar/minitar.rb', line 470

def initialize(header, anIO)
  @io       = anIO
  @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 = @io.pos
end

Instance Method Details

#bytes_readObject



542
543
544
# File 'lib/archive/tar/minitar.rb', line 542

def bytes_read
  @read
end

#closeObject

Closes the entry.



556
557
558
# File 'lib/archive/tar/minitar.rb', line 556

def close
  invalidate
end

#directory?Boolean Also known as: directory

Returns true if the entry represents a directory.

Returns:

  • (Boolean)


513
514
515
# File 'lib/archive/tar/minitar.rb', line 513

def directory?
  @typeflag == "5"
end

#eof?Boolean

Returns true if the current read pointer is at the end of the EntryStream data.

Returns:

  • (Boolean)


526
527
528
# File 'lib/archive/tar/minitar.rb', line 526

def eof?
  @read >= @size
end

#file?Boolean Also known as: file

Returns true if the entry represents a plain file.

Returns:

  • (Boolean)


519
520
521
# File 'lib/archive/tar/minitar.rb', line 519

def file?
  @typeflag == "0" or @typeflag == "\0"
end

#full_nameObject

Returns the full and proper name of the entry.



547
548
549
550
551
552
553
# File 'lib/archive/tar/minitar.rb', line 547

def full_name
  if @prefix != ""
    File.join(@prefix, @name)
  else
    @name
  end
end

#getcObject

Reads one byte from the entry. Returns nil if there is no more data to read.



505
506
507
508
509
510
# File 'lib/archive/tar/minitar.rb', line 505

def getc
  return nil if @read >= @size
  ret = @io.getc
  @read += 1 if ret
  ret
end

#posObject

Returns the current read pointer in the EntryStream.



531
532
533
# File 'lib/archive/tar/minitar.rb', line 531

def pos
  @read
end

#read(len = nil) ⇒ Object

Reads len bytes (or all remaining data) from the entry. Returns nil if there is no more data to read.



494
495
496
497
498
499
500
501
# File 'lib/archive/tar/minitar.rb', line 494

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.size
  ret
end

#rewindObject

Sets the current read pointer to the beginning of the EntryStream.

Raises:



536
537
538
539
540
# File 'lib/archive/tar/minitar.rb', line 536

def rewind
  raise NonSeekableStream unless @io.respond_to?(:pos=)
  @io.pos = @orig_pos
  @read = 0
end