blob: 299b0241b92b1e370e2eb126beae88aaa25588c6 [file] [log] [blame]
Tianjie Xu1c26e2e2017-10-26 17:19:41 -07001// 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
9namespace bsdiff {
10
11const 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
25void CompressorBuffer::AddDataToChunks(size_t data_size) {
26 if (data_size > comp_buffer_.size()) {
27 LOG(ERROR) << "data size: " << data_size
Tianjie Xu18480eb2017-11-29 16:21:43 -080028 << " is larger than buffer size: " << comp_buffer_.size();
Tianjie Xu1c26e2e2017-10-26 17:19:41 -070029 return;
30 }
31 comp_chunks_.emplace_back(comp_buffer_.data(),
32 comp_buffer_.data() + data_size);
33}
34
35} // namespace bsdiff