Podmiana LZ4 na ZSTD raw block. Podmiana CompressManager na ChunkManager
This commit is contained in:
parent
00d4b00209
commit
b3c317c914
10 changed files with 244 additions and 267 deletions
69
ChunkManager.h
Normal file
69
ChunkManager.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <lz4.h>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#define ZSTD_STATIC_LINKING_ONLY
|
||||
#include <zstd.h>
|
||||
|
||||
#if ZSTD_VERSION_NUMBER < 10400
|
||||
#error "Wymagane zstd >= 1.4.0 dla ZSTD_c_format / ZSTD_f_zstd1_magicless"
|
||||
#endif
|
||||
|
||||
#include "EncryptionManager.h"
|
||||
|
||||
#define BLOCK_SIZE 131072 // 128KB
|
||||
|
||||
struct BlockSize
|
||||
{
|
||||
uint32_t raw;
|
||||
uint32_t zip;
|
||||
};
|
||||
|
||||
class ChunkManager
|
||||
{
|
||||
public:
|
||||
ChunkManager(EncryptionManager& em);
|
||||
~ChunkManager();
|
||||
|
||||
// Kompresja danych
|
||||
std::vector<char> chunked(const std::vector<char>&, const bool&);
|
||||
|
||||
// Dekompresja
|
||||
std::vector<char> dechunked(const std::vector<char>&, const bool&);
|
||||
|
||||
private:
|
||||
EncryptionManager eman;
|
||||
std::vector<BlockSize> blockSizes;
|
||||
|
||||
// Przekonwertuj zmienn¹ na ci¹g na vector
|
||||
template <typename T>
|
||||
void addIntToVector(std::vector<char>& vec, const T& val)
|
||||
{
|
||||
size_t tmpSize = vec.size();
|
||||
vec.resize(tmpSize + sizeof(val));
|
||||
std::memcpy(vec.data() + tmpSize, &val, sizeof(val));
|
||||
}
|
||||
|
||||
// Pobierz zmienn¹ z vectora
|
||||
template <typename T>
|
||||
T getIntFromVector(const std::vector<char>& vec, size_t& offset)
|
||||
{
|
||||
T tmp{};
|
||||
std::memcpy(&tmp, vec.data() + offset, sizeof(tmp));
|
||||
offset += sizeof(tmp);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Kompresja
|
||||
std::vector<char> compress_data(const std::vector<char>&);
|
||||
|
||||
// Dekompresja
|
||||
std::vector<char> decompress_data(const std::vector<char>&, const size_t&);
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue