Module: Xxd
- Defined in:
- lib/xxd.rb,
lib/xxd/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.dump(input) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/xxd.rb', line 6 def dump(input) io = StringIO.new res = input.bytes.each_slice(2).each_slice(8).each_with_index do |row, i| io.write format( "%07x0: %-40s %-16s\n", i, row.map { |pair| pair.map { |b| b.to_s(16).rjust(2, "0") }.join }.join(" "), row.flat_map { |pair| pair.map { |b| (b >= 32 && b < 127 ? b.chr : ".") } }.flatten.join ) end io.string end |
.parse(input) ⇒ Object
20 21 22 23 24 |
# File 'lib/xxd.rb', line 20 def parse(input) res = input.lines.flat_map do |line| line[10..48].gsub(" ", "").scan(/../).map { |hb| hb.to_i(16) } end.pack("c*") end |