simplify and avoid temporary buffers when piping to/from gzip
This commit is contained in:
@ -37,13 +37,12 @@ void Reader::open_file(const char *file)
|
||||
{
|
||||
if (fp != nullptr) close_file();
|
||||
|
||||
compressed = 0;
|
||||
const 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
|
||||
@ -51,8 +50,11 @@ void Reader::open_file(const 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)
|
||||
|
||||
Reference in New Issue
Block a user