From 9fdccf4d7f641724ddb63793fbd5e106f26b90a1 Mon Sep 17 00:00:00 2001 From: KristofferStrube Date: Mon, 11 Mar 2024 19:38:11 +0100 Subject: [PATCH] Changed `ReadableStreamReadResultInProcess.Value` to return `IJSInProcessObjectReference` instead of `IJSObjectReference`. --- .../Pages/Index.razor | 10 ++++++++-- .../ReadableStreamReadResult.InProcess.cs | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/samples/KristofferStrube.Blazor.Streams.WasmExample/Pages/Index.razor b/samples/KristofferStrube.Blazor.Streams.WasmExample/Pages/Index.razor index eb2a2f4..a64c498 100644 --- a/samples/KristofferStrube.Blazor.Streams.WasmExample/Pages/Index.razor +++ b/samples/KristofferStrube.Blazor.Streams.WasmExample/Pages/Index.razor @@ -1,4 +1,5 @@ @page "/" +@using KristofferStrube.Blazor.WebIDL @inject IJSInProcessRuntime JSRuntime Streams - Index @@ -15,7 +16,7 @@ Using the reader we read the chunks until there are no more. } @code { - private List chunkSizes = new(); + private List chunkSizes = new(); private int dataSize = 1000 * 1024; protected override async Task OnInitializedAsync() @@ -28,7 +29,12 @@ Using the reader we read the chunks until there are no more. ReadableStreamReadResultInProcess read = await readableStreamReader.ReadAsync(); while (!read.Done) { - var length = await JSRuntime.InvokeAsync("getAttribute", read.Value, "length"); + await using Uint8ArrayInProcess chunk = await Uint8ArrayInProcess.CreateAsync( + JSRuntime, + read.Value, + new() { DisposesJSReference = true } + ); + var length = chunk.Length; chunkSizes.Add(length); await Task.Delay(100); await read.DisposeAsync(); diff --git a/src/KristofferStrube.Blazor.Streams/ReadableStream/ReadableStreamReadResult.InProcess.cs b/src/KristofferStrube.Blazor.Streams/ReadableStream/ReadableStreamReadResult.InProcess.cs index f0c1879..3829bbc 100644 --- a/src/KristofferStrube.Blazor.Streams/ReadableStream/ReadableStreamReadResult.InProcess.cs +++ b/src/KristofferStrube.Blazor.Streams/ReadableStream/ReadableStreamReadResult.InProcess.cs @@ -35,8 +35,8 @@ internal ReadableStreamReadResultInProcess(IJSRuntime jSRuntime, IJSInProcessObj /// /// A JS Reference to a chunk of data. /// - /// A to a value which can be of any type. - public IJSObjectReference Value => inProcessHelper.Invoke("getAttribute", JSReference, "value"); + /// An to a value which can be of any type. + public IJSInProcessObjectReference Value => inProcessHelper.Invoke("getAttribute", JSReference, "value"); /// /// Indicates whether this is the last read which means that will be undefined.