Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug that would throw PlatformNotSupportedException under net6… #187

Merged
merged 2 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Blazor.FileReader/Blazor.FileReader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<PackageTags>blazor blazor-component stream filestream file-stream read-file filereader</PackageTags>
<Configurations>Debug;Release;Ghpages</Configurations>
<PackageId>Tewr.Blazor.FileReader</PackageId>
<PackageReleaseNotes>net6 support</PackageReleaseNotes>
<PackageReleaseNotes>fixes a bug under net6 that would throw PlatformNotSupportedException</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>icon.png</PackageIcon>
<RazorLangVersion>3.0</RazorLangVersion>
<AssemblyName>Tewr.Blazor.FileReader</AssemblyName>
<RootNamespace>Tewr.Blazor.FileReader</RootNamespace>
<AssemblyVersion>3.3.0.21348</AssemblyVersion>
<Version>3.3.0.21348</Version>
<FileVersion>3.3.0.21348</FileVersion>
<AssemblyVersion>3.3.1.21360</AssemblyVersion>
<Version>3.3.1.21360</Version>
<FileVersion>3.3.1.21360</FileVersion>
</PropertyGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public override void Flush()
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
ThrowIfDisposed();
if (Position >= length)
{
return 0;
}

var bytesRead = await fileReaderJsInterop.ReadFileAsync(fileRef, buffer, Position, offset, count, cancellationToken);
Position += bytesRead;
return bytesRead;
Expand Down
3 changes: 3 additions & 0 deletions src/Blazor.FileReader/FileReaderJsInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ internal void Initialize()
UnmarshalledRuntime = new JSUnmarshalledRuntime(CurrentJSRuntime);
}
#endif

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

Expand Down
56 changes: 56 additions & 0 deletions src/Blazor.FileReader/Tewr.Blazor.FileReader.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@
- [CreateMemoryStreamAsync()](#M-Tewr-Blazor-FileReader-IFileReference-CreateMemoryStreamAsync-System-Threading-CancellationToken- 'Tewr.Blazor.FileReader.IFileReference.CreateMemoryStreamAsync(System.Threading.CancellationToken)')
- [CreateMemoryStreamAsync()](#M-Tewr-Blazor-FileReader-IFileReference-CreateMemoryStreamAsync-System-Int32- 'Tewr.Blazor.FileReader.IFileReference.CreateMemoryStreamAsync(System.Int32)')
- [CreateMemoryStreamAsync()](#M-Tewr-Blazor-FileReader-IFileReference-CreateMemoryStreamAsync-System-Int32,System-Threading-CancellationToken- 'Tewr.Blazor.FileReader.IFileReference.CreateMemoryStreamAsync(System.Int32,System.Threading.CancellationToken)')
- [GetJSObjectReferenceAsync()](#M-Tewr-Blazor-FileReader-IFileReference-GetJSObjectReferenceAsync 'Tewr.Blazor.FileReader.IFileReference.GetJSObjectReferenceAsync')
- [GetObjectUrlAsync()](#M-Tewr-Blazor-FileReader-IFileReference-GetObjectUrlAsync 'Tewr.Blazor.FileReader.IFileReference.GetObjectUrlAsync')
- [OpenReadAsync()](#M-Tewr-Blazor-FileReader-IFileReference-OpenReadAsync 'Tewr.Blazor.FileReader.IFileReference.OpenReadAsync')
- [OpenReadBase64Async()](#M-Tewr-Blazor-FileReader-IFileReference-OpenReadBase64Async 'Tewr.Blazor.FileReader.IFileReference.OpenReadBase64Async')
- [ReadFileInfoAsync()](#M-Tewr-Blazor-FileReader-IFileReference-ReadFileInfoAsync 'Tewr.Blazor.FileReader.IFileReference.ReadFileInfoAsync')
- [IObjectUrl](#T-Tewr-Blazor-FileReader-IObjectUrl 'Tewr.Blazor.FileReader.IObjectUrl')
- [Url](#P-Tewr-Blazor-FileReader-IObjectUrl-Url 'Tewr.Blazor.FileReader.IObjectUrl.Url')
- [PasteEventOptions](#T-Tewr-Blazor-FileReader-DropEvents-PasteEventOptions 'Tewr.Blazor.FileReader.DropEvents.PasteEventOptions')
- [Additive](#P-Tewr-Blazor-FileReader-DropEvents-PasteEventOptions-Additive 'Tewr.Blazor.FileReader.DropEvents.PasteEventOptions.Additive')
- [PlatformConfig](#T-Tewr-Blazor-FileReader-PlatformConfig 'Tewr.Blazor.FileReader.PlatformConfig')
Expand Down Expand Up @@ -775,6 +779,36 @@ The length of the resulting [MemoryStream](http://msdn.microsoft.com/query/dev14

A [MemoryStream](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.IO.MemoryStream 'System.IO.MemoryStream') representing the full file, with [Position](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.IO.MemoryStream.Position 'System.IO.MemoryStream.Position') set to 0.

##### Parameters

This method has no parameters.

<a name='M-Tewr-Blazor-FileReader-IFileReference-GetJSObjectReferenceAsync'></a>
### GetJSObjectReferenceAsync() `method`

##### Summary

Returns the underlying file object as an [IJSObjectReference](#T-Microsoft-JSInterop-IJSObjectReference 'Microsoft.JSInterop.IJSObjectReference')

##### Returns



##### Parameters

This method has no parameters.

<a name='M-Tewr-Blazor-FileReader-IFileReference-GetObjectUrlAsync'></a>
### GetObjectUrlAsync() `method`

##### Summary

Returns an object url for a file.

##### Returns



##### Parameters

This method has no parameters.
Expand Down Expand Up @@ -824,6 +858,28 @@ An object containing the file metadata

This method has no parameters.

<a name='T-Tewr-Blazor-FileReader-IObjectUrl'></a>
## IObjectUrl `type`

##### Namespace

Tewr.Blazor.FileReader

##### Summary

Represents an object url for a file.

##### Remarks

https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

<a name='P-Tewr-Blazor-FileReader-IObjectUrl-Url'></a>
### Url `property`

##### Summary

Returns the Object Url.

<a name='T-Tewr-Blazor-FileReader-DropEvents-PasteEventOptions'></a>
## PasteEventOptions `type`

Expand Down
23 changes: 23 additions & 0 deletions src/Blazor.FileReader/Tewr.Blazor.FileReader.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Demo/Net6/Blazor.FileReader.Wasm.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddFileReaderService();
builder.Services.AddFileReaderService(x => x.UseWasmSharedBuffer = true);

await builder.Build().RunAsync();