diff --git a/contrib/zstd/utils/utils_zstd.cc b/contrib/zstd/utils/utils_zstd.cc index 9a8936f..806b3d0 100644 --- a/contrib/zstd/utils/utils_zstd.cc +++ b/contrib/zstd/utils/utils_zstd.cc @@ -28,12 +28,12 @@ std::streamsize GetStreamSize(std::ifstream& stream) { return ssize; } -absl::Status CompressInMemory(ZstdApi& api, std::ifstream& in_file, +absl::Status CompressInMemory(ZstdApi& api, std::ifstream& in_stream, std::ofstream& out_stream, int level) { - std::streamsize ssize = GetStreamSize(in_file); + std::streamsize ssize = GetStreamSize(in_stream); sapi::v::Array inbuf(ssize); - in_file.read(reinterpret_cast(inbuf.GetData()), ssize); - if (in_file.gcount() != ssize) { + in_stream.read(reinterpret_cast(inbuf.GetData()), ssize); + if (in_stream.gcount() != ssize) { return absl::UnavailableError("Unable to read file"); } @@ -57,13 +57,13 @@ absl::Status CompressInMemory(ZstdApi& api, std::ifstream& in_file, return absl::OkStatus(); } -absl::Status DecompressInMemory(ZstdApi& api, std::ifstream& in_file, +absl::Status DecompressInMemory(ZstdApi& api, std::ifstream& in_stream, std::ofstream& out_stream) { int iserr; - std::streamsize ssize = GetStreamSize(in_file); + std::streamsize ssize = GetStreamSize(in_stream); sapi::v::Array inbuf(ssize); - in_file.read(reinterpret_cast(inbuf.GetData()), ssize); - if (in_file.gcount() != ssize) { + in_stream.read(reinterpret_cast(inbuf.GetData()), ssize); + if (in_stream.gcount() != ssize) { return absl::UnavailableError("Unable to read file"); } @@ -94,7 +94,7 @@ absl::Status DecompressInMemory(ZstdApi& api, std::ifstream& in_file, return absl::OkStatus(); } -absl::Status CompressStream(ZstdApi& api, std::ifstream& in_file, +absl::Status CompressStream(ZstdApi& api, std::ifstream& in_stream, std::ofstream& out_stream, int level) { int iserr; @@ -127,8 +127,8 @@ absl::Status CompressStream(ZstdApi& api, std::ifstream& in_file, } // Compress. - while (in_file) { - in_file.read(reinterpret_cast(inbuf.GetData()), inbuf_size); + while (in_stream) { + in_stream.read(reinterpret_cast(inbuf.GetData()), inbuf_size); if (!api.GetSandbox()->TransferToSandboxee(&inbuf).ok()) { return absl::UnavailableError("Unable to transfer data"); @@ -137,10 +137,10 @@ absl::Status CompressStream(ZstdApi& api, std::ifstream& in_file, sapi::v::Struct struct_in; struct_in.mutable_data()->src = static_cast(inbuf.GetRemote()); struct_in.mutable_data()->pos = 0; - struct_in.mutable_data()->size = in_file.gcount(); + struct_in.mutable_data()->size = in_stream.gcount(); ZSTD_EndDirective mode = ZSTD_e_continue; - if (in_file.gcount() < inbuf_size) { + if (in_stream.gcount() < inbuf_size) { mode = ZSTD_e_end; } @@ -170,7 +170,7 @@ absl::Status CompressStream(ZstdApi& api, std::ifstream& in_file, } if (mode == ZSTD_e_continue) { - isdone = (struct_in.mutable_data()->pos == in_file.gcount()); + isdone = (struct_in.mutable_data()->pos == in_stream.gcount()); } else { isdone = (remaining == 0); } @@ -182,7 +182,7 @@ absl::Status CompressStream(ZstdApi& api, std::ifstream& in_file, return absl::OkStatus(); } -absl::Status DecompressStream(ZstdApi& api, std::ifstream& in_file, +absl::Status DecompressStream(ZstdApi& api, std::ifstream& in_stream, std::ofstream& out_stream) { // Create necessary buffers. SAPI_ASSIGN_OR_RETURN(size_t inbuf_size, api.ZSTD_CStreamInSize()); @@ -200,8 +200,8 @@ absl::Status DecompressStream(ZstdApi& api, std::ifstream& in_file, sapi::v::RemotePtr rdctx(dctx); // Decompress. - while (in_file) { - in_file.read(reinterpret_cast(inbuf.GetData()), inbuf_size); + while (in_stream) { + in_stream.read(reinterpret_cast(inbuf.GetData()), inbuf_size); if (!api.GetSandbox()->TransferToSandboxee(&inbuf).ok()) { return absl::UnavailableError("Unable to transfer data"); @@ -209,10 +209,10 @@ absl::Status DecompressStream(ZstdApi& api, std::ifstream& in_file, sapi::v::Struct struct_in; *struct_in.mutable_data() = {static_cast(inbuf.GetRemote()), - (size_t)in_file.gcount(), 0}; + (size_t)in_stream.gcount(), 0}; bool isdone = false; - while (struct_in.mutable_data()->pos < in_file.gcount()) { + while (struct_in.mutable_data()->pos < in_stream.gcount()) { sapi::v::Struct struct_out; *struct_out.mutable_data() = {static_cast(outbuf.GetRemote()), (size_t)outbuf.GetSize(), 0}; diff --git a/contrib/zstd/utils/utils_zstd.h b/contrib/zstd/utils/utils_zstd.h index 1c5f131..cac7a9d 100644 --- a/contrib/zstd/utils/utils_zstd.h +++ b/contrib/zstd/utils/utils_zstd.h @@ -20,14 +20,14 @@ #include "contrib/zstd/sandboxed.h" -absl::Status CompressInMemory(ZstdApi& api, std::ifstream& in_file, - std::ofstream& out_file, int level); -absl::Status DecompressInMemory(ZstdApi& api, std::ifstream& in_file, - std::ofstream& out_file); +absl::Status CompressInMemory(ZstdApi& api, std::ifstream& in_stream, + std::ofstream& out_stream, int level); +absl::Status DecompressInMemory(ZstdApi& api, std::ifstream& in_stream, + std::ofstream& out_stream); -absl::Status CompressStream(ZstdApi& api, std::ifstream& in_file, - std::ofstream& out_file, int level); -absl::Status DecompressStream(ZstdApi& api, std::ifstream& in_file, - std::ofstream& out_file); +absl::Status CompressStream(ZstdApi& api, std::ifstream& in_stream, + std::ofstream& out_stream, int level); +absl::Status DecompressStream(ZstdApi& api, std::ifstream& in_stream, + std::ofstream& out_stream); #endif // CONTRIB_ZSTD_UTILS_UTILS_ZSTD_H_