Class: NTFS::AttribData
- Inherits:
-
Object
- Object
- NTFS::AttribData
- Defined in:
- lib/fs/ntfs/attrib_data.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#run ⇒ Object
readonly
Returns the value of attribute run.
Class Method Summary collapse
-
.create_from_header(header, buf) ⇒ Object
DATA_ATTR - Attribute: Data attribute (0x80).
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(buf) ⇒ AttribData
constructor
A new instance of AttribData.
-
#read(bytes = @length) ⇒ Object
This now behaves exactly like a normal read.
- #rewind ⇒ Object
- #seek(offset, method = IO::SEEK_SET) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(buf) ⇒ AttribData
Returns a new instance of AttribData.
20 21 22 23 24 25 |
# File 'lib/fs/ntfs/attrib_data.rb', line 20 def initialize(buf) @run = buf if buf.kind_of?(NTFS::DataRun) @data = buf @length = @data.length @pos = 0 end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
18 19 20 |
# File 'lib/fs/ntfs/attrib_data.rb', line 18 def data @data end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
18 19 20 |
# File 'lib/fs/ntfs/attrib_data.rb', line 18 def length @length end |
#run ⇒ Object (readonly)
Returns the value of attribute run.
18 19 20 |
# File 'lib/fs/ntfs/attrib_data.rb', line 18 def run @run end |
Class Method Details
.create_from_header(header, buf) ⇒ Object
DATA_ATTR - Attribute: Data attribute (0x80)
NOTE: Can be resident or non-resident.
Data contents of a file (i.e. the unnamed stream) or of a named stream.
12 13 14 15 16 |
# File 'lib/fs/ntfs/attrib_data.rb', line 12 def self.create_from_header(header, buf) return AttribData.new(buf) if header.namelen == 0 $log.debug("MFT Alternate Data Stream (#{header.name})") if $log nil end |
Instance Method Details
#dump ⇒ Object
67 68 69 70 71 72 |
# File 'lib/fs/ntfs/attrib_data.rb', line 67 def dump out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n" out << " Length: #{@length}\n" out << @data.dumpRunList if @data.class == NTFS::DataRun out << "---\n" end |
#read(bytes = @length) ⇒ Object
This now behaves exactly like a normal read.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fs/ntfs/attrib_data.rb', line 41 def read(bytes = @length) return nil if @pos >= @length bytes = @length - @pos if bytes.nil? bytes = @length - @pos if @pos + bytes > @length out = @data[@pos, bytes] if @data.kind_of?(String) out = @data.read(bytes) if @data.kind_of?(NTFS::DataRun) @pos += out.size out end |
#rewind ⇒ Object
63 64 65 |
# File 'lib/fs/ntfs/attrib_data.rb', line 63 def rewind seek(0) end |
#seek(offset, method = IO::SEEK_SET) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/fs/ntfs/attrib_data.rb', line 53 def seek(offset, method = IO::SEEK_SET) @pos = case method when IO::SEEK_CUR then (@pos + offset) when IO::SEEK_END then (@length - offset) when IO::SEEK_SET then offset end @data.seek(offset, method) if @data.kind_of?(NTFS::DataRun) @pos end |
#to_s ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fs/ntfs/attrib_data.rb', line 27 def to_s return @data.hex_dump if @data.kind_of?(String) raise "MIQ(NTFS::AttribData.to_s) Unexpected data class: #{@data.class}" unless @data.kind_of?(NTFS::DataRun) # Must be a Data Run savedPos = @pos seek(0) data = read(@length) seek(savedPos) data end |