Pioneer
LZ4Format.h
Go to the documentation of this file.
1 // Copyright © 2019 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #pragma once
5 
6 #include "nonstd/string_view.hpp"
7 
8 #include <memory>
9 #include <stdexcept>
10 #include <string>
11 
12 namespace lz4 {
13  using nonstd::string_view;
14 
15  struct DecompressionFailedException : public std::runtime_error {
16  using std::runtime_error::runtime_error;
17  };
18  struct CompressionFailedException : public std::runtime_error {
19  using std::runtime_error::runtime_error;
20  };
21 
22  // Checks if the data block could plausibly be a lz4 file.
23  // This really just checks for the magic lz4 bytes and a basic length check.
24  bool IsLZ4Format(const char *data, size_t length);
25 
26  // Decompress lz4 format data.
27  // If the input fails format checks or checksum then it will throw an exception.
28  std::string DecompressLZ4(const string_view data);
29 
30  // Compresses a block of data according to the lz4 framing format.
31  // If compression fails it throws an exception.
32  // lz4_speed is the compression preset; 0 = default compression, 3-12 = HC compression
33  std::string CompressLZ4(const string_view data, const int lz4_preset);
34 } // namespace lz4
Definition: LZ4Format.h:12
std::string DecompressLZ4(const string_view data)
Definition: LZ4Format.cpp:26
bool IsLZ4Format(const char *data, size_t length)
Definition: LZ4Format.cpp:11
std::string CompressLZ4(const string_view data, const int lz4_preset)
Definition: LZ4Format.cpp:71
Definition: LZ4Format.h:18
Definition: LZ4Format.h:15