simple_delta.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // Implementation of the byte-level differential compression used internally by
  5. // Courgette.
  6. #include "courgette/simple_delta.h"
  7. #include "base/logging.h"
  8. #include "courgette/third_party/bsdiff/bsdiff.h"
  9. namespace courgette {
  10. namespace {
  11. Status BSDiffStatusToStatus(bsdiff::BSDiffStatus status) {
  12. switch (status) {
  13. case bsdiff::OK: return C_OK;
  14. case bsdiff::CRC_ERROR: return C_BINARY_DIFF_CRC_ERROR;
  15. default: return C_GENERAL_ERROR;
  16. }
  17. }
  18. }
  19. Status ApplySimpleDelta(SourceStream* old, SourceStream* delta,
  20. SinkStream* target) {
  21. return BSDiffStatusToStatus(bsdiff::ApplyBinaryPatch(old, delta, target));
  22. }
  23. Status GenerateSimpleDelta(SourceStream* old, SourceStream* target,
  24. SinkStream* delta) {
  25. VLOG(1) << "GenerateSimpleDelta " << old->Remaining()
  26. << " " << target->Remaining();
  27. return BSDiffStatusToStatus(bsdiff::CreateBinaryPatch(old, target, delta));
  28. }
  29. } // namespace courgette