Class: BinData::BitAligned::BitAlignedIO
- Inherits:
-
Object
- Object
- BinData::BitAligned::BitAlignedIO
- Defined in:
- lib/bindata/alignment.rb
Instance Method Summary collapse
- #binary_string(str) ⇒ Object
-
#initialize(io) ⇒ BitAlignedIO
constructor
A new instance of BitAlignedIO.
- #readbytes(n) ⇒ Object
- #writebytes(str) ⇒ Object
Constructor Details
#initialize(io) ⇒ BitAlignedIO
Returns a new instance of BitAlignedIO.
45 46 47 |
# File 'lib/bindata/alignment.rb', line 45 def initialize(io) @io = io end |
Instance Method Details
#binary_string(str) ⇒ Object
49 50 51 |
# File 'lib/bindata/alignment.rb', line 49 def binary_string(str) str.to_s.dup.force_encoding(Encoding::BINARY) end |
#readbytes(n) ⇒ Object
53 54 55 56 57 |
# File 'lib/bindata/alignment.rb', line 53 def readbytes(n) n.times.inject(binary_string("")) do |bytes, _| bytes + @io.readbits(8, :big).chr end end |
#writebytes(str) ⇒ Object
58 59 60 |
# File 'lib/bindata/alignment.rb', line 58 def writebytes(str) str.each_byte { |v| @io.writebits(v, 8, :big) } end |