Alexander Afanasyev | 6ee98ff | 2018-02-13 19:12:28 -0500 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 3 | * Copyright (c) 2012-2021 University of California, Los Angeles |
Alexander Afanasyev | 6ee98ff | 2018-02-13 19:12:28 -0500 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
| 7 | * |
| 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame^] | 20 | #include "bzip2-helper.hpp" |
Alexander Afanasyev | 6ee98ff | 2018-02-13 19:12:28 -0500 | [diff] [blame] | 21 | |
Alexander Afanasyev | 6ee98ff | 2018-02-13 19:12:28 -0500 | [diff] [blame] | 22 | #include <boost/iostreams/copy.hpp> |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame^] | 23 | #include <boost/iostreams/device/array.hpp> |
| 24 | #include <boost/iostreams/filtering_stream.hpp> |
| 25 | #include <boost/iostreams/filter/bzip2.hpp> |
| 26 | #include <boost/iostreams/stream.hpp> |
Alexander Afanasyev | 6ee98ff | 2018-02-13 19:12:28 -0500 | [diff] [blame] | 27 | |
| 28 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
| 29 | |
| 30 | namespace chronosync { |
| 31 | namespace bzip2 { |
| 32 | |
| 33 | namespace bio = boost::iostreams; |
| 34 | |
| 35 | std::shared_ptr<ndn::Buffer> |
| 36 | compress(const char* buffer, size_t bufferSize) |
| 37 | { |
| 38 | ndn::OBufferStream os; |
| 39 | bio::filtering_stream<bio::output> out; |
| 40 | out.push(bio::bzip2_compressor()); |
| 41 | out.push(os); |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame^] | 42 | bio::stream<bio::array_source> in(buffer, bufferSize); |
Alexander Afanasyev | 6ee98ff | 2018-02-13 19:12:28 -0500 | [diff] [blame] | 43 | bio::copy(in, out); |
| 44 | return os.buf(); |
| 45 | } |
| 46 | |
| 47 | std::shared_ptr<ndn::Buffer> |
| 48 | decompress(const char* buffer, size_t bufferSize) |
| 49 | { |
| 50 | ndn::OBufferStream os; |
| 51 | bio::filtering_stream<bio::output> out; |
| 52 | out.push(bio::bzip2_decompressor()); |
| 53 | out.push(os); |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame^] | 54 | bio::stream<bio::array_source> in(buffer, bufferSize); |
Alexander Afanasyev | 6ee98ff | 2018-02-13 19:12:28 -0500 | [diff] [blame] | 55 | bio::copy(in, out); |
| 56 | return os.buf(); |
| 57 | } |
| 58 | |
| 59 | } // namespace bzip2 |
| 60 | } // namespace chronosync |