Class: Pack::XDelta
- Inherits:
-
Object
- Object
- Pack::XDelta
- Defined in:
- lib/pack/xdelta.rb
Constant Summary collapse
- BLOCK_SIZE =
16
Class Method Summary collapse
Instance Method Summary collapse
- #compress(target) ⇒ Object
-
#initialize(source, index) ⇒ XDelta
constructor
A new instance of XDelta.
Constructor Details
#initialize(source, index) ⇒ XDelta
Returns a new instance of XDelta.
21 22 23 24 |
# File 'lib/pack/xdelta.rb', line 21 def initialize(source, index) @source = source @index = index end |
Class Method Details
.create_index(source) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pack/xdelta.rb', line 6 def self.create_index(source) blocks = source.bytesize / BLOCK_SIZE index = {} (0 ... blocks).each do |i| offset = i * BLOCK_SIZE slice = source.byteslice(offset, BLOCK_SIZE) index[slice] ||= [] index[slice].push(offset) end XDelta.new(source, index) end |
Instance Method Details
#compress(target) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pack/xdelta.rb', line 26 def compress(target) @target = target @offset = 0 @insert = [] @ops = [] generate_ops while @offset < @target.bytesize flush_insert @ops end |