Module: Hexdump

Included in:
IO, String, StringIO
Defined in:
lib/hexdump/hexdump.rb,
lib/hexdump/dumper.rb,
lib/hexdump/version.rb

Overview

Provides the Hexdump.dump method and can add hexdumping to other classes by including the Hexdump module.

class AbstractData

  include Hexdump

  def each_byte
    # ...
  end

end

data = AbstractData.new
data.hexdump

Defined Under Namespace

Classes: Dumper

Constant Summary collapse

VERSION =

hexdump version

'0.2.3'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dump(data, options = {}) {|index, numeric, printable| ... } ⇒ nil

Hexdumps the given data.

Parameters:

  • data (#each_byte)

    The data to be hexdumped.

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :width (Integer) — default: 16

    The number of bytes to dump for each line.

  • :endian (Integer) — default: :little

    The endianness that the bytes are organized in. Supported endianness include :little and :big.

  • :word_size (Integer) — default: 1

    The number of bytes within a word.

  • :base (Symbol, Integer) — default: :hexadecimal

    The base to print bytes in. Supported bases include, :hexadecimal, :hex, 16,:decimal,:dec,10, :octal, :oct, 8, :binary, :bin and 2.

  • :ascii (Boolean) — default: false

    Print ascii characters when possible.

  • :output (#<<) — default: STDOUT

    The output to print the hexdump to.

Yields:

  • (index, numeric, printable)

    The given block will be passed the hexdump break-down of each segment.

Yield Parameters:

  • index (Integer)

    The index of the hexdumped segment.

  • numeric (Array<String>)

    The numeric representation of the segment.

  • printable (Array<String>)

    The printable representation of the segment.

Returns:

  • (nil)

Raises:

  • (ArgumentError)

    The given data does not define the #each_byte method, the :output value does not support the #<< method or the :base value was unknown.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hexdump/hexdump.rb', line 71

def Hexdump.dump(data,options={},&block)
  output = (options.delete(:output) || STDOUT)
  dumper = Dumper.new(options)

  if block
    dumper.each(data,&block)
  else
    dumper.dump(data,output)
  end

  return nil
end

Instance Method Details

#hexdump(options = {}, &block) ⇒ Object

Hexdumps the object.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

See Also:



92
93
94
# File 'lib/hexdump/hexdump.rb', line 92

def hexdump(options={},&block)
  Hexdump.dump(self,options,&block)
end