1 // Copyright 2017 The Chromium OS 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 #include "bsdiff/compressor_buffer.h"
6 
7 #include "bsdiff/logging.h"
8 
9 namespace bsdiff {
10 
11 const std::vector<uint8_t>& CompressorBuffer::GetCompressedData() {
12   if (!comp_chunks_.empty()) {
13     size_t chunks_size = 0;
14     for (const auto& chunk : comp_chunks_)
15       chunks_size += chunk.size();
16     comp_data_.reserve(comp_data_.size() + chunks_size);
17     for (const auto& chunk : comp_chunks_) {
18       comp_data_.insert(comp_data_.end(), chunk.begin(), chunk.end());
19     }
20     comp_chunks_.clear();
21   }
22   return comp_data_;
23 }
24 
25 void CompressorBuffer::AddDataToChunks(size_t data_size) {
26   if (data_size > comp_buffer_.size()) {
27     LOG(ERROR) << "data size: " << data_size
28                << " is larger than buffer size: " << comp_buffer_.size();
29     return;
30   }
31   comp_chunks_.emplace_back(comp_buffer_.data(),
32                             comp_buffer_.data() + data_size);
33 }
34 
35 }  // namespace bsdiff
36