mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-30 23:12:56 +00:00
LibWeb: Add an initial implementation for Web::FileAPI::FileReader
Some steps are still to be implemented, namely: * Properly aborting the read algorithm * Handling BinaryString type properly * Setting error on any error But as it stands, this is enough functionality for the basic case of reading the contents of a blob using the FileReader API.
This commit is contained in:
parent
47616210b6
commit
77d32fcb5f
Notes:
sideshowbarker
2024-07-17 06:29:49 +09:00
Author: https://github.com/shannonbooth
Commit: 77d32fcb5f
Pull-request: https://github.com/SerenityOS/serenity/pull/21008
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ
7 changed files with 545 additions and 0 deletions
28
Tests/LibWeb/Text/input/FileAPI/filereader-basic.html
Normal file
28
Tests/LibWeb/Text/input/FileAPI/filereader-basic.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest((done) => {
|
||||
const array = ['This is some data to be read! 🦬'];
|
||||
let blob = new Blob(array, { type: "application/octet-stream"});
|
||||
let fileReader = new FileReader();
|
||||
|
||||
let count = 0;
|
||||
|
||||
// Trigger events in order of readAs Text->DataURL->ArrayBuffer
|
||||
fileReader.addEventListener("loadend", () => {
|
||||
++count;
|
||||
|
||||
if (count === 1) {
|
||||
println(`${count}: readAsText(): '${fileReader.result}' error: '${fileReader.error}'`);
|
||||
fileReader.readAsDataURL(blob);
|
||||
} else if (count === 2) {
|
||||
println(`${count}: readAsDataURL(): '${fileReader.result}' error: '${fileReader.error}'`);
|
||||
fileReader.readAsArrayBuffer(blob);
|
||||
} else if (count === 3) {
|
||||
println(`${count}: readAsArrayBuffer(): '${new TextDecoder().decode(fileReader.result)}' error: '${fileReader.error}'`);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
fileReader.readAsText(blob);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue