wasm: add Blob and File type

Convenience getters for mime type associated with the object.

Change-Id: I7e3530459e50ac4740d533db59c46e838c94dbcd
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Lorn Potter 2021-11-11 09:27:16 +10:00
parent be84b033dc
commit 0fa98a26fd
2 changed files with 12 additions and 0 deletions

View File

@ -117,6 +117,11 @@ uint64_t File::size() const
return uint64_t(m_file["size"].as<uint53_t>());
}
std::string Blob::type() const
{
return m_blob["type"].as<std::string>();
}
// Streams partial file content into the given buffer asynchronously. The completed
// callback is called on completion.
void File::stream(uint32_t offset, uint32_t length, char *buffer, const std::function<void ()> &completed) const
@ -162,6 +167,11 @@ void File::stream(char *buffer, const std::function<void ()> &completed) const
stream(0, size(), buffer, completed);
}
std::string File::type() const
{
return m_file["type"].as<std::string>();
}
FileList::FileList(const emscripten::val &fileList)
:m_fileList(fileList)
{

View File

@ -88,6 +88,7 @@ namespace qstdweb {
uint32_t size() const;
static Blob copyFrom(const char *buffer, uint32_t size);
emscripten::val val();
std::string type() const;
private:
friend class FileReader;
@ -102,6 +103,7 @@ namespace qstdweb {
Blob slice(uint64_t begin, uint64_t end) const;
std::string name() const;
uint64_t size() const;
std::string type() const;
void stream(uint32_t offset, uint32_t length, char *buffer, const std::function<void ()> &completed) const;
void stream(char *buffer, const std::function<void ()> &completed) const;