mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-06 05:01:25 -07:00
Use QSaveFile wherever applicable
expected.hpp was fetched from:
b803e3c07b/include/nonstd/expected.hpp
This commit is contained in:
parent
81139c0098
commit
21f72baae2
17 changed files with 2597 additions and 88 deletions
|
@ -28,8 +28,13 @@
|
|||
|
||||
#include "io.h"
|
||||
|
||||
#include <libtorrent/bencode.hpp>
|
||||
#include <libtorrent/entry.hpp>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QFileDevice>
|
||||
#include <QSaveFile>
|
||||
#include <QString>
|
||||
|
||||
Utils::IO::FileDeviceOutputIterator::FileDeviceOutputIterator(QFileDevice &device, const int bufferSize)
|
||||
: m_device {&device}
|
||||
|
@ -60,3 +65,24 @@ Utils::IO::FileDeviceOutputIterator &Utils::IO::FileDeviceOutputIterator::operat
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nonstd::expected<void, QString> Utils::IO::saveToFile(const QString &path, const QByteArray &data)
|
||||
{
|
||||
QSaveFile file {path};
|
||||
if (!file.open(QIODevice::WriteOnly) || (file.write(data) != data.size()) || !file.commit())
|
||||
return nonstd::make_unexpected(file.errorString());
|
||||
return {};
|
||||
}
|
||||
|
||||
nonstd::expected<void, QString> Utils::IO::saveToFile(const QString &path, const lt::entry &data)
|
||||
{
|
||||
QSaveFile file {path};
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
return nonstd::make_unexpected(file.errorString());
|
||||
|
||||
const int bencodedDataSize = lt::bencode(Utils::IO::FileDeviceOutputIterator {file}, data);
|
||||
if ((file.size() != bencodedDataSize) || !file.commit())
|
||||
return nonstd::make_unexpected(file.errorString());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue