Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / courgette / simple_delta.cc
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Implementation of the byte-level differential compression used internally by
6 // Courgette.
7
8 #include "courgette/simple_delta.h"
9
10 #include "base/logging.h"
11
12 #include "courgette/third_party/bsdiff/bsdiff.h"
13
14 namespace courgette {
15
16 namespace {
17
18 Status BSDiffStatusToStatus(bsdiff::BSDiffStatus status) {
19   switch (status) {
20     case bsdiff::OK: return C_OK;
21     case bsdiff::CRC_ERROR: return C_BINARY_DIFF_CRC_ERROR;
22     default: return C_GENERAL_ERROR;
23   }
24 }
25
26 }
27
28 Status ApplySimpleDelta(SourceStream* old, SourceStream* delta,
29                         SinkStream* target) {
30   return BSDiffStatusToStatus(bsdiff::ApplyBinaryPatch(old, delta, target));
31 }
32
33 Status GenerateSimpleDelta(SourceStream* old, SourceStream* target,
34                            SinkStream* delta) {
35   VLOG(1) << "GenerateSimpleDelta " << old->Remaining()
36           << " " << target->Remaining();
37   return BSDiffStatusToStatus(bsdiff::CreateBinaryPatch(old, target, delta));
38 }
39
40 }  // namespace courgette