AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
APathOwner Struct Reference

RAII-style file owner for storing temporary data on disk. More...

#include <AUI/IO/APath.h>

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();
    }
        AFileInputStream(tempFilePath), aui::archive::ExtractTo {
          .prefix = unpackedUpdateDir,
          .pathProjection = &APath::withoutUppermostFolder,
        });
See also
APath::nextRandomTemporary()