Object for Javascript to perform I/O.
More...
#include <file_api.hpp>
|
| file (std::string path, const std::string &mode) |
|
| file (std::FILE *fp, std::function< void(std::FILE *)> destructor) noexcept |
|
virtual | ~file () noexcept |
|
const std::string & | get_path () const noexcept |
|
std::FILE * | get_handle () noexcept |
|
void | close () noexcept |
|
Object for Javascript to perform I/O.
This class can be constructed to Javascript.
It is used in:
- Irccd.File [constructor]
- Irccd.System.popen (optional)
◆ file() [1/2]
irccd::js::file::file |
( |
std::string |
path, |
|
|
const std::string & |
mode |
|
) |
| |
|
inline |
Construct a file specified by path
- Parameters
-
path | the path |
mode | the mode string (for std::fopen) |
- Exceptions
-
std::runtime_error | on failures |
◆ file() [2/2]
irccd::js::file::file |
( |
std::FILE * |
fp, |
|
|
std::function< void(std::FILE *)> |
destructor |
|
) |
| |
|
inlinenoexcept |
Construct a file from a already created FILE pointer (e.g. popen).
The class takes ownership of fp and will close it.
- Precondition
- destructor must not be null
- Parameters
-
fp | the file pointer |
destructor | the function to close fp (e.g. std::fclose) |
◆ ~file()
virtual irccd::js::file::~file |
( |
| ) |
|
|
inlinevirtualnoexcept |
◆ close()
void irccd::js::file::close |
( |
| ) |
|
|
inlinenoexcept |
Force close, can be safely called multiple times.
◆ get_handle()
std::FILE* irccd::js::file::get_handle |
( |
| ) |
|
|
inlinenoexcept |
Get the handle.
- Returns
- the handle or nullptr if the stream was closed
◆ get_path()
const std::string& irccd::js::file::get_path |
( |
| ) |
const |
|
inlinenoexcept |
Get the path.
- Returns
- the path
- Warning
- empty when constructed from the FILE constructor
The documentation for this class was generated from the following file: