Class: JXL::Bit::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/jxl/bit/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWriter

Returns a new instance of Writer.



8
9
10
11
12
13
# File 'lib/jxl/bit/writer.rb', line 8

def initialize
  @bytes = +"".b
  @buffer = 0
  @count = 0
  @bits_written = 0
end

Instance Attribute Details

#bits_writtenObject (readonly)

Returns the value of attribute bits_written.



6
7
8
# File 'lib/jxl/bit/writer.rb', line 6

def bits_written
  @bits_written
end

Instance Method Details

#alignObject



26
27
28
# File 'lib/jxl/bit/writer.rb', line 26

def align
  write((-@count) & 7, 0)
end

#bytesObject



30
31
32
33
# File 'lib/jxl/bit/writer.rb', line 30

def bytes
  align
  @bytes.dup
end

#write(count, value) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
# File 'lib/jxl/bit/writer.rb', line 15

def write(count, value)
  raise ArgumentError, "invalid bit count" unless count.between?(0, 64)
  raise ArgumentError, "value does not fit" if value.negative? || value.bit_length > count

  @buffer |= value << @count
  @count += count
  @bits_written += count
  flush_bytes
  self
end