Skip to content

Commit

Permalink
Merge pull request #15 from KristofferStrube/feature/readablestream-r…
Browse files Browse the repository at this point in the history
…eadresult-inprocess-value-inprocess

Changed `ReadableStreamReadResultInProcess.Value` to return `IJSInProcessObjectReference` instead of `IJSObjectReference`.
  • Loading branch information
KristofferStrube authored Mar 11, 2024
2 parents 8bfc776 + 9fdccf4 commit 325b418
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/"
@using KristofferStrube.Blazor.WebIDL
@inject IJSInProcessRuntime JSRuntime

<PageTitle>Streams - Index</PageTitle>
Expand All @@ -15,7 +16,7 @@ Using the reader we read the chunks until there are no more.
}

@code {
private List<int> chunkSizes = new();
private List<long> chunkSizes = new();
private int dataSize = 1000 * 1024;

protected override async Task OnInitializedAsync()
Expand All @@ -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<int>("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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ internal ReadableStreamReadResultInProcess(IJSRuntime jSRuntime, IJSInProcessObj
/// <summary>
/// A JS Reference to a chunk of data.
/// </summary>
/// <returns>A <see cref="IJSObjectReference"/> to a value which can be of <c>any</c> type.</returns>
public IJSObjectReference Value => inProcessHelper.Invoke<IJSObjectReference>("getAttribute", JSReference, "value");
/// <returns>An <see cref="IJSInProcessObjectReference"/> to a value which can be of <c>any</c> type.</returns>
public IJSInProcessObjectReference Value => inProcessHelper.Invoke<IJSInProcessObjectReference>("getAttribute", JSReference, "value");

/// <summary>
/// Indicates whether this is the last read which means that <see cref="Value"/> will be <c>undefined</c>.
Expand Down

0 comments on commit 325b418

Please sign in to comment.