Wypakowywanie strumieniowe
This commit is contained in:
parent
c2bdcfe2b9
commit
e69bfd0e3d
4 changed files with 57 additions and 15 deletions
|
|
@ -42,7 +42,7 @@ CreateCargo::~CreateCargo() {
|
|||
//-----------------------------------------------------------------------------
|
||||
bool CreateCargo::Create(const std::string& path, const uint8_t& flag)
|
||||
{
|
||||
cargoFile = path + "." + signature;
|
||||
cargoFile = path + "." + extension;
|
||||
catalogPath = path;
|
||||
methodFlags = flag;
|
||||
|
||||
|
|
|
|||
|
|
@ -64,13 +64,13 @@ namespace fl {
|
|||
namespace ds
|
||||
{
|
||||
// Chunki streamowania
|
||||
inline constexpr int chunk_stream = 268435456; // 256MB
|
||||
inline constexpr uint32_t chunk_stream = 268435456; // 256MB
|
||||
|
||||
// Blok chunków
|
||||
inline constexpr int block_size = 131072; // 128KB
|
||||
inline constexpr uint32_t block_size = 131072; // 128KB
|
||||
|
||||
// Maksymalny rozmiar pliku do spakowania
|
||||
inline constexpr int maxFileSize = 8589934592; // 8GB
|
||||
inline constexpr uint64_t maxFileSize = 8589934592; // 8GB
|
||||
}
|
||||
|
||||
// Flagi
|
||||
|
|
|
|||
|
|
@ -195,19 +195,59 @@ void ExtractCargo::ExtractingFilesFromCargo()
|
|||
|
||||
std::cout << fh.size << std::endl;
|
||||
cargoFile.seekg(fh.offset);
|
||||
std::vector<char> buffor(fh.size);
|
||||
|
||||
cargoFile.read(buffor.data(), fh.size);
|
||||
|
||||
std::vector<char> rawBuffor;
|
||||
computingBytes(buffor, rawBuffor, fh.flag);
|
||||
|
||||
if (!HashValid(rawBuffor, fh.crc))
|
||||
// Strumieñ wyci¹gaj¹cy
|
||||
for (uint64_t sc = 0; sc < fh.size; sc += ds::chunk_stream)
|
||||
{
|
||||
std::cerr << fh.nameFile << " Error: Corrupted data integration CRC" << std::endl;
|
||||
if (fh.flag == flag::raw)
|
||||
{
|
||||
const uint32_t streamChunk = std::min(ds::chunk_stream, static_cast<uint32_t>(fh.size - sc));
|
||||
|
||||
std::vector<char> buffer(streamChunk);
|
||||
cargoFile.read(buffer.data(), streamChunk);
|
||||
file.write(reinterpret_cast<const char*>(buffer.data()), streamChunk);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t chunkLen;
|
||||
uint32_t chunkBeforeSize;
|
||||
uint32_t chunkLastSize;
|
||||
|
||||
cargoFile.read(reinterpret_cast<char*>(&chunkLen), sizeof(chunkLen));
|
||||
cargoFile.read(reinterpret_cast<char*>(&chunkBeforeSize), sizeof(chunkBeforeSize));
|
||||
cargoFile.read(reinterpret_cast<char*>(&chunkLastSize), sizeof(chunkLastSize));
|
||||
|
||||
std::vector<char> chunksString;
|
||||
|
||||
// Dekompresja bloków
|
||||
for (size_t i = 0; i < chunkLen; ++i)
|
||||
{
|
||||
// Pobierz rozmiar chunków przed i po skompresowaniem
|
||||
uint32_t chunkSize = i < chunkLen - 1 ? chunkBeforeSize : chunkLastSize;
|
||||
uint32_t chunkZipSize;
|
||||
|
||||
cargoFile.read(reinterpret_cast<char*>(&chunkZipSize), sizeof(chunkZipSize));
|
||||
|
||||
// Pobierz blok chunka
|
||||
std::vector<char> buffer(chunkZipSize);
|
||||
cargoFile.read(buffer.data(), chunkZipSize);
|
||||
|
||||
std::vector<char> rawBuffer(chunkSize);
|
||||
if ((fh.flag & flag::zip) == flag::zip)
|
||||
{
|
||||
rawBuffer = (fh.flag & flag::enc) == flag::enc ?
|
||||
eman.decrypt(cman.decompress(buffer, chunkSize)) :
|
||||
cman.decompress(buffer, chunkSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
rawBuffer = eman.decrypt(buffer);
|
||||
}
|
||||
|
||||
file.write(reinterpret_cast<const char*>(rawBuffor.data()), rawBuffor.size());
|
||||
file.write(reinterpret_cast<const char*>(rawBuffer.data()), chunkSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,13 @@
|
|||
#include <sstream>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <xxhash.h>
|
||||
|
||||
#include "DataStruct.h"
|
||||
#include "ChunkManager.h"
|
||||
#include "EncryptionManager.h"
|
||||
#include "CompressionManager.h"
|
||||
|
||||
class ExtractCargo {
|
||||
public:
|
||||
|
|
@ -57,7 +59,7 @@ private:
|
|||
std::ifstream cargoFile;
|
||||
|
||||
EncryptionManager eman;
|
||||
|
||||
CompressionManager cman;
|
||||
|
||||
// Sprawdzenie poprawnoœci archiwum
|
||||
bool CheckCargoFile();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue