42 std::ifstream inStream(filename, std::ios::in | std::ios::binary);
46 inStream.seekg(0, std::ios::end);
47 if (!(inStream.rdstate() & std::ifstream::failbit))
49 const unsigned long int endPos = inStream.tellg();
50 contents.resize((maximumBytes > 0 && (endPos > maximumBytes)) ? maximumBytes : endPos);
51 inStream.seekg(0, std::ios::beg);
52 inStream.read(&contents[0], contents.size());
57 inStream.clear(std::ifstream::goodbit);
60 ss << inStream.rdbuf();
73 std::string
getStringFromFile(std::string
const& filename,
const unsigned long int maximumBytes)
131 return (stat(
fileName.c_str(), &statStr) == 0);
unsigned long id
ID of the file.
std::string getStringFromFile(const char *filename, const unsigned long int maximumBytes)
Reads the content of a file and return it as a string.
std::string getContent(const unsigned long int maximumBytes=1<< 20) const
Get the content of the file limited by maximumBytes.
std::string fileName
Path of the file.
unsigned long getId() const
fo namespace holds the FOSSology library functions.
const std::string & getFileName() const
Utility functions for file handling.
File(unsigned long id, const char *fileName)