mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-21 07:57:22 -06:00
Provide torrent creation feature via WebAPI
PR #20366. Closes #5614. Co-authored-by: Radu Carpa <radu.carpa@cern.ch>
This commit is contained in:
committed by
GitHub
parent
15697f904d
commit
0114610a40
@@ -40,6 +40,7 @@
|
||||
#include <QFileDevice>
|
||||
#include <QSaveFile>
|
||||
#include <QString>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include "base/path.h"
|
||||
#include "base/utils/fs.h"
|
||||
@@ -149,3 +150,27 @@ nonstd::expected<void, QString> Utils::IO::saveToFile(const Path &path, const lt
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
nonstd::expected<Path, QString> Utils::IO::saveToTempFile(const QByteArray &data)
|
||||
{
|
||||
QTemporaryFile file {(Utils::Fs::tempPath() / Path(u"file_"_s)).data()};
|
||||
if (!file.open() || (file.write(data) != data.length()) || !file.flush())
|
||||
return nonstd::make_unexpected(file.errorString());
|
||||
|
||||
file.setAutoRemove(false);
|
||||
return Path(file.fileName());
|
||||
}
|
||||
|
||||
nonstd::expected<Path, QString> Utils::IO::saveToTempFile(const lt::entry &data)
|
||||
{
|
||||
QTemporaryFile file {(Utils::Fs::tempPath() / Path(u"file_"_s)).data()};
|
||||
if (!file.open())
|
||||
return nonstd::make_unexpected(file.errorString());
|
||||
|
||||
const int bencodedDataSize = lt::bencode(Utils::IO::FileDeviceOutputIterator {file}, data);
|
||||
if ((file.size() != bencodedDataSize) || !file.flush())
|
||||
return nonstd::make_unexpected(file.errorString());
|
||||
|
||||
file.setAutoRemove(false);
|
||||
return Path(file.fileName());
|
||||
}
|
||||
|
||||
@@ -103,4 +103,6 @@ namespace Utils::IO
|
||||
|
||||
nonstd::expected<void, QString> saveToFile(const Path &path, const QByteArray &data);
|
||||
nonstd::expected<void, QString> saveToFile(const Path &path, const lt::entry &data);
|
||||
nonstd::expected<Path, QString> saveToTempFile(const QByteArray &data);
|
||||
nonstd::expected<Path, QString> saveToTempFile(const lt::entry &data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user