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