APathOwner
RAII-style file owner for storing temporary data on disk.
Detailed Description
This class represents a type that transparently converts to underlying APath. When APathOwner is destructed, the
pointed file is cleaned up, too, regardless of it's type.
APathOwner is designed to simplify management of (temporary) files on disk, ensuring cleanup of the pointed file
in RAII (Resource Acquisition Is Initialization) style.
| APathOwner tempFilePath(APath::nextRandomTemporary());
{
AFileOutputStream tempFileOs(tempFilePath);
size_t downloadedBytes = 0;
*ACurl::Builder(std::move(downloadUrl))
.withWriteCallback([&](ACurl& c, AByteBufferView toWrite) {
tempFileOs << toWrite;
downloadedBytes += toWrite.size();
static constexpr auto PRECISION = 100;
// NOLINTNEXTLINE(*-integer-division)
reportDownloadedPercentage(float(PRECISION * downloadedBytes / c.getContentLength()) / float(PRECISION));
return toWrite.size();
})
.runAsync();
}
aui::archive::zip::read(
AFileInputStream(tempFilePath), aui::archive::ExtractTo {
.prefix = unpackedUpdateDir,
.pathProjection = &APath::withoutUppermostFolder,
});
|