Not working yet.

This commit is contained in:
Your Name
2025-05-03 10:24:02 +12:00
parent 24a4c66c13
commit a658ba1de6
5 changed files with 3 additions and 46 deletions

View File

@@ -14,42 +14,6 @@
namespace simple_object_storage {
std::string decompress_gzip(const std::string& file_path) {
std::ifstream file(file_path, std::ios::binary);
if (!file) return {};
std::vector<char> compressed((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
if (compressed.size() < 2) return {};
// Skip gzip header (10 bytes)
size_t pos = 10;
if (compressed.size() <= pos) return {};
// Prepare zlib stream
z_stream strm = {};
strm.next_in = reinterpret_cast<Bytef*>(compressed.data() + pos);
strm.avail_in = compressed.size() - pos;
if (inflateInit2(&strm, 16 + MAX_WBITS) != Z_OK) return {};
std::string out;
char buffer[4096];
int ret;
do {
strm.next_out = reinterpret_cast<Bytef*>(buffer);
strm.avail_out = sizeof(buffer);
ret = inflate(&strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) {
inflateEnd(&strm);
return {};
}
out.append(buffer, sizeof(buffer) - strm.avail_out);
} while (ret != Z_STREAM_END);
inflateEnd(&strm);
return out;
}
// if the file is a tgz file (we can't rely on the extension), then unpack on disk and has the contents
// with hash_directory_recursive in hash.hpp
uint64_t get_hash_from_tgz(const std::string &file_path)
@@ -66,10 +30,8 @@ uint64_t get_hash_from_tgz(const std::string &file_path)
TempDirectory temp_dir_manager("tgz_unpack_"); // Creates dir and schedules cleanup
std::string temp_dir = temp_dir_manager.string(); // Get the path string to use
std::string decompressed = decompress_gzip(file_path);
// unpack the file on disk
std::string command = "tar -xzf " + file_path + " -C " + temp_dir;
std::string command = "tar -zxzf " + file_path + " -C " + temp_dir;
int result = system(command.c_str()); // Basic tar extraction - requires 'tar' command
if (result != 0) {
std::cerr << "Error unpacking tgz file: " << file_path << std::endl;