Class: CheapByteCount
- Inherits:
-
Object
- Object
- CheapByteCount
- Defined in:
- lib/cheap_byte_count.rb
Instance Attribute Summary collapse
-
#byte_count_array ⇒ Object
readonly
Returns the value of attribute byte_count_array.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fd_in) ⇒ CheapByteCount
constructor
A new instance of CheapByteCount.
Constructor Details
#initialize(fd_in) ⇒ CheapByteCount
Returns a new instance of CheapByteCount.
19 20 21 22 23 24 25 26 27 |
# File 'lib/cheap_byte_count.rb', line 19 def initialize(fd_in) @byte_count_array = [] 256.times {@byte_count_array << 0} while s = self.class.readblock(fd_in) do s.each_byte do |b| @byte_count_array[b] += 1 end end end |
Instance Attribute Details
#byte_count_array ⇒ Object (readonly)
Returns the value of attribute byte_count_array.
17 18 19 |
# File 'lib/cheap_byte_count.rb', line 17 def byte_count_array @byte_count_array end |
Class Method Details
.byte_count_array_from_file(file_name) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/cheap_byte_count.rb', line 9 def self.byte_count_array_from_file(file_name) bca = nil File.open(file_name, 'rb') do |fd_in| bca = new(fd_in).byte_count_array end bca end |
.readblock(fd_in) ⇒ Object
3 4 5 6 7 |
# File 'lib/cheap_byte_count.rb', line 3 def self.readblock(fd_in) fd_in.readpartial 4096 rescue EOFError nil end |