aboutsummaryrefslogtreecommitdiff
path: root/src/zen/cmds/cache_cmd.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-10-04 11:32:46 +0200
committerGitHub Enterprise <[email protected]>2024-10-04 11:32:46 +0200
commit28a4a4766fc745a13b6a4b271eec325b7f28797f (patch)
tree6cac30fbe86ea4e66da03f1af1daa26f3d6ccb2b /src/zen/cmds/cache_cmd.cpp
parentimprove naming and feedback in zen commands (#185) (diff)
downloadarchived-zen-28a4a4766fc745a13b6a4b271eec325b7f28797f.tar.xz
archived-zen-28a4a4766fc745a13b6a4b271eec325b7f28797f.zip
add automatic decompression to cache-get (default on) and oplog-mirror (default off) (#186)
Diffstat (limited to 'src/zen/cmds/cache_cmd.cpp')
-rw-r--r--src/zen/cmds/cache_cmd.cpp14
1 files changed, 13 insertions, 1 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();