Skip to content

Commit

Permalink
Fixes a bug that would throw PlatformNotSupportedException under net6 (
Browse files Browse the repository at this point in the history
  • Loading branch information
Tewr committed Dec 26, 2021
1 parent 696c3bb commit ce7eb63
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
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();

0 comments on commit ce7eb63

Please sign in to comment.