ApplyFragment applies the changes in the fragment f and writes the result to dst. ApplyFragment can be called at most once. If an error occurs while applying, ApplyFragment returns an *ApplyError that annotates the error with additional information. If the error is because of a conflict between a f
(f *BinaryFragment)
| 34 | // a conflict between a fragment and the source, the wrapped error will be a |
| 35 | // *Conflict. |
| 36 | func (a *BinaryApplier) ApplyFragment(f *BinaryFragment) error { |
| 37 | if f == nil { |
| 38 | return applyError(errors.New("nil fragment")) |
| 39 | } |
| 40 | if a.closed { |
| 41 | return applyError(errApplierClosed) |
| 42 | } |
| 43 | if a.dirty { |
| 44 | return applyError(errApplyInProgress) |
| 45 | } |
| 46 | |
| 47 | // mark an apply as in progress, even if it fails before making changes |
| 48 | a.dirty = true |
| 49 | |
| 50 | switch f.Method { |
| 51 | case BinaryPatchLiteral: |
| 52 | if _, err := a.dst.Write(f.Data); err != nil { |
| 53 | return applyError(err) |
| 54 | } |
| 55 | case BinaryPatchDelta: |
| 56 | if err := applyBinaryDeltaFragment(a.dst, a.src, f.Data); err != nil { |
| 57 | return applyError(err) |
| 58 | } |
| 59 | default: |
| 60 | return applyError(fmt.Errorf("unsupported binary patch method: %v", f.Method)) |
| 61 | } |
| 62 | return nil |
| 63 | } |
| 64 | |
| 65 | // Close writes any data following the last applied fragment and prevents |
| 66 | // future calls to ApplyFragment. |