# TemporaryFile.hpp
This File On Github
Ask A Question
API: latest
module: oatpp
#include "oatpp/core/data/resource/TemporaryFile.hpp"
# TemporaryFile
Temporary file - the file which gets deleted when the destructor is called (more precisely when all copies of the same TemporaryFile
object deleted).
The TemporaryFile
object internally stores a shared_ptr
to a file handle. When file handle deleted it also deletes the underlying file.
Thus it's safe to copy TemporaryFile
object and you may treat TemporaryFile
object as a shared_ptr to a temporary file.
extends - oatpp::data::Resource.
namespace oatpp { namespace data { namespace resource {
class TemporaryFile : public Resource {}
}}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | TemporaryFile | Multiple implementations:
|
std::shared_ptr<data::stream::OutputStream> | openOutputStream | Open output stream to a temporary file. |
std::shared_ptr<data::stream::InputStream> | openInputStream | Open input stream to a temporary file. |
oatpp::String | getInMemoryData | Not applicable. |
v_int64 | getKnownSize | Not applicable. |
oatpp::String | getLocation | Get location where temporary data is stored. |
bool | moveFile | Move payload to a different file. |
# TemporaryFile::TemporaryFile
- Default constructor.
TemporaryFile() = default
- Constructor.
Create temporary file with a random name in thetmpDirectory
.
The actual file will be created only after first write to that file.
Example of the generated random file name:f7c6ecd44024ff31.tmp
.- @param tmpDirectory - directory where to create a temporary file.
- @param randomWordSizeBytes - number of random bytes to generate file name.
TemporaryFile(const oatpp::String& tmpDirectory, v_int32 randomWordSizeBytes = 8)
- Constructor.
Create temporary file with thetmpFileName
name in thetmpDirectory
.
- @param tmpDirectory - directory where to create a temporary file.
- @param tmpFileName - predefined name for the temporary file.
TemporaryFile(const oatpp::String& tmpDirectory, const oatpp::String& tmpFileName)
# TemporaryFile::openOutputStream
Open output stream to a temporary file.
Note: stream also captures file-handle. The temporary file won't be deleted until the stream is deleted.
- @return -
std::shared_ptr
to oatpp::data::stream::OutputStream.
std::shared_ptr<data::stream::OutputStream> openOutputStream() override
# TemporaryFile::openInputStream
Open input stream to a temporary file.
Note: stream also captures file-handle. The temporary file won't be deleted until the stream is deleted.
- @return -
std::shared_ptr
oatpp::data::stream::InputStream.
std::shared_ptr<data::stream::InputStream> openInputStream() override
# TemporaryFile::getInMemoryData
Not applicable.
- @return - always returns
nullptr
.
oatpp::String getInMemoryData() override
# TemporaryFile::getKnownSize
Not applicable.
- @return - always returns
-1
.
v_int64 getKnownSize() override
# TemporaryFile::getLocation
Get location where temporary data is stored.
- @return -
[oatpp::String](/api/latest/oatpp/core/Types/#string)
.
oatpp::String getLocation() override
# TemporaryFile::moveFile
Move payload to a different file.
- @param fullFileName - full-file-name. Note: all the parent folders must exist.
- @return -
true
- file was successfully moved,false
- otherwise.
bool moveFile(const oatpp::String& fullFileName)