Skip to content

Commit

Permalink
unmaintained unusable
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Jul 29, 2024
1 parent 3928700 commit 01248d6
Showing 1 changed file with 46 additions and 48 deletions.
94 changes: 46 additions & 48 deletions extern/miniz/include/miniz/zip_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#pragma once

#include <ghc/filesystem.hpp>

#include <algorithm>
#include <cstdint>
#include <fstream>
Expand Down Expand Up @@ -9681,14 +9683,22 @@ namespace miniz_cpp

void extract(const std::string &member, const std::string &path)
{
std::fstream stream(detail::join_path({ path, member }), std::ios::binary | std::ios::out);
stream << open(member).rdbuf();
auto file = detail::join_path({ path, member });
auto target = ghc::filesystem::path(file).parent_path();
if (!ghc::filesystem::exists(target))
ghc::filesystem::create_directories(target);
std::fstream stream(file, std::ios::binary | std::ios::out);
stream << open(member).rdbuf();
}

void extract(const zip_info &member, const std::string &path)
{
std::fstream stream(detail::join_path({ path, member.filename }), std::ios::binary | std::ios::out);
stream << open(member).rdbuf();
auto file = detail::join_path({ path, member.filename });
auto target = ghc::filesystem::path(file).parent_path();
if (!ghc::filesystem::exists(target))
ghc::filesystem::create_directories(target);
std::fstream stream(file, std::ios::binary | std::ios::out);
stream << open(member).rdbuf();
}

void extractall(const std::string &path)
Expand Down Expand Up @@ -9821,49 +9831,37 @@ namespace miniz_cpp
write(filename, arcname);
}

void write(const std::string &filename, const std::string &arcname)
{
std::fstream file(filename, std::ios::binary | std::ios::in);
std::stringstream ss;
ss << file.rdbuf();
std::string bytes = ss.str();

writestr(arcname, bytes);
}

void writestr(const std::string &arcname, const std::string &bytes)
{
if (archive_->m_zip_mode != MZ_ZIP_MODE_WRITING)
{
start_write();
}

if (!mz_zip_writer_add_mem(archive_.get(), arcname.c_str(), bytes.data(), bytes.size(), MZ_BEST_COMPRESSION))
{
throw std::runtime_error("write error");
}
}

void writestr(const zip_info &info, const std::string &bytes)
{
if (info.filename.empty() || info.date_time.year < 1980)
{
throw std::runtime_error("must specify a filename and valid date (year >= 1980");
}

if (archive_->m_zip_mode != MZ_ZIP_MODE_WRITING)
{
start_write();
}

auto crc = detail::crc32buf(bytes.c_str(), bytes.size());

if (!mz_zip_writer_add_mem_ex(archive_.get(), info.filename.c_str(), bytes.data(), bytes.size(), info.comment.c_str(),
static_cast<mz_uint16>(info.comment.size()), MZ_BEST_COMPRESSION, 0, crc))
{
throw std::runtime_error("write error");
}
}
void write(const std::string& filepath_on_disk, const std::string& filepath_in_zip)
{
std::fstream file(filepath_on_disk, std::ios::binary | std::ios::in);
std::stringstream ss;
ss << file.rdbuf();
std::string bytes = ss.str();

if (archive_->m_zip_mode != MZ_ZIP_MODE_WRITING) {
start_write();
}

auto crc = detail::crc32buf(bytes.c_str(), bytes.size());
std::string comment = "";
MZ_TIME_T time;

if (!mz_zip_get_file_modified_time(filepath_on_disk.c_str(), &time))
throw std::runtime_error("stat error");

if (!mz_zip_writer_add_mem_ex_v2(
archive_.get(),
filepath_in_zip.c_str(),
bytes.data(),
bytes.size(),
comment.c_str(),
static_cast<mz_uint16>(comment.size()),
MZ_BEST_COMPRESSION,
0,
crc, &time, NULL, 0, NULL, 0)) {
throw std::runtime_error("write error");
}
}

std::string get_filename() const
{
Expand Down Expand Up @@ -10037,4 +10035,4 @@ namespace miniz_cpp
std::string filename_;
};

} // namespace miniz_cpp
} // namespace miniz_cpp

0 comments on commit 01248d6

Please sign in to comment.