Class: Archive::Tar::Minitar::Reader::EntryStream
- Inherits:
-
Object
- Object
- Archive::Tar::Minitar::Reader::EntryStream
- Defined in:
- lib/folio/minitar.rb
Overview
EntryStreams are pseudo-streams on top of the main data stream.
Instance Method Summary collapse
- #bytes_read ⇒ Object
-
#close ⇒ Object
Closes the entry.
-
#directory? ⇒ Boolean
(also: #directory)
Returns
true
if the entry represents a directory. -
#eof? ⇒ Boolean
Returns
true
if the current read pointer is at the end of the EntryStream data. -
#file? ⇒ Boolean
(also: #file)
Returns
true
if the entry represents a plain file. -
#full_name ⇒ Object
Returns the full and proper name of the entry.
-
#getc ⇒ Object
Reads one byte from the entry.
-
#initialize(header, anIO) ⇒ EntryStream
constructor
A new instance of EntryStream.
-
#pos ⇒ Object
Returns the current read pointer in the EntryStream.
-
#read(len = nil) ⇒ Object
Reads
len
bytes (or all remaining data) from the entry. -
#rewind ⇒ Object
Sets the current read pointer to the beginning of the EntryStream.
Constructor Details
#initialize(header, anIO) ⇒ EntryStream
Returns a new instance of EntryStream.
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/folio/minitar.rb', line 546 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_read ⇒ Object
618 619 620 |
# File 'lib/folio/minitar.rb', line 618 def bytes_read @read end |
#close ⇒ Object
Closes the entry.
632 633 634 |
# File 'lib/folio/minitar.rb', line 632 def close invalidate end |
#directory? ⇒ Boolean Also known as: directory
Returns true
if the entry represents a directory.
589 590 591 |
# File 'lib/folio/minitar.rb', line 589 def directory? @typeflag == "5" end |
#eof? ⇒ Boolean
Returns true
if the current read pointer is at the end of the EntryStream data.
602 603 604 |
# File 'lib/folio/minitar.rb', line 602 def eof? @read >= @size end |
#file? ⇒ Boolean Also known as: file
Returns true
if the entry represents a plain file.
595 596 597 |
# File 'lib/folio/minitar.rb', line 595 def file? @typeflag == "0" end |
#full_name ⇒ Object
Returns the full and proper name of the entry.
623 624 625 626 627 628 629 |
# File 'lib/folio/minitar.rb', line 623 def full_name if @prefix != "" File.join(@prefix, @name) else @name end end |
#getc ⇒ Object
Reads one byte from the entry. Returns nil
if there is no more data to read.
581 582 583 584 585 586 |
# File 'lib/folio/minitar.rb', line 581 def getc return nil if @read >= @size ret = @io.getc @read += 1 if ret ret end |
#pos ⇒ Object
Returns the current read pointer in the EntryStream.
607 608 609 |
# File 'lib/folio/minitar.rb', line 607 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.
570 571 572 573 574 575 576 577 |
# File 'lib/folio/minitar.rb', line 570 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 |
#rewind ⇒ Object
Sets the current read pointer to the beginning of the EntryStream.
612 613 614 615 616 |
# File 'lib/folio/minitar.rb', line 612 def rewind raise NonSeekableStream unless @io.respond_to?(:pos=) @io.pos = @orig_pos @read = 0 end |