mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-16 05:51:55 +00:00
LibWeb: Use DefaultReader request in read_all_chunks instead of ReadLoop
ReadLoop requests require the chunks to be Uint8Array objects, however, TextEncoderStream requires a String (Convertible) value. This is fixed by implementing read_all_chunks as a loop of DefaultReader requests instead, which is an identity transformation. This should be okay to do, as stream chunk steps expect a JS::Value, and convert it to the type they want.
This commit is contained in:
parent
187f8c5460
commit
c14d5f27f9
Notes:
github-actions[bot]
2025-02-07 16:06:06 +00:00
Author: https://github.com/Lubrsi
Commit: c14d5f27f9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3481
Reviewed-by: https://github.com/trflynn89 ✅
3 changed files with 43 additions and 16 deletions
|
@ -353,15 +353,12 @@ GC::Ref<WebIDL::Promise> readable_stream_pipe_to(ReadableStream& source, Writabl
|
|||
|
||||
// FIXME: Currently a naive implementation that uses ReadableStreamDefaultReader::read_all_chunks() to read all chunks
|
||||
// from the source and then through the callback success_steps writes those chunks to the destination.
|
||||
auto chunk_steps = GC::create_function(realm.heap(), [&realm, writer](ByteBuffer buffer) {
|
||||
auto array_buffer = JS::ArrayBuffer::create(realm, move(buffer));
|
||||
auto chunk = JS::Uint8Array::create(realm, array_buffer->byte_length(), *array_buffer);
|
||||
|
||||
auto chunk_steps = GC::create_function(realm.heap(), [&realm, writer](JS::Value chunk) {
|
||||
auto promise = writable_stream_default_writer_write(writer, chunk);
|
||||
WebIDL::resolve_promise(realm, promise, JS::js_undefined());
|
||||
});
|
||||
|
||||
auto success_steps = GC::create_function(realm.heap(), [promise, &realm, reader, writer](ByteBuffer) {
|
||||
auto success_steps = GC::create_function(realm.heap(), [promise, &realm, reader, writer]() {
|
||||
// Make sure we close the acquired writer.
|
||||
WebIDL::resolve_promise(realm, writable_stream_default_writer_close(*writer), JS::js_undefined());
|
||||
readable_stream_default_reader_release(*reader);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue