diff options
| author | Dan Engelbrecht <[email protected]> | 2024-10-04 11:32:46 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-10-04 11:32:46 +0200 |
| commit | 28a4a4766fc745a13b6a4b271eec325b7f28797f (patch) | |
| tree | 6cac30fbe86ea4e66da03f1af1daa26f3d6ccb2b /src | |
| parent | improve naming and feedback in zen commands (#185) (diff) | |
| download | zen-28a4a4766fc745a13b6a4b271eec325b7f28797f.tar.xz zen-28a4a4766fc745a13b6a4b271eec325b7f28797f.zip | |
add automatic decompression to cache-get (default on) and oplog-mirror (default off) (#186)
Diffstat (limited to 'src')
| -rw-r--r-- | src/zen/cmds/cache_cmd.cpp | 14 | ||||
| -rw-r--r-- | src/zen/cmds/cache_cmd.h | 3 | ||||
| -rw-r--r-- | src/zen/cmds/projectstore_cmd.cpp | 20 | ||||
| -rw-r--r-- | src/zen/cmds/projectstore_cmd.h | 1 |
4 files changed, 35 insertions, 3 deletions
diff --git a/src/zen/cmds/cache_cmd.cpp b/src/zen/cmds/cache_cmd.cpp index bf5f308e1..37e7c8fd1 100644 --- a/src/zen/cmds/cache_cmd.cpp +++ b/src/zen/cmds/cache_cmd.cpp @@ -531,6 +531,8 @@ CacheGetCommand::CacheGetCommand() "<attachmenthash>"); m_Options.add_option("", "o", "output-path", "File path for output data", cxxopts::value(m_OutputPath), "<path>"); m_Options.add_option("", "t", "text", "Ouput content of cache entry record as text", cxxopts::value(m_AsText), "<text>"); + m_Options + .add_option("", "d", "decompress", "Decompress data when applicable. Default = true", cxxopts::value(m_Decompress), "<decompress>"); m_Options.parse_positional({"namespace", "bucket", "valuekey", "attachmenthash"}); m_Options.positional_help("namespace bucket valuekey attachmenthash"); } @@ -613,7 +615,17 @@ CacheGetCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) } if (HttpClient::Response Result = Http.Download(Url, std::filesystem::temp_directory_path()); Result) { - IoBuffer ChunkData = Result.ResponsePayload; + auto TryDecompress = [](const IoBuffer& Buffer) -> IoBuffer { + IoHash RawHash; + uint64_t RawSize; + if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer), RawHash, RawSize)) + { + return Compressed.Decompress().AsIoBuffer(); + }; + return std::move(Buffer); + }; + + IoBuffer ChunkData = m_Decompress ? TryDecompress(Result.ResponsePayload) : Result.ResponsePayload; if (m_AsText) { std::string StringData = Result.ToText(); diff --git a/src/zen/cmds/cache_cmd.h b/src/zen/cmds/cache_cmd.h index 225665680..8ba7903fb 100644 --- a/src/zen/cmds/cache_cmd.h +++ b/src/zen/cmds/cache_cmd.h @@ -113,7 +113,8 @@ private: std::string m_ValueKey; std::string m_AttachmentHash; std::string m_OutputPath; - bool m_AsText = false; + bool m_AsText = false; + bool m_Decompress = true; }; } // namespace zen diff --git a/src/zen/cmds/projectstore_cmd.cpp b/src/zen/cmds/projectstore_cmd.cpp index 50f6b3633..14cd2ce3d 100644 --- a/src/zen/cmds/projectstore_cmd.cpp +++ b/src/zen/cmds/projectstore_cmd.cpp @@ -3,6 +3,7 @@ #include "projectstore_cmd.h" #include <zencore/compactbinarybuilder.h> +#include <zencore/compress.h> #include <zencore/filesystem.h> #include <zencore/fmtutils.h> #include <zencore/logging.h> @@ -1669,6 +1670,12 @@ OplogMirrorCommand::OplogMirrorCommand() "Oplog file entry chunk id to limit output, defaults to no filtering", cxxopts::value(m_ChunkIdFilter), "<chunkid>"); + m_Options.add_option("", + "d", + "decompress", + "Decompress data when applicable. Default = false", + cxxopts::value(m_Decompress), + "<decompress>"); m_Options.parse_positional({"project", "oplog", "target"}); m_Options.positional_help("[<projectid> <oplogid> <target>]"); @@ -1768,7 +1775,18 @@ OplogMirrorCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg if (HttpClient::Response ChunkResponse = Http.Download(fmt::format("/prj/{}/oplog/{}/{}"sv, m_ProjectName, m_OplogName, ChunkId), TmpPath)) { - IoBuffer ChunkData = ChunkResponse.ResponsePayload; + auto TryDecompress = [](const IoBuffer& Buffer) -> IoBuffer { + IoHash RawHash; + uint64_t RawSize; + if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Buffer), RawHash, RawSize)) + { + return Compressed.Decompress().AsIoBuffer(); + }; + return std::move(Buffer); + }; + + IoBuffer ChunkData = m_Decompress ? TryDecompress(ChunkResponse.ResponsePayload) : ChunkResponse.ResponsePayload; + std::filesystem::path TargetPath = RootPath / FileName; if (!MoveToFile(TargetPath, ChunkData)) { diff --git a/src/zen/cmds/projectstore_cmd.h b/src/zen/cmds/projectstore_cmd.h index 8eee570c8..5aa050d23 100644 --- a/src/zen/cmds/projectstore_cmd.h +++ b/src/zen/cmds/projectstore_cmd.h @@ -234,6 +234,7 @@ private: std::string m_KeyFilter; std::string m_FilenameFilter; std::string m_ChunkIdFilter; + bool m_Decompress = false; }; } // namespace zen |