simplify and avoid temporary buffers when piping to/from gzip

This commit is contained in:
Axel Kohlmeyer
2021-04-07 23:26:21 -04:00
parent a84ac392a3
commit 1ca38db9df
5 changed files with 60 additions and 68 deletions

View File

@ -1954,13 +1954,12 @@ int ReadData::reallocate(int **pcount, int cmax, int amax)
void ReadData::open(char *file)
{
compressed = 0;
char *suffix = file + strlen(file) - 3;
if (suffix > file && strcmp(suffix,".gz") == 0) compressed = 1;
if (!compressed) fp = fopen(file,"r");
else {
if (utils::strmatch(file,"\\.gz$")) {
compressed = 1;
#ifdef LAMMPS_GZIP
std::string gunzip = fmt::format("gzip -c -d {}",file);
auto gunzip = fmt::format("gzip -c -d {}",file);
#ifdef _WIN32
fp = _popen(gunzip.c_str(),"rb");
#else
@ -1968,8 +1967,11 @@ void ReadData::open(char *file)
#endif
#else
error->one(FLERR,"Cannot open gzipped file: " + utils::getsyserror());
error->one(FLERR,"Cannot open gzipped file without gzip support");
#endif
} else {
compressed = 0;
fp = fopen(file,"r");
}
if (fp == nullptr)