Skip to content

Commit

Permalink
Upgrade to 5 multi targeting (#167)
Browse files Browse the repository at this point in the history
* Updated to 5.0rc1

* Small corrections

* Less of an allocation risk

* Some cleanup, removed repetitive cast

* Build after merge

* Update old value for Wasm detection
  • Loading branch information
Tewr authored Dec 8, 2020
1 parent 43c9328 commit ee28131
Show file tree
Hide file tree
Showing 82 changed files with 2,609 additions and 158 deletions.
99 changes: 23 additions & 76 deletions src/Blazor.FileReader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.ServerSid
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Demo", "Demo", "{8AA482CE-0130-43A1-84BC-92215AF25AED}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{C9B92F56-D84F-4DB7-B8B6-B93D76CE6BA1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.E2ETestsShared", "Tests\Blazor.FileReader.E2ETestsShared\Blazor.FileReader.E2ETestsShared.csproj", "{33687379-9E64-48A3-B639-C4C68ED1E34C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.ServerSideE2ETests", "Tests\Blazor.FileReader.ServerSideE2ETests\Blazor.FileReader.ServerSideE2ETests.csproj", "{2739877D-DB94-4382-B591-BDC62975BCF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.WasmE2ETests", "Tests\Blazor.FileReader.WasmE2ETests\Blazor.FileReader.WasmE2ETests.csproj", "{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "E2ETestApplications", "E2ETestApplications", "{3B98DC81-24B2-4EBF-A629-6A2D7948341C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.E2ETestAppShared", "Tests\E2ETestApplications\Blazor.FileReader.E2ETestAppShared\Blazor.FileReader.E2ETestAppShared.csproj", "{9ADAE778-C2E2-4EDB-9302-1F15B00454CB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.ServerSideTestApp", "Tests\E2ETestApplications\Blazor.FileReader.ServerSideTestApp\Blazor.FileReader.ServerSideTestApp.csproj", "{20935500-FE99-4660-83F6-4F58D48E4464}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.Demo.Common", "Demo\Blazor.FileReader.Demo.Common\Blazor.FileReader.Demo.Common.csproj", "{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.WasmTestApp.Client", "Tests\E2ETestApplications\Blazor.FileReader.WasmTestApp.Client\Blazor.FileReader.WasmTestApp.Client.csproj", "{20017041-698E-4635-B193-5E2F8DB2121B}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Net5", "Net5", "{C37C1525-4B17-48BC-9B12-9E74FBAA9BE8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.WasmTestApp.Server", "Tests\E2ETestApplications\Blazor.FileReader.WasmTestApp.Server\Blazor.FileReader.WasmTestApp.Server.csproj", "{E071BF86-678D-45D2-B4D2-5414AAE6E734}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Blazor3", "Blazor3", "{856A3F73-2C95-4E2E-819C-41F6456EE049}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.Demo.Common", "Demo\Blazor.FileReader.Demo.Common\Blazor.FileReader.Demo.Common.csproj", "{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.Wasm.Demo", "Demo\Blazor3\Blazor.FileReader.Wasm.Demo\Blazor.FileReader.Wasm.Demo.csproj", "{707F28F7-80EF-4A66-BF30-44EB218A4B11}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.FileReader.UnitTests", "Tests\Blazor.FileReader.UnitTests\Blazor.FileReader.UnitTests.csproj", "{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.FileReader.ServerSide.Demo", "Demo\Blazor3\Blazor.FileReader.ServerSide.Demo\Blazor.FileReader.ServerSide.Demo.csproj", "{AEA2CBDF-329E-4B17-9B02-4178D045F528}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -57,77 +45,36 @@ Global
{DD950FC8-40D7-46CE-8144-7D66B3A86286}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{DD950FC8-40D7-46CE-8144-7D66B3A86286}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD950FC8-40D7-46CE-8144-7D66B3A86286}.Release|Any CPU.Build.0 = Release|Any CPU
{33687379-9E64-48A3-B639-C4C68ED1E34C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33687379-9E64-48A3-B639-C4C68ED1E34C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33687379-9E64-48A3-B639-C4C68ED1E34C}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{33687379-9E64-48A3-B639-C4C68ED1E34C}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{33687379-9E64-48A3-B639-C4C68ED1E34C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33687379-9E64-48A3-B639-C4C68ED1E34C}.Release|Any CPU.Build.0 = Release|Any CPU
{2739877D-DB94-4382-B591-BDC62975BCF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2739877D-DB94-4382-B591-BDC62975BCF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2739877D-DB94-4382-B591-BDC62975BCF5}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{2739877D-DB94-4382-B591-BDC62975BCF5}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{2739877D-DB94-4382-B591-BDC62975BCF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2739877D-DB94-4382-B591-BDC62975BCF5}.Release|Any CPU.Build.0 = Release|Any CPU
{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D}.Release|Any CPU.Build.0 = Release|Any CPU
{9ADAE778-C2E2-4EDB-9302-1F15B00454CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9ADAE778-C2E2-4EDB-9302-1F15B00454CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9ADAE778-C2E2-4EDB-9302-1F15B00454CB}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{9ADAE778-C2E2-4EDB-9302-1F15B00454CB}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{9ADAE778-C2E2-4EDB-9302-1F15B00454CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9ADAE778-C2E2-4EDB-9302-1F15B00454CB}.Release|Any CPU.Build.0 = Release|Any CPU
{20935500-FE99-4660-83F6-4F58D48E4464}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20935500-FE99-4660-83F6-4F58D48E4464}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20935500-FE99-4660-83F6-4F58D48E4464}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{20935500-FE99-4660-83F6-4F58D48E4464}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{20935500-FE99-4660-83F6-4F58D48E4464}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20935500-FE99-4660-83F6-4F58D48E4464}.Release|Any CPU.Build.0 = Release|Any CPU
{20017041-698E-4635-B193-5E2F8DB2121B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20017041-698E-4635-B193-5E2F8DB2121B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20017041-698E-4635-B193-5E2F8DB2121B}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{20017041-698E-4635-B193-5E2F8DB2121B}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{20017041-698E-4635-B193-5E2F8DB2121B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20017041-698E-4635-B193-5E2F8DB2121B}.Release|Any CPU.Build.0 = Release|Any CPU
{E071BF86-678D-45D2-B4D2-5414AAE6E734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E071BF86-678D-45D2-B4D2-5414AAE6E734}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E071BF86-678D-45D2-B4D2-5414AAE6E734}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{E071BF86-678D-45D2-B4D2-5414AAE6E734}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{E071BF86-678D-45D2-B4D2-5414AAE6E734}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E071BF86-678D-45D2-B4D2-5414AAE6E734}.Release|Any CPU.Build.0 = Release|Any CPU
{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D6A6678-F90F-4EA3-94A7-A930D27F47E0}.Release|Any CPU.Build.0 = Release|Any CPU
{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703}.Release|Any CPU.Build.0 = Release|Any CPU
{707F28F7-80EF-4A66-BF30-44EB218A4B11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{707F28F7-80EF-4A66-BF30-44EB218A4B11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{707F28F7-80EF-4A66-BF30-44EB218A4B11}.Ghpages|Any CPU.ActiveCfg = Ghpages|Any CPU
{707F28F7-80EF-4A66-BF30-44EB218A4B11}.Ghpages|Any CPU.Build.0 = Ghpages|Any CPU
{707F28F7-80EF-4A66-BF30-44EB218A4B11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{707F28F7-80EF-4A66-BF30-44EB218A4B11}.Release|Any CPU.Build.0 = Release|Any CPU
{AEA2CBDF-329E-4B17-9B02-4178D045F528}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEA2CBDF-329E-4B17-9B02-4178D045F528}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEA2CBDF-329E-4B17-9B02-4178D045F528}.Ghpages|Any CPU.ActiveCfg = Debug|Any CPU
{AEA2CBDF-329E-4B17-9B02-4178D045F528}.Ghpages|Any CPU.Build.0 = Debug|Any CPU
{AEA2CBDF-329E-4B17-9B02-4178D045F528}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEA2CBDF-329E-4B17-9B02-4178D045F528}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9FA01C57-BBB5-420E-AA9B-AD22F39B77ED} = {8AA482CE-0130-43A1-84BC-92215AF25AED}
{DD950FC8-40D7-46CE-8144-7D66B3A86286} = {8AA482CE-0130-43A1-84BC-92215AF25AED}
{33687379-9E64-48A3-B639-C4C68ED1E34C} = {C9B92F56-D84F-4DB7-B8B6-B93D76CE6BA1}
{2739877D-DB94-4382-B591-BDC62975BCF5} = {C9B92F56-D84F-4DB7-B8B6-B93D76CE6BA1}
{2CF5D654-B4DB-41FA-B4B3-2C10E41A854D} = {C9B92F56-D84F-4DB7-B8B6-B93D76CE6BA1}
{3B98DC81-24B2-4EBF-A629-6A2D7948341C} = {C9B92F56-D84F-4DB7-B8B6-B93D76CE6BA1}
{9ADAE778-C2E2-4EDB-9302-1F15B00454CB} = {3B98DC81-24B2-4EBF-A629-6A2D7948341C}
{20935500-FE99-4660-83F6-4F58D48E4464} = {3B98DC81-24B2-4EBF-A629-6A2D7948341C}
{20017041-698E-4635-B193-5E2F8DB2121B} = {3B98DC81-24B2-4EBF-A629-6A2D7948341C}
{E071BF86-678D-45D2-B4D2-5414AAE6E734} = {3B98DC81-24B2-4EBF-A629-6A2D7948341C}
{9FA01C57-BBB5-420E-AA9B-AD22F39B77ED} = {C37C1525-4B17-48BC-9B12-9E74FBAA9BE8}
{DD950FC8-40D7-46CE-8144-7D66B3A86286} = {C37C1525-4B17-48BC-9B12-9E74FBAA9BE8}
{6D6A6678-F90F-4EA3-94A7-A930D27F47E0} = {8AA482CE-0130-43A1-84BC-92215AF25AED}
{7E1DF17E-F84D-44E0-B3C6-64CE3EE0C703} = {C9B92F56-D84F-4DB7-B8B6-B93D76CE6BA1}
{C37C1525-4B17-48BC-9B12-9E74FBAA9BE8} = {8AA482CE-0130-43A1-84BC-92215AF25AED}
{856A3F73-2C95-4E2E-819C-41F6456EE049} = {8AA482CE-0130-43A1-84BC-92215AF25AED}
{707F28F7-80EF-4A66-BF30-44EB218A4B11} = {856A3F73-2C95-4E2E-819C-41F6456EE049}
{AEA2CBDF-329E-4B17-9B02-4178D045F528} = {856A3F73-2C95-4E2E-819C-41F6456EE049}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7BCBB258-C07A-4039-838A-09F3B45F7E58}
Expand Down
31 changes: 20 additions & 11 deletions src/Blazor.FileReader/Blazor.FileReader.csproj
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<BlazorLinkOnBuild>true</BlazorLinkOnBuild>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>2.1.0.20274</Version>
<Version>3.0.0.20340</Version>
<Authors>Tor Knutsson (Tewr)</Authors>
<PackageProjectUrl>https://github.com/Tewr/BlazorFileReader</PackageProjectUrl>
<RepositoryUrl>https://github.com/Tewr/BlazorFileReader</RepositoryUrl>
<Description>Create Read-Only file streams from file input elements or drop targets in Blazor.</Description>
<PackageTags>blazor blazor-component stream filestream file-stream read-file filereader</PackageTags>
<Configurations>Debug;Release;Ghpages</Configurations>
<PackageId>Tewr.Blazor.FileReader</PackageId>
<PackageReleaseNotes></PackageReleaseNotes>
<AssemblyVersion>2.1.0.20274</AssemblyVersion>
<PackageReleaseNotes>Support for to 5, multi-targeting</PackageReleaseNotes>
<AssemblyVersion>3.0.0.20340</AssemblyVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>icon.png</PackageIcon>
<RazorLangVersion>3.0</RazorLangVersion>
<AssemblyName>Tewr.Blazor.FileReader</AssemblyName>
<RootNamespace>Tewr.Blazor.FileReader</RootNamespace>
<FileVersion>2.1.0.20274</FileVersion>
<FileVersion>3.0.0.20340</FileVersion>
</PropertyGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PropertyGroup>
<NoWarn>1701;1702;NU5104</NoWarn>
<DocumentationFile>Blazor.FileReader.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>Blazor.FileReader.xml</DocumentationFile>
</PropertyGroup>


<ItemGroup>
<!-- .js/.css files will be referenced via <script>/<link> tags; other content files will just be included in the app's 'dist' directory without any tags referencing them -->
<EmbeddedResource Include="wwwroot\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net5.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.3" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
</ItemGroup>
Expand All @@ -68,4 +69,12 @@
<Folder Include="Extensions\" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<DefineConstants>$(DefineConstants);NETSTANDARD20</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net5.0'">
<DefineConstants>$(DefineConstants);NET5</DefineConstants>
</PropertyGroup>

</Project>
39 changes: 30 additions & 9 deletions src/Blazor.FileReader/FileReaderJsInterop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
Expand All @@ -21,6 +20,7 @@ private static readonly Dictionary<long, TaskCompletionSource<int>> _readFileUnm
= new Dictionary<long, TaskCompletionSource<int>>();

internal IJSRuntime CurrentJSRuntime;
internal IJSUnmarshalledRuntime UnmarshalledRuntime;

internal FileReaderJsInterop(IJSRuntime jsRuntime, FileReaderServiceOptions options)
{
Expand All @@ -29,6 +29,26 @@ internal FileReaderJsInterop(IJSRuntime jsRuntime, FileReaderServiceOptions opti
_needsInitialization = options.InitializeOnFirstCall;
}

internal void Initialize()
{
if (_options.UseWasmSharedBuffer)
{
#if NET5
UnmarshalledRuntime = CurrentJSRuntime as IJSUnmarshalledRuntime;
#endif
#if NETSTANDARD20
if (JSUnmarshalledRuntime.IsInvokeUnmarshalledSupported())
{
UnmarshalledRuntime = new JSUnmarshalledRuntime(CurrentJSRuntime);
}
#endif
if (UnmarshalledRuntime is null)
{
throw new PlatformNotSupportedException($"{nameof(_options.UseWasmSharedBuffer)}=true is not supported on this platform: Unable to acquire {nameof(IJSUnmarshalledRuntime)}.");
}
}
}

public async Task<bool> RegisterDropEvents(ElementReference elementReference, bool additive)
{
await EnsureInitializedAsync();
Expand Down Expand Up @@ -75,7 +95,7 @@ public async Task EnsureInitializedAsync(bool force = false)
return;
}

await Initialize();
await InitializeAsync();
}

private async Task<int> OpenReadAsync(ElementReference elementReference, int fileIndex)
Expand Down Expand Up @@ -171,8 +191,9 @@ private async Task<int> ReadFileUnmarshalledAsync(
var id = ++_readFileUnmarshalledCallIdSource;
_readFileUnmarshalledCalls[id] = taskCompletionSource;
cancellationToken.Register(() => taskCompletionSource.TrySetCanceled());
// Do not try to push over the buffer here...
CurrentJSRuntime.InvokeUnmarshalled<ReadFileParams, int>(

// Buffer is not allocated here,
UnmarshalledRuntime.InvokeUnmarshalled<ReadFileParams, int>(
$"FileReaderComponent.ReadFileUnmarshalledAsync",
new ReadFileParams {
BufferOffset = bufferOffset,
Expand All @@ -182,11 +203,11 @@ private async Task<int> ReadFileUnmarshalledAsync(
TaskId = id
});

// as it might not survive the heap charge of the following statement
// as the corresponding TypeArray might not survive the heap charge of the following statement
await taskCompletionSource.Task;
// Charge the buffer here instead, once its loadeg on the js side
var bytesRead = CurrentJSRuntime.InvokeUnmarshalled<BufferParams, int>(

// It is safely filled up here instead
var bytesRead = UnmarshalledRuntime.InvokeUnmarshalled<BufferParams, int>(
$"FileReaderComponent.FillBufferUnmarshalled",
new BufferParams
{
Expand Down Expand Up @@ -226,7 +247,7 @@ public static void EndReadFileUnmarshalledAsyncError(long taskId, string error)
taskCompletionSource.SetException(new BrowserFileReaderException(error));
}

private async Task Initialize()
private async Task InitializeAsync()
{
var isLoaded = await IsLoaded();
if (isLoaded)
Expand Down
3 changes: 3 additions & 0 deletions src/Blazor.FileReader/FileReaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public FileReaderService(IJSRuntime jsRuntime, FileReaderServiceOptions options,
options.MaximumRecieveMessageSize = MaximumReceiveMessageSize.Value;
}



this._fileReaderJsInterop = new FileReaderJsInterop(jsRuntime, options);
this._fileReaderJsInterop.Initialize();
}

public IFileReaderServiceOptions Options { get; }
Expand Down
Loading

0 comments on commit ee28131

Please sign in to comment.