wasm: extend qstdweb to support objectUrls in File
Change-Id: If346f8afcf4578dedccce6f768e85c7750a9de3e Done-with: Mikolaj.Boc@qt.io Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
e853c83491
commit
a7bf26642b
@ -578,6 +578,17 @@ File::File(const emscripten::val &file)
|
||||
|
||||
}
|
||||
|
||||
File::~File() = default;
|
||||
|
||||
File::File(const File &other) = default;
|
||||
|
||||
File::File(File &&other) = default;
|
||||
|
||||
File &File::operator=(const File &other) = default;
|
||||
|
||||
File &File::operator=(File &&other) = default;
|
||||
|
||||
|
||||
Blob File::slice(uint64_t begin, uint64_t end) const
|
||||
{
|
||||
return Blob(m_file.call<emscripten::val>("slice", uint53_t(begin), uint53_t(end)));
|
||||
@ -623,6 +634,22 @@ emscripten::val File::val() const
|
||||
return m_file;
|
||||
}
|
||||
|
||||
FileUrlRegistration::FileUrlRegistration(File file)
|
||||
{
|
||||
m_path = QString::fromStdString(emscripten::val::global("window")["URL"].call<std::string>(
|
||||
"createObjectURL", file.file()));
|
||||
}
|
||||
|
||||
FileUrlRegistration::~FileUrlRegistration()
|
||||
{
|
||||
emscripten::val::global("window")["URL"].call<void>("revokeObjectURL",
|
||||
emscripten::val(m_path.toStdString()));
|
||||
}
|
||||
|
||||
FileUrlRegistration::FileUrlRegistration(FileUrlRegistration &&other) = default;
|
||||
|
||||
FileUrlRegistration &FileUrlRegistration::operator=(FileUrlRegistration &&other) = default;
|
||||
|
||||
FileList::FileList(const emscripten::val &fileList)
|
||||
:m_fileList(fileList)
|
||||
{
|
||||
|
@ -88,6 +88,12 @@ namespace qstdweb {
|
||||
public:
|
||||
File() = default;
|
||||
explicit File(const emscripten::val &file);
|
||||
~File();
|
||||
|
||||
File(const File &other);
|
||||
File(File &&other);
|
||||
File &operator=(const File &other);
|
||||
File &operator=(File &&other);
|
||||
|
||||
Blob slice(uint64_t begin, uint64_t end) const;
|
||||
std::string name() const;
|
||||
@ -97,11 +103,34 @@ namespace qstdweb {
|
||||
std::function<void()> completed) const;
|
||||
void stream(char *buffer, std::function<void()> completed) const;
|
||||
emscripten::val val() const;
|
||||
void fileUrlRegistration() const;
|
||||
const QString &fileUrlPath() const { return m_urlPath; }
|
||||
emscripten::val file() const { return m_file; }
|
||||
|
||||
private:
|
||||
emscripten::val m_file = emscripten::val::undefined();
|
||||
QString m_urlPath;
|
||||
};
|
||||
|
||||
class Q_CORE_EXPORT FileUrlRegistration
|
||||
{
|
||||
public:
|
||||
explicit FileUrlRegistration(File file);
|
||||
~FileUrlRegistration();
|
||||
|
||||
FileUrlRegistration(const FileUrlRegistration &other) = delete;
|
||||
FileUrlRegistration(FileUrlRegistration &&other);
|
||||
FileUrlRegistration &operator=(const FileUrlRegistration &other) = delete;
|
||||
FileUrlRegistration &operator=(FileUrlRegistration &&other);
|
||||
|
||||
const QString &path() const { return m_path; }
|
||||
|
||||
private:
|
||||
QString m_path;
|
||||
};
|
||||
|
||||
using FileUrlRegistrations = std::vector<std::unique_ptr<FileUrlRegistration>>;
|
||||
|
||||
class Q_CORE_EXPORT FileList {
|
||||
public:
|
||||
FileList() = default;
|
||||
|
Loading…
x
Reference in New Issue
Block a user