Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/hexdump/core_ext/file.rb

Class Method Summary collapse

Class Method Details

.hexdump(path, **kwargs) {|hexdump| ... } ⇒ Object

Hexdumps the contents of a file.

Examples:

File.hexdump("/bin/ls")
# 00000000  7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00  |.ELF............|
# ...

Parameters:

Options Hash (**kwargs):

  • :output (#print) — default: $stdout

    The output to print the hexdump to.

  • :type (:int8, :uint8, :char, :uchar, :byte, :int16, :int16_le, :int16_be, :int16_ne, :uint16, :uint16_le, :uint16_be, :uint16_ne, :short, :short_le, :short_be, :short_ne, :ushort, :ushort_le, :ushort_be, :ushort_ne, :int32, :int32_le, :int32_be, :int32_ne, :uint32, :uint32_le, :uint32_be, :uint32_ne, :int, :long, :long_le, :long_be, :long_ne, :uint, :ulong, :ulong_le, :ulong_be, :ulong_ne, :int64, :int64_le, :int64_be, :int64_ne, :uint64, :uint64_le, :uint64_be, :uint64_ne, :long_long, :long_long_le, :long_long_be, :long_long_ne, :ulong_long, :ulong_long_le, :ulong_long_be, :ulong_long_ne, :float, :float_le, :float_be, :float_ne, :double, :double_le, :double_be, :double_ne) — default: :byte

    The type to decode the data as.

  • :offset (Integer, nil)

    Controls whether to skip N number of bytes before starting to read data.

  • :length (Integer, nil)

    Controls control many bytes to read.

  • :zero_pad (Boolean) — default: false

    Enables or disables zero padding of data, so that the remaining bytes can be decoded as a uint, int, or float.

  • :columns (Integer) — default: 16

    The number of bytes to dump for each line.

  • :group_columns (Integer, nil)

    Separate groups of columns with an additional space.

  • :group_chars (Integer, :type, nil)

    Group chars into columns. If :type, then the chars will be grouped by the type's size.

  • :repeating (Boolean)

    Controls whether to omit repeating duplicate rows data with a *.

  • :base (16, 10, 8, 2) — default: 16

    The base to print bytes in.

  • :index_base (16, 10, 8, 2) — default: 16

    Control the base that the index is displayed in.

  • :index_offset (Integer, nil)

    The offset to start the index at.

  • :chars_column (Boolean) — default: true

    Controls whether to display the characters column.

  • :encoding (:ascii, :utf8, Encoding, nil)

    The encoding to display the characters in.

  • :style (Boolean, Hash{:index,:numeric,:chars => Symbol,Array<Symbol>})

    Enables theming of index, numeric, or chars columns.

  • :highlights (Boolean, Hash{:index,:numeric,:chars => Hash{String,Regexp => Symbol,Array<Symbol>}})

    Enables selective highlighting of index, numeric, or chars columns.

Yields:

  • (hexdump)

    If a block is given, it will be passed the newly initialized hexdump instance.

Yield Parameters:

See Also:



78
79
80
81
82
# File 'lib/hexdump/core_ext/file.rb', line 78

def self.hexdump(path,**kwargs,&block)
  self.open(path,'rb') do |file|
    file.hexdump(**kwargs,&block)
  end
end