Class: Pack::Expander

Inherits:
Object
  • Object
show all
Defined in:
lib/pack/expander.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delta) ⇒ Expander

Returns a new instance of Expander.



15
16
17
18
19
20
# File 'lib/pack/expander.rb', line 15

def initialize(delta)
  @delta = StringIO.new(delta)

  @source_size = read_size
  @target_size = read_size
end

Instance Attribute Details

#source_sizeObject (readonly)

Returns the value of attribute source_size.



9
10
11
# File 'lib/pack/expander.rb', line 9

def source_size
  @source_size
end

#target_sizeObject (readonly)

Returns the value of attribute target_size.



9
10
11
# File 'lib/pack/expander.rb', line 9

def target_size
  @target_size
end

Class Method Details

.expand(source, delta) ⇒ Object



11
12
13
# File 'lib/pack/expander.rb', line 11

def self.expand(source, delta)
  Expander.new(delta).expand(source)
end

Instance Method Details

#expand(source) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pack/expander.rb', line 22

def expand(source)
  check_size(source, @source_size)
  target = ""

  until @delta.eof?
    byte = @delta.readbyte

    if byte < 0x80
      insert = Delta::Insert.parse(@delta, byte)
      target.concat(insert.data)
    else
      copy = Delta::Copy.parse(@delta, byte)
      size = (copy.size == 0) ? GIT_MAX_COPY : copy.size
      target.concat(source.byteslice(copy.offset, size))
    end
  end

  check_size(target, @target_size)
  target
end