Skip to content

Commit

Permalink
2 space and check magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Jul 27, 2024
1 parent 93aa2d7 commit 79c8a82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions tools/replay/logreader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include <utility>
#include "tools/replay/filereader.h"
#include "tools/replay/util.h"
#include "common/util.h"

bool LogReader::load(const std::string &url, std::atomic<bool> *abort, bool local_cache, int chunk_size, int retries) {
std::string data = FileReader(local_cache, chunk_size, retries).read(url, abort);
if (!data.empty()) {
if (url.find(".bz2") != std::string::npos) {
if (url.find(".bz2") != std::string::npos || util::starts_with(data, "BZh9")) {
data = decompressBZ2(data, abort);
} else if (url.find(".zst") != std::string::npos) {
} else if (url.find(".zst") != std::string::npos || util::starts_with(data, "\x28\xB5\x2F\xFD")) {
data = decompressZST((std::byte *)data.data(), data.size(), abort);
}
}
Expand Down
20 changes: 10 additions & 10 deletions tools/replay/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,25 +320,25 @@ std::string decompressBZ2(const std::byte *in, size_t in_size, std::atomic<bool>
}

std::string decompressZST(const std::byte *in, size_t in_size, std::atomic<bool> *abort) {
ZSTD_DCtx* dctx = ZSTD_createDCtx();
ZSTD_DCtx *dctx = ZSTD_createDCtx();
assert(dctx != nullptr);

// Initialize input and output buffers
ZSTD_inBuffer input = { in, in_size, 0 };
ZSTD_inBuffer input = {in, in_size, 0};
std::string decompressedData;
const size_t bufferSize = ZSTD_DStreamOutSize(); // recommended output buffer size
const size_t bufferSize = ZSTD_DStreamOutSize(); // recommended output buffer size
std::string outputBuffer(bufferSize, '\0');

while (input.pos < input.size && !(abort && *abort)) {
ZSTD_outBuffer output = { outputBuffer.data(), bufferSize, 0 };
ZSTD_outBuffer output = {outputBuffer.data(), bufferSize, 0};

size_t result = ZSTD_decompressStream(dctx, &output, &input);
if (ZSTD_isError(result)) {
rWarning("decompressZST error: content is corrupt");
break;
}
size_t result = ZSTD_decompressStream(dctx, &output, &input);
if (ZSTD_isError(result)) {
rWarning("decompressZST error: content is corrupt");
break;
}

decompressedData.append(outputBuffer.data(), output.pos);
decompressedData.append(outputBuffer.data(), output.pos);
}

ZSTD_freeDCtx(dctx);
Expand Down

0 comments on commit 79c8a82

Please sign in to comment.