KJB
|
This class transparently opens gzipped or bzip2-ed files. More...
#include <l_stdio_wrap.h>
Public Member Functions | |
File_Ptr_Smart_Read (const std::string &fn) | |
std::string | get_temp_filename () const |
Public Member Functions inherited from kjb::File_Ptr | |
virtual int | close () |
close file before destruction; rarely needed; safe to do twice. More... | |
virtual | ~File_Ptr () |
dtor can simply call close() because closing a null ptr is OK. More... | |
operator FILE * () const | |
transparently use this object wherever a FILE* is used! More... | |
Additional Inherited Members | |
Protected Member Functions inherited from kjb::File_Ptr | |
void | throw_io_error (const std::string &pathname, const char *mode) |
this is what we do when things go terribly wrong More... | |
File_Ptr (const std::string &pathname, const char *mode) | |
ctor needs the pathname and a mode; mode is set by derived class More... | |
File_Ptr () | |
default ctor wraps a null pointer (to set up a later swap maybe) More... | |
void | swap (File_Ptr &that) |
swap the contents of two wrappers More... | |
This class transparently opens gzipped or bzip2-ed files.
This is like a fancier version of File_Ptr_Read, handling for you the chance that you've zipped up the target file, even if you don't remember doing so. I.e., this will automatically try your filename with zip-like suffixes added on if the ordinary filename is not found (or otherwise not readable).
You, the user, are not expected to append ".gz" or ".bz2" to the filename. Rather, the ctor of this class takes your filename (say "apple.txt") and tries to open it. If it fails, it automatically looks for the presence of zipped versions (e.g., "apple.txt.gz" and "apple.txt.bz2"), and if they are found, this unzips them in a temporary file and gives you a pointer to the temporary file. This temporary file has a randomly generated filename; use method get_temp_filename() to access it. When this object is destroyed the temporary file is deleted.
In other words, if the filename given to the ctor is present, then this object acts just like a File_Ptr_Read. If not, but if filename plus a common zip suffix exists, then this object decompresses to a temporary file and opens that as a File_Ptr_Read.
We do not specify the order that the compression suffixes are tested; if more than one are present, any one of them might be opened.
If the input filename is, for example, "apple.txt.bz2" and if that file is present, this file will simply open the binary compressed file for you, which is likely to be non-text. That maybe wasn't what you meant.
|
inline |
|
inline |