73 open(pathname, streamOpt);
111 mode_(modeType::NONE)
116 std::ios_base::openmode openmode
118 std::ios_base::out | std::ios_base::binary
123 openmode |= std::ios_base::app;
137 openmode |= std::ios_base::in;
155 const fileName pathname_gz(pathname +
".gz");
156 const fileName pathname_tmp(pathname +
"~tmp~");
168 const fileName& target = (atomic ? pathname_tmp : pathname_gz);
187 ptr_.reset(
new ogzstream(target, openmode));
195 <<
"No write support for gz compressed files (libz)" 196 <<
" : downgraded to UNCOMPRESSED" <<
nl 197 <<
"file: " << pathname_gz <<
endl;
204 const fileName& target = (atomic ? pathname_tmp : pathname);
224 auto filePtr = std::make_unique<std::ofstream>(target, openmode);
275 (std::ios_base::out | std::ios_base::binary)
285 mode_ = modeType::APPENDING;
291 mode_ |= modeType::ATOMIC;
298 const fileName& pathname,
307 IOstreamOption(IOstreamOption::ASCII, comp),
325 const std::ios_base::openmode openmode
327 std::ios_base::in | std::ios_base::binary
330 ptr_.reset(
new std::ifstream(pathname, openmode));
336 const fileName pathname_gz(pathname +
".gz");
342 ptr_.reset(
new igzstream(pathname_gz, openmode));
347 <<
"No read support for gz compressed files (libz)" 348 <<
" : could use 'gunzip' from the command-line" <<
nl 349 <<
"file: " << pathname_gz <<
endl 369 auto* gz =
dynamic_cast<igzstream*
>(ptr_.get());
380 (std::ios_base::in | std::ios_base::binary)
391 auto* gz =
dynamic_cast<ogzstream*
>(ptr_.get());
399 if (mode_ & modeType::ATOMIC)
404 (std::ios_base::out | std::ios_base::binary)
412 (std::ios_base::out | std::ios_base::binary)
419 auto* file =
dynamic_cast<std::ofstream*
>(ptr_.get());
431 mode_ &= ~modeType::APPENDING;
433 if (mode_ & modeType::ATOMIC)
438 (std::ios_base::out | std::ios_base::binary)
446 (std::ios_base::out | std::ios_base::binary)
457 mode_ &= ~modeType::APPENDING;
459 if (pathname.empty() || !(mode_ & modeType::ATOMIC))
465 auto* gz =
dynamic_cast<ogzstream*
>(ptr_.get());
475 (pathname +
"~tmp~").c_str(),
476 (pathname +
".gz").c_str()
482 auto* file =
dynamic_cast<std::ofstream*
>(ptr_.get());
494 (pathname +
"~tmp~").c_str(),
506 if (dynamic_cast<const igzstream*>(ptr_.get()))
508 return IOstreamOption::compressionType::COMPRESSED;
512 return IOstreamOption::compressionType::UNCOMPRESSED;
520 if (dynamic_cast<const ogzstream*>(ptr_.get()))
522 return IOstreamOption::compressionType::COMPRESSED;
526 return IOstreamOption::compressionType::UNCOMPRESSED;
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
static bool supports_gz() noexcept
True if compiled with libz support.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
IOstreamOption::compressionType whichCompression() const
Which compression type?
Trivial output stream for calculating byte counts.
constexpr char nl
The newline '\n' character (0x0a)
static bool supports_gz() noexcept
True if compiled with libz support.
ofstreamPointer() noexcept
Default construct (empty)
Ostream & endl(Ostream &os)
Add newline and flush stream.
append (seek end each write)
void reopen_gz(const std::string &pathname)
Special 'rewind' method for compressed stream.
A simple container for options an IOstream can normally have.
autoPtr< OFstream > filePtr
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
no append (truncates existing)
void reopen(const std::string &pathname)
Reopen for compressed/non-compressed. Discards append status.
append (seek end after open)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
ifstreamPointer() noexcept=default
Default construct (empty)
compressionType compression() const noexcept
Get the stream compression.
appendType
File appending (NO_APPEND | APPEND_APP | APPEND_ATE)
void close(const std::string &pathname)
Close stream and rename file.
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text...
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
IOstreamOption::compressionType whichCompression() const
Which compression type?
void open(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption())
Attempts to open the specified file for reading.
Type
Enumerations to handle directory entry types.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.