Class used to forge a String from a stream of bits. Internally used by some filters.
Finalizes the stream.
# File lib/origami/filters.rb, line 109 def final @data << @last_byte.chr if @last_byte @last_byte = nil @p = 0 self end
Returns the data size in bits.
# File lib/origami/filters.rb, line 102 def size (@data.size << 3) + @ptr_bit end
Outputs the stream as a String.
# File lib/origami/filters.rb, line 120 def to_s @data.dup end
Writes data represented as Fixnum to a length number of bits.
# File lib/origami/filters.rb, line 62 def write(data, length) return BitWriterError, "Invalid data length" unless length > 0 and (1 << length) > data # optimization for aligned byte writing if length == 8 and @last_byte.nil? and @ptr_bit == 0 @data << data.chr return self end while length > 0 if length >= 8 - @ptr_bit length -= 8 - @ptr_bit @last_byte ||= 0 @last_byte |= (data >> length) & ((1 << (8 - @ptr_bit)) - 1) data &= (1 << length) - 1 @data << @last_byte.chr @last_byte = nil @ptr_bit = 0 else @last_byte ||= 0 @last_byte |= (data & ((1 << length) - 1)) << (8 - @ptr_bit - length) @ptr_bit += length if @ptr_bit == 8 @data << @last_byte.chr @last_byte = nil @ptr_bit = 0 end length = 0 end end self end
Generated with the Darkfish Rdoc Generator 2.