file_detect Class Reference

#include <file_detect.h>


Detailed Description

Read a (possibly compressed) file and automatically detect the file format.

Really nasty hack. This works by copying the file to a temporary file in /tmp and then uncompressing it using a call to system("gunzip /tmp/filename") . When the file is closed, the temporary file is removed using 'rm -f'.

If the filename ends with ".gz" or ".bz2", then input_detect will try to uncompress it (using gunzip or bunzip2), otherwise, the file will be treated as normal.

Note that there must be enough disk space in the temporary directory for the uncompressed file or the read will fail.

Idea for future:
Allow the user to specify the compression commands in configure, or at least specify the path to gzip, bzip2, etc.

Definition at line 57 of file file_detect.h.


Public Member Functions

virtual ~file_detect ()
in_file_formatopen (const char *s)
 Open an input file with the given name.
virtual int close ()
 Close an input file.
virtual bool is_compressed ()
 Return true if the opened file was originally compressed.
virtual bool is_binary ()
 Return true if the opened file was a binary file.

Protected Attributes

std::string temp_filename
 The temporary filename.
std::string user_filename
 The user-supplied filename.
in_file_formatiffp
 The input file.
bool compressed
 True if the file was compressed.
bool binary
 True if the file was a binary file.

Member Function Documentation

in_file_format* open ( const char *  s  ) 

Open an input file with the given name.

If the filename ends with ".gz" or ".bz2", then the file is assumed to be compressed.

It is important to note that the file is not closed until file_detect::close() method is called.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page