Zipper: now computeing crc32 on the fly during zip creation
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/crc.hpp> // for boost::crc_32_type
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
|
||||
class Crc32Calculator
|
||||
{
|
||||
public:
|
||||
|
||||
void processBytes(const std::byte* _data, std::size_t dataSize)
|
||||
{
|
||||
_result.process_bytes(_data, dataSize);
|
||||
}
|
||||
|
||||
std::uint32_t getResult() const
|
||||
{
|
||||
return _result.checksum();
|
||||
}
|
||||
|
||||
private:
|
||||
using Crc32Type = boost::crc_32_type;
|
||||
Crc32Type _result;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <filesystem>
|
||||
|
||||
#include "Exception.hpp"
|
||||
#include "utils/Crc32Calculator.hpp"
|
||||
|
||||
namespace Zip
|
||||
{
|
||||
@@ -33,17 +34,12 @@ namespace Zip
|
||||
using LmsException::LmsException;
|
||||
};
|
||||
|
||||
// Very simple on-the-fly zip creator
|
||||
// Very simple on-the-fly zip creator, "store" method only
|
||||
class Zipper
|
||||
{
|
||||
public:
|
||||
|
||||
enum class CompressionMethod
|
||||
{
|
||||
NoCompression,
|
||||
};
|
||||
|
||||
Zipper(const std::map<std::string, std::filesystem::path>& files, CompressionMethod comp = CompressionMethod::NoCompression);
|
||||
Zipper(const std::map<std::string, std::filesystem::path>& files);
|
||||
|
||||
static constexpr std::size_t minOutputBufferSize = 64;
|
||||
std::size_t writeSome(std::byte* buffer, std::size_t bufferSize);
|
||||
@@ -55,6 +51,7 @@ namespace Zip
|
||||
std::size_t writeLocalFileHeader(std::byte* buffer, std::size_t bufferSize);
|
||||
std::size_t writeLocalFileHeaderFileName(std::byte* buffer, std::size_t bufferSize);
|
||||
std::size_t writeFileData(std::byte* buffer, std::size_t bufferSize);
|
||||
std::size_t writeDataDescriptor(std::byte* buffer, std::size_t bufferSize);
|
||||
std::size_t writeCentralDirectoryHeader(std::byte* buffer, std::size_t bufferSize);
|
||||
std::size_t writeCentralDirectoryHeaderFileName(std::byte* buffer, std::size_t bufferSize);
|
||||
std::size_t writeEndOfCentralDirectoryRecord(std::byte* buffer, std::size_t bufferSize);
|
||||
@@ -63,7 +60,7 @@ namespace Zip
|
||||
{
|
||||
std::filesystem::path filePath;
|
||||
std::size_t fileSize;
|
||||
std::uint32_t fileCrc32;
|
||||
Utils::Crc32Calculator fileCrc32;
|
||||
std::size_t localFileHeaderOffset {};
|
||||
};
|
||||
|
||||
@@ -75,13 +72,13 @@ namespace Zip
|
||||
LocalFileHeader,
|
||||
LocalFileHeaderFileName,
|
||||
FileData,
|
||||
DataDescriptor,
|
||||
CentralDirectoryHeader,
|
||||
CentralDirectoryHeaderFileName,
|
||||
EndOfCentralDirectoryRecord,
|
||||
Complete,
|
||||
};
|
||||
|
||||
CompressionMethod _compMethod {CompressionMethod::NoCompression};
|
||||
WriteState _writeState {WriteState::LocalFileHeader};
|
||||
FileContainer::iterator _currentFile;
|
||||
std::size_t _currentOffset {};
|
||||
|
||||
Reference in New Issue
Block a user