Skip to content

Commit

Permalink
Update argument names
Browse files Browse the repository at this point in the history
  • Loading branch information
dvsku committed Aug 31, 2024
1 parent c55fb16 commit 5edd3b5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
16 changes: 8 additions & 8 deletions include/libevp/evp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace libevp {
* status == evp_result_status::ok packed successfully;
* status == evp_result_status::failure an error occurred during packing, message contains details;
*/
LIBEVP_API evp_result pack(const pack_input& input, const FILE_PATH& evp);
LIBEVP_API evp_result pack(const pack_input& input, const FILE_PATH& output);

/*
* Unpacks .evp archive contents into a dir.
Expand All @@ -71,7 +71,7 @@ namespace libevp {
*
* @param context -> pointer to context that has callbacks
*/
LIBEVP_API void pack_async(const pack_input& input, const FILE_PATH& evp, evp_context* context = nullptr);
LIBEVP_API void pack_async(const pack_input& input, const FILE_PATH& output, evp_context* context = nullptr);

/*
* Asynchronously unpacks .evp archive contents into a dir.
Expand All @@ -93,7 +93,7 @@ namespace libevp {
* status == evp_result_status::ok all files successfully validated;
* status == evp_result_status::failure an error occurred, message contains details;
*/
LIBEVP_API evp_result validate_files(const FILE_PATH& evp, std::vector<evp_fd>* failed_fds = nullptr);
LIBEVP_API evp_result validate_files(const FILE_PATH& input, std::vector<evp_fd>* failed_files = nullptr);

/*
* Get file fds packed inside .evp archive.
Expand All @@ -105,7 +105,7 @@ namespace libevp {
* status == evp_result_status::ok got files successfully;
* status == evp_result_status::failure an error occurred, message contains details;
*/
LIBEVP_API evp_result get_archive_fds(const FILE_PATH& evp, std::vector<evp_fd>& files);
LIBEVP_API evp_result get_archive_fds(const FILE_PATH& input, std::vector<evp_fd>& files);

/*
* Unpack a single file from .evp archive into a buffer.
Expand All @@ -118,7 +118,7 @@ namespace libevp {
* status == evp_result_status::ok unpacked successfully;
* status == evp_result_status::failure an error occurred during unpacking, message contains details;
*/
LIBEVP_API evp_result get_file(const FILE_PATH& evp, const evp_fd& fd, std::vector<uint8_t>& buffer);
LIBEVP_API evp_result get_file(const FILE_PATH& input, const evp_fd& file, std::vector<uint8_t>& buffer);

/*
* Unpack a single file from .evp archive into a stringstream.
Expand All @@ -131,7 +131,7 @@ namespace libevp {
* status == evp_result_status::ok unpacked successfully;
* status == evp_result_status::failure an error occurred during unpacking, message contains details;
*/
LIBEVP_API evp_result get_file(const FILE_PATH& evp, const evp_fd& fd, std::stringstream& stream);
LIBEVP_API evp_result get_file(const FILE_PATH& input, const evp_fd& file, std::stringstream& stream);

/*
* Unpack a single file from .evp archive into a buffer.
Expand All @@ -144,7 +144,7 @@ namespace libevp {
* status == evp_result_status::ok unpacked successfully;
* status == evp_result_status::failure an error occurred during unpacking, message contains details;
*/
LIBEVP_API evp_result get_file(const FILE_PATH& evp, const FILE_PATH& file, std::vector<uint8_t>& buffer);
LIBEVP_API evp_result get_file(const FILE_PATH& input, const FILE_PATH& file, std::vector<uint8_t>& buffer);

/*
* Unpack a single file from .evp archive into a stringstream.
Expand All @@ -157,6 +157,6 @@ namespace libevp {
* status == evp_result_status::ok unpacked successfully;
* status == evp_result_status::failure an error occurred during unpacking, message contains details;
*/
LIBEVP_API evp_result get_file(const FILE_PATH& evp, const FILE_PATH& file, std::stringstream& stream);
LIBEVP_API evp_result get_file(const FILE_PATH& input, const FILE_PATH& file, std::stringstream& stream);
};
}
64 changes: 32 additions & 32 deletions source/libevp/evp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void MD5_hex_string_to_bytes(MD5& md5, uint8_t* bytes);
namespace libevp {
class evp_impl {
public:
static evp_result pack_impl(const evp::pack_input input, FILE_PATH evp,
static evp_result pack_impl(const evp::pack_input input, FILE_PATH output,
evp_context_internal& context);

static evp_result unpack_impl(evp::unpack_input input, DIR_PATH output,
Expand All @@ -59,10 +59,10 @@ namespace libevp {
///////////////////////////////////////////////////////////////////////////////
// PUBLIC

evp_result evp::pack(const pack_input& input, const FILE_PATH& evp) {
evp_result evp::pack(const pack_input& input, const FILE_PATH& output) {
try {
evp_context_internal context_internal(nullptr);
return evp_impl::pack_impl(input, evp, context_internal);
return evp_impl::pack_impl(input, output, context_internal);
}
catch (const std::exception& e) {
evp_result result;
Expand All @@ -87,12 +87,12 @@ evp_result evp::unpack(const unpack_input& input, const DIR_PATH& output) {
}
}

void evp::pack_async(const pack_input& input, const FILE_PATH& evp, evp_context* context) {
std::thread t([input, evp, context] {
void evp::pack_async(const pack_input& input, const FILE_PATH& output, evp_context* context) {
std::thread t([input, output, context] {
evp_context_internal context_internal(context);

try {
evp_impl::pack_impl(input, evp, context_internal);
evp_impl::pack_impl(input, output, context_internal);
}
catch (const std::exception& e) {
evp_result result;
Expand Down Expand Up @@ -123,17 +123,17 @@ void evp::unpack_async(const unpack_input& input, const DIR_PATH& output, evp_co
t.detach();
}

evp_result evp::validate_files(const FILE_PATH& evp, std::vector<evp_fd>* failed_fds) {
evp_result evp::validate_files(const FILE_PATH& input, std::vector<evp_fd>* failed_files) {
evp_result result, res;
result.status = evp_result::status::failure;

res = validate_evp_archive(evp, true);
res = validate_evp_archive(input, true);
if (!res) {
result.message = res.message;
return result;
}

fstream_read stream(evp);
fstream_read stream(input);
if (!stream.is_valid()) {
result.message = EVP_STR_FORMAT("Failed to open input archive for reading.");
return result;
Expand Down Expand Up @@ -163,26 +163,26 @@ evp_result evp::validate_files(const FILE_PATH& evp, std::vector<evp_fd>* failed
if (memcmp(hash.data(), file.hash.data(), 16) != 0) {
failed_count++;

if (failed_fds)
failed_fds->push_back(file);
if (failed_files)
failed_files->push_back(file);
}
}

result.status = failed_count == 0 ? evp_result::status::ok : evp_result::status::failure;
return result;
}

evp_result evp::get_archive_fds(const FILE_PATH& evp, std::vector<evp_fd>& files) {
evp_result evp::get_archive_fds(const FILE_PATH& input, std::vector<evp_fd>& files) {
evp_result result, res;
result.status = evp_result::status::failure;

res = validate_evp_archive(evp, true);
res = validate_evp_archive(input, true);
if (!res) {
result.message = res.message;
return result;
}

fstream_read stream(evp);
fstream_read stream(input);
if (!stream.is_valid()) {
result.message = EVP_STR_FORMAT("Failed to open input archive for reading.");
return result;
Expand All @@ -203,27 +203,27 @@ evp_result evp::get_archive_fds(const FILE_PATH& evp, std::vector<evp_fd>& files
return result;
}

evp_result evp::get_file(const FILE_PATH& evp, const evp_fd& fd, std::vector<uint8_t>& buffer) {
evp_result evp::get_file(const FILE_PATH& input, const evp_fd& file, std::vector<uint8_t>& buffer) {
evp_result result, res;
result.status = evp_result::status::failure;

res = validate_evp_archive(evp, true);
res = validate_evp_archive(input, true);
if (!res) {
result.message = res.message;
return result;
}

fstream_read stream(evp);
fstream_read stream(input);
if (!stream.is_valid()) {
result.message = EVP_STR_FORMAT("Failed to open input archive for reading.");
return result;
}

try {
buffer.resize(fd.data_size);
buffer.resize(file.data_size);

stream.seek(fd.data_offset, std::ios::beg);
stream.read(buffer.data(), fd.data_size);
stream.seek(file.data_offset, std::ios::beg);
stream.read(buffer.data(), file.data_size);
}
catch (const std::exception& e) {
result.message = e.what();
Expand All @@ -234,10 +234,10 @@ evp_result evp::get_file(const FILE_PATH& evp, const evp_fd& fd, std::vector<uin
return result;
}

evp_result evp::get_file(const FILE_PATH& evp, const evp_fd& fd, std::stringstream& stream) {
evp_result evp::get_file(const FILE_PATH& input, const evp_fd& file, std::stringstream& stream) {
buffer_t buffer;

auto result = get_file(evp, fd, buffer);
auto result = get_file(input, file, buffer);
if (!result)
return result;

Expand All @@ -246,17 +246,17 @@ evp_result evp::get_file(const FILE_PATH& evp, const evp_fd& fd, std::stringstre
return result;
}

evp_result evp::get_file(const FILE_PATH& evp, const FILE_PATH& file, std::vector<uint8_t>& buffer) {
evp_result evp::get_file(const FILE_PATH& input, const FILE_PATH& file, std::vector<uint8_t>& buffer) {
evp_result result, res;
result.status = evp_result::status::failure;

res = validate_evp_archive(evp, true);
res = validate_evp_archive(input, true);
if (!res) {
result.message = res.message;
return result;
}

fstream_read stream(evp);
fstream_read stream(input);
if (!stream.is_valid()) {
result.message = EVP_STR_FORMAT("Failed to open input archive for reading.");
return result;
Expand Down Expand Up @@ -298,10 +298,10 @@ evp_result evp::get_file(const FILE_PATH& evp, const FILE_PATH& file, std::vecto
return result;
}

evp_result evp::get_file(const FILE_PATH& evp, const FILE_PATH& file, std::stringstream& stream) {
evp_result evp::get_file(const FILE_PATH& input, const FILE_PATH& file, std::stringstream& stream) {
buffer_t buffer;

auto result = get_file(evp, file, buffer);
auto result = get_file(input, file, buffer);
if (!result)
return result;

Expand Down Expand Up @@ -444,7 +444,7 @@ void MD5_hex_string_to_bytes(MD5& md5, uint8_t* bytes) {
///////////////////////////////////////////////////////////////////////////////
// EVP IMPL

evp_result evp_impl::pack_impl(const evp::pack_input input, FILE_PATH evp,
evp_result evp_impl::pack_impl(const evp::pack_input input, FILE_PATH output,
evp_context_internal& context)
{
evp_result result, res;
Expand All @@ -453,8 +453,8 @@ evp_result evp_impl::pack_impl(const evp::pack_input input, FILE_PATH evp,
///////////////////////////////////////////////////////////////////////////
// VERIFY

if (!evp.is_absolute())
evp = std::filesystem::absolute(evp);
if (!output.is_absolute())
output = std::filesystem::absolute(output);

res = validate_directory(input.base);
if (!res) {
Expand All @@ -464,7 +464,7 @@ evp_result evp_impl::pack_impl(const evp::pack_input input, FILE_PATH evp,
return result;
}

res = validate_evp_archive(evp, false);
res = validate_evp_archive(output, false);
if (!res) {
result.message = EVP_STR_FORMAT("Failed to validate output archive path. | {}", res.message);

Expand All @@ -477,7 +477,7 @@ evp_result evp_impl::pack_impl(const evp::pack_input input, FILE_PATH evp,

format::v1::format format;

fstream_write stream(evp);
fstream_write stream(output);
if (!stream.is_valid()) {
result.message = EVP_STR_FORMAT("Failed to open output archive file for writing.");

Expand Down

0 comments on commit 5edd3b5

Please sign in to comment.