zhexdump 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b2e6bfef9bdafb2b9c55ca2682113a71e008e5e9fc5d2492e0a03f7fbb74abb
4
- data.tar.gz: 6c8ffe4c3d33f5c1fbe2c79dd02263f5b57582abb7c12950d54def6e8e942ff3
3
+ metadata.gz: 87be9581b8556e6969275cb73e07ff353805db106f1f741bb522a941db276919
4
+ data.tar.gz: 0f75b82fe5bb212b0f4ad29d9aea29f89b62f21de3fabc7496c5eb75a387b1dc
5
5
  SHA512:
6
- metadata.gz: f6fe0c14cdf444797c7393def5d1949ad319fc93f86075efecc7f083e012d87e210f78530340cb4401919905445c2f7f79581b1fe45f7348c79a367629ae1090
7
- data.tar.gz: 4c86d845b5820ac1ab2b51293e290cb3b8877005b80316355ae0e40b234d245f05560c80f3617791a14c47bdcd18e0b16a0c7314e5b811ba7104cb01a9730314
6
+ metadata.gz: 1fc327641290592b335173fc7385ef73344f0f5f45bad467f25e7edc5a20a130a0f5a4daf54888932c8084fe500823446ed69676c286fa1d48fc199310a92c5c
7
+ data.tar.gz: 0231db65834152f9a9afce551a689a4a786c6a77863acf981929054db6254e8e96f74df59e4aa5e3a8c8c18f5c289107f819abb0b84405e10cf096140fb9eba3
@@ -1,3 +1,3 @@
1
1
  module ZHexdump
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/zhexdump.rb CHANGED
@@ -19,7 +19,15 @@ module ZHexdump
19
19
  r
20
20
  end
21
21
 
22
+ @defaults = {}
23
+
22
24
  class << self
25
+ attr_accessor :defaults
26
+
27
+ def _get_param(h, key, default)
28
+ h[key] || defaults[key] || default
29
+ end
30
+
23
31
  def dump data, h = {}
24
32
  offset = h.fetch(:offset, 0)
25
33
  dedup = h.fetch(:dedup, true)
@@ -30,13 +38,13 @@ module ZHexdump
30
38
  offset = 0
31
39
  end
32
40
 
33
- add = h[:add] || 0
34
- size = h[:size] || (data.size-offset)
35
- tail = h[:tail] || "\n"
36
- width = h[:width] || 0x10 # row width, in bytes
37
- output = h[:output] || $>
38
- indent = h[:indent] || 0
39
- offset_format = h[:offset_format] || "%08x: "
41
+ add = _get_param(h, :add, 0)
42
+ size = _get_param(h, :size, data.size-offset)
43
+ tail = _get_param(h, :tail, "\n")
44
+ width = _get_param(h, :width, 16)
45
+ output = _get_param(h, :output, $stdout)
46
+ indent = _get_param(h, :indent, 0)
47
+ offset_format = _get_param(h, :offset_format, "%08x: ")
40
48
 
41
49
  indent = ' ' * indent
42
50
  size = data.size-offset if size+offset > data.size
@@ -47,8 +55,9 @@ module ZHexdump
47
55
  width.times do |i|
48
56
  hex << ' ' if i%8==0 && i>0
49
57
  if c = ((size > 0) && data[offset+i])
50
- hex << "%02x " % c.ord
51
- ascii << ((32..126).include?(c.ord) ? c : '.')
58
+ ord = c.ord
59
+ hex << "%02x " % ord
60
+ ascii << (ord == 0 ? ' ' : ((32..126).include?(ord) ? c : '.'))
52
61
  else
53
62
  hex << ' '
54
63
  ascii << ' '
@@ -57,7 +66,7 @@ module ZHexdump
57
66
  end
58
67
 
59
68
  if dedup && hex == prevhex
60
- row = "*"
69
+ row = indent + "*"
61
70
  yield(row, offset+add, ascii) if block_given?
62
71
  unless prevdup
63
72
  output << "\n" if offset > start
data/spec/hexdump_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #coding: binary
1
2
  require 'spec_helper'
2
3
  require 'stringio'
3
4
 
@@ -53,6 +54,17 @@ describe ZHexdump do
53
54
  s.should == "00000002: 6f 62 61 |oba |\n"
54
55
  end
55
56
 
57
+ it "respects :indent" do
58
+ data = 'foobar' + "\x00"*100
59
+ s = ''
60
+ ZHexdump.dump data, :output => s, :indent => 2
61
+ a = s.split("\n")
62
+ a[0].should == " 00000000: 66 6f 6f 62 61 72 00 00 00 00 00 00 00 00 00 00 |foobar |"
63
+ a[1].should == " 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |"
64
+ a[2].should == " *"
65
+ a[3].should == " 00000060: 00 00 00 00 00 00 00 00 00 00 | |"
66
+ end
67
+
56
68
  it "adds :add to offset shown" do
57
69
  data = 'foo'*100
58
70
  s = ''
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,6 @@ require File.join(File.dirname(__FILE__), '../lib/zhexdump.rb')
2
2
 
3
3
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
4
4
  RSpec.configure do |config|
5
- config.treat_symbols_as_metadata_keys_with_true_values = true
6
5
  config.run_all_when_everything_filtered = true
7
6
  #config.filter_run :focus
8
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhexdump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-14 00:00:00.000000000 Z
11
+ date: 2024-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.5.6
64
+ rubygems_version: 3.5.16
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: A highly flexible hexdump implementation.