LibreWeb-Browser/src/file.cc

37 lines
759 B
C++
Raw Normal View History

2020-12-04 17:51:40 -08:00
#include "file.h"
#include <stdexcept>
2020-12-14 10:40:08 -08:00
#include <fstream>
#include <sstream>
#include <iostream>
2020-12-04 17:51:40 -08:00
File::File() {}
/**
* Get file from disk
* \param path File path
* \return AST model of markdown file (cmark_node)
*/
2020-12-14 10:40:08 -08:00
std::string const File::read(const std::string& path)
2020-12-04 17:51:40 -08:00
{
2020-12-14 10:40:08 -08:00
std::ifstream inFile;
inFile.open(path, std::ifstream::in);
std::stringstream strStream;
strStream << inFile.rdbuf();
return strStream.str();
2020-12-04 17:51:40 -08:00
}
/**
* Fetch file from IFPS network
* \param path File path
* \throw runtime error when something goes wrong
* \return AST model of markdown file (cmark_node)
*/
2020-12-14 10:40:08 -08:00
std::string const File::fetch(const std::string& path)
2020-12-04 17:51:40 -08:00
{
std::stringstream contents;
network.fetchFile(path, &contents);
2020-12-14 10:40:08 -08:00
return contents.str();
2020-12-04 17:51:40 -08:00
}