From 4e79e8f489890e3bb39dd69a9f0f64b1a163d357 Mon Sep 17 00:00:00 2001 From: Yaming Pei Date: Thu, 6 Mar 2025 20:18:49 +0800 Subject: [PATCH] feat: zlib compression is supported only on linux and mac platforms --- tools/taos-tools/inc/benchCsv.h | 5 +++++ tools/taos-tools/src/CMakeLists.txt | 4 +++- tools/taos-tools/src/benchCsv.c | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/taos-tools/inc/benchCsv.h b/tools/taos-tools/inc/benchCsv.h index 624bcadedc..f944600ecb 100644 --- a/tools/taos-tools/inc/benchCsv.h +++ b/tools/taos-tools/inc/benchCsv.h @@ -16,7 +16,10 @@ #ifndef INC_BENCHCSV_H_ #define INC_BENCHCSV_H_ +#ifndef _WIN32 #include +#endif + #include "bench.h" @@ -38,7 +41,9 @@ typedef struct { CsvCompressionLevel compress_level; CsvIoError result; union { +#ifndef _WIN32 gzFile gf; +#endif FILE* fp; } handle; } CsvFileHandle; diff --git a/tools/taos-tools/src/CMakeLists.txt b/tools/taos-tools/src/CMakeLists.txt index 5bc2703165..93b1530020 100644 --- a/tools/taos-tools/src/CMakeLists.txt +++ b/tools/taos-tools/src/CMakeLists.txt @@ -316,6 +316,9 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin ENDIF () ENDIF () + + target_link_libraries(taosBenchmark z) + ELSE () ADD_DEFINITIONS(-DWINDOWS) SET(CMAKE_C_STANDARD 11) @@ -364,4 +367,3 @@ ELSE () TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ${WEBSOCKET_LINK_FLAGS}) ENDIF () -target_link_libraries(taosBenchmark z) diff --git a/tools/taos-tools/src/benchCsv.c b/tools/taos-tools/src/benchCsv.c index 39f1a7983f..d08b9d19b0 100644 --- a/tools/taos-tools/src/benchCsv.c +++ b/tools/taos-tools/src/benchCsv.c @@ -953,12 +953,15 @@ static CsvFileHandle* csvOpen(const char* filename, CsvCompressionLevel compress if (compress_level == CSV_COMPRESS_NONE) { fhdl->handle.fp = fopen(filename, "w"); failed = (!fhdl->handle.fp); - } else { + } +#ifndef _WIN32 + else { char mode[TINY_BUFF_LEN]; (void)snprintf(mode, sizeof(mode), "wb%d", compress_level); fhdl->handle.gf = gzopen(filename, mode); failed = (!fhdl->handle.gf); } +#endif if (failed) { tmfree(fhdl); @@ -986,7 +989,9 @@ static CsvIoError csvWrite(CsvFileHandle* fhdl, const char* buf, size_t size) { fhdl->result = CSV_ERR_WRITE_FAILED; return CSV_ERR_WRITE_FAILED; } - } else { + } +#ifndef _WIN32 + else { int ret = gzwrite(fhdl->handle.gf, buf, size); if (ret != size) { errorPrint("Failed to write csv file: %s. expected written %zu but %d.\n", @@ -998,6 +1003,8 @@ static CsvIoError csvWrite(CsvFileHandle* fhdl, const char* buf, size_t size) { return CSV_ERR_WRITE_FAILED; } } +#endif + return CSV_ERR_OK; } @@ -1012,12 +1019,16 @@ static void csvClose(CsvFileHandle* fhdl) { fclose(fhdl->handle.fp); fhdl->handle.fp = NULL; } - } else { + } +#ifndef _WIN32 + else { if (fhdl->handle.gf) { gzclose(fhdl->handle.gf); fhdl->handle.gf = NULL; } } +#endif + tmfree(fhdl); }