feat: zlib compression is supported only on linux and mac platforms

This commit is contained in:
Yaming Pei 2025-03-06 20:18:49 +08:00
parent 53b9743ac4
commit 4e79e8f489
3 changed files with 22 additions and 4 deletions

View File

@ -16,7 +16,10 @@
#ifndef INC_BENCHCSV_H_
#define INC_BENCHCSV_H_
#ifndef _WIN32
#include <zlib.h>
#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;

View File

@ -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)

View File

@ -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);
}