See https://rsync.samba.org/tech_report/node4.html for the design of this algorithm
()
| 531 | |
| 532 | // See https://rsync.samba.org/tech_report/node4.html for the design of this algorithm |
| 533 | func (self *diff) read_next() (err error) { |
| 534 | if self.window.sz > 0 { |
| 535 | if ok, err := self.ensure_idx_valid(self.window.pos + self.window.sz); !ok { |
| 536 | if err != nil { |
| 537 | return err |
| 538 | } |
| 539 | return self.finish_up() |
| 540 | } |
| 541 | self.window.pos++ |
| 542 | self.data.sz++ |
| 543 | self.rc.add_one_byte(self.buffer[self.window.pos], self.buffer[self.window.pos+self.window.sz-1]) |
| 544 | } else { |
| 545 | if ok, err := self.ensure_idx_valid(self.window.pos + self.block_size - 1); !ok { |
| 546 | if err != nil { |
| 547 | return err |
| 548 | } |
| 549 | return self.finish_up() |
| 550 | } |
| 551 | self.window.sz = self.block_size |
| 552 | self.rc.full(self.buffer[self.window.pos : self.window.pos+self.window.sz]) |
| 553 | } |
| 554 | found_hash := false |
| 555 | var block_index uint64 |
| 556 | if hh, ok := self.hash_lookup[self.rc.val]; ok { |
| 557 | block_index, found_hash = find_hash(hh, self.hash(self.buffer[self.window.pos:self.window.pos+self.window.sz])) |
| 558 | } |
| 559 | if found_hash { |
| 560 | if err = self.send_data(); err != nil { |
| 561 | return |
| 562 | } |
| 563 | self.enqueue(Operation{Type: OpBlock, BlockIndex: block_index}) |
| 564 | self.window.pos += self.window.sz |
| 565 | self.data.pos = self.window.pos |
| 566 | self.window.sz = 0 |
| 567 | } |
| 568 | return nil |
| 569 | } |
| 570 | |
| 571 | type OperationWriter struct { |
| 572 | Operations []Operation |
no test coverage detected