mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 22:30:31 +00:00
LibWeb: Implement FileReaderSync
interface
This interface allows the user to read File or Blob objects synchronously from inside workers.
This commit is contained in:
parent
3f71907255
commit
bbcd8bd97c
Notes:
github-actions[bot]
2025-02-28 04:50:48 +00:00
Author: https://github.com/tcl3
Commit: bbcd8bd97c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3667
Reviewed-by: https://github.com/shannonbooth
6 changed files with 170 additions and 9 deletions
41
Libraries/LibWeb/FileAPI/FileReaderSync.h
Normal file
41
Libraries/LibWeb/FileAPI/FileReaderSync.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/FileAPI/FileReader.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
// https://w3c.github.io/FileAPI/#FileReaderSync
|
||||
class FileReaderSync : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(FileReaderSync, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(FileReaderSync);
|
||||
|
||||
public:
|
||||
virtual ~FileReaderSync() override;
|
||||
|
||||
[[nodiscard]] static GC::Ref<FileReaderSync> create(JS::Realm&);
|
||||
static GC::Ref<FileReaderSync> construct_impl(JS::Realm&);
|
||||
|
||||
WebIDL::ExceptionOr<GC::Root<JS::ArrayBuffer>> read_as_array_buffer(Blob&);
|
||||
WebIDL::ExceptionOr<String> read_as_binary_string(Blob&);
|
||||
WebIDL::ExceptionOr<String> read_as_text(Blob&, Optional<String> const& encoding = {});
|
||||
WebIDL::ExceptionOr<String> read_as_data_url(Blob&);
|
||||
|
||||
private:
|
||||
explicit FileReaderSync(JS::Realm&);
|
||||
|
||||
template<typename Result>
|
||||
WebIDL::ExceptionOr<Result> read_as(Blob&, FileReader::Type, Optional<String> const& encoding = {});
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue