Skip to content

Commit bce3aba

Browse files
Added method comments
1 parent c466cfc commit bce3aba

3 files changed

Lines changed: 81 additions & 5 deletions

File tree

src/KristofferStrube.Blazor.FileAPI/Blob.InProcess.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ internal BlobInProcess(IJSRuntime jSRuntime, IJSInProcessObjectReference inProce
6767
/// <returns>The MIME type of this blob.</returns>
6868
public string Type => inProcessHelper.Invoke<string>("getAttribute", JSReference, "type");
6969

70+
/// <summary>
71+
/// Gets some range of the content of a <see cref="Blob"/> as a new <see cref="Blob"/>.
72+
/// </summary>
73+
/// <param name="start">The start index of the range. If <see langword="null"/> or negative then <c>0</c> is assumed.</param>
74+
/// <param name="end">The start index of the range. If <see langword="null"/> or larger than the size of the original <see cref="Blob"/> then the size of the original <see cref="Blob"/> is assumed.</param>
75+
/// <param name="contentType">An optional MIME type of the new <see cref="Blob"/>. If <see langword="null"/> then the MIME type of the original <see cref="Blob"/> is used.</param>
76+
/// <returns>A new <see cref="Blob"/>.</returns>
7077
public Blob Slice(long? start = null, long? end = null, string? contentType = null)
7178
{
7279
start ??= 0;

src/KristofferStrube.Blazor.FileAPI/Blob.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public async Task<string> GetTypeAsync()
6767
return await helper.InvokeAsync<string>("getAttribute", JSReference, "type");
6868
}
6969

70+
/// <summary>
71+
/// Gets some range of the content of a <see cref="Blob"/> as a new <see cref="Blob"/>.
72+
/// </summary>
73+
/// <param name="start">The start index of the range. If <see langword="null"/> or negative then <c>0</c> is assumed.</param>
74+
/// <param name="end">The start index of the range. If <see langword="null"/> or larger than the size of the original <see cref="Blob"/> then the size of the original <see cref="Blob"/> is assumed.</param>
75+
/// <param name="contentType">An optional MIME type of the new <see cref="Blob"/>. If <see langword="null"/> then the MIME type of the original <see cref="Blob"/> is used.</param>
76+
/// <returns>A new <see cref="Blob"/>.</returns>
7077
public async Task<Blob> SliceAsync(long? start = null, long? end = null, string? contentType = null)
7178
{
7279
start ??= 0;
@@ -75,12 +82,20 @@ public async Task<Blob> SliceAsync(long? start = null, long? end = null, string?
7582
return new Blob(jSRuntime, jSInstance);
7683
}
7784

85+
/// <summary>
86+
/// Creates a new <see cref="ReadableStream"/> from the <see cref="Blob"/>.
87+
/// </summary>
88+
/// <returns>A new wrapper for a <see cref="ReadableStream"/></returns>
7889
public async Task<ReadableStream> StreamAsync()
7990
{
8091
IJSObjectReference jSInstance = await JSReference.InvokeAsync<IJSObjectReference>("stream");
8192
return ReadableStream.Create(jSRuntime, jSInstance);
8293
}
8394

95+
/// <summary>
96+
/// Creates a new <see cref="ReadableStreamInProcess"/> from the <see cref="Blob"/>.
97+
/// </summary>
98+
/// <returns>A new wrapper for a <see cref="ReadableStreamInProcess"/> which can access members and call non-promise methods synchronously.</returns>
8499
public async Task<ReadableStreamInProcess> StreamInProcessAsync()
85100
{
86101
IJSInProcessObjectReference jSInstance = await JSReference.InvokeAsync<IJSInProcessObjectReference>("stream");

src/KristofferStrube.Blazor.FileAPI/FileReader.cs

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static FileReader Create(IJSRuntime jSRuntime, IJSObjectReference jSRefer
2323
/// Constructs a wrapper instance using the standard constructor.
2424
/// </summary>
2525
/// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
26-
/// <returns></returns>
26+
/// <returns>A wrapper instance for a <see cref="FileReader"/>.</returns>
2727
public static async Task<FileReader> CreateAsync(IJSRuntime jSRuntime)
2828
{
2929
IJSObjectReference helper = await jSRuntime.GetHelperAsync();
@@ -44,26 +44,52 @@ internal FileReader(IJSRuntime jSRuntime, IJSObjectReference jSReference) : base
4444

4545
public DotNetObjectReference<FileReader> ObjRef { get; init; }
4646

47+
/// <summary>
48+
/// Starts a new read for some <see cref="Blob"/> as an <see langword="byte"/>[] which can be read from <see cref="GetResultAsByteArrayAsync"/> once the load has ended which can be checked by setting the action <see cref="OnLoadEnd"/>.
49+
/// </summary>
50+
/// <param name="blob">The <see cref="Blob"/> that should be read asynchronously.</param>
51+
/// <returns></returns>
4752
public async Task ReadAsArrayBufferAsync(Blob blob)
4853
{
4954
await JSReference.InvokeVoidAsync("readAsArrayBuffer", blob.JSReference);
5055
}
5156

57+
/// <summary>
58+
/// Starts a new read for some <see cref="Blob"/> as a binarily encoded <see langword="string"/> which can be read from <see cref="GetResultAsStringAsync"/> once the load has ended which can be checked by setting the action <see cref="OnLoadEnd"/>.
59+
/// </summary>
60+
/// <param name="blob">The <see cref="Blob"/> that should be read asynchronously.</param>
61+
/// <returns></returns>
5262
public async Task ReadAsBinaryStringAsync(Blob blob)
5363
{
5464
await JSReference.InvokeVoidAsync("readAsBinaryString", blob.JSReference);
5565
}
5666

67+
/// <summary>
68+
/// Starts a new read for some <see cref="Blob"/> as a <see langword="string"/> which can be read from <see cref="GetResultAsStringAsync"/> once the load has ended which can be checked by setting the action <see cref="OnLoadEnd"/>.
69+
/// </summary>
70+
/// <param name="blob">The <see cref="Blob"/> that should be read asynchronously.</param>
71+
/// <param name="encoding">An optional encoding for the text. The default is UTF-8.</param>
72+
/// <returns></returns>
5773
public async Task ReadAsTextAsync(Blob blob, string? encoding = null)
5874
{
5975
await JSReference.InvokeVoidAsync("readAsText", blob.JSReference, encoding);
6076
}
6177

78+
/// <summary>
79+
/// Starts a new read for some <see cref="Blob"/> as a base64 encoded Data URL which can be read from <see cref="GetResultAsStringAsync"/> once the load has ended which can be checked by setting the action <see cref="OnLoadEnd"/>.
80+
/// </summary>
81+
/// <param name="blob">The <see cref="Blob"/> that should be read asynchronously.</param>
82+
/// <returns></returns>
6283
public async Task ReadAsDataURLAsync(Blob blob)
6384
{
6485
await JSReference.InvokeVoidAsync("readAsDataURL", blob.JSReference);
6586
}
6687

88+
/// <summary>
89+
/// Terminates the load if the <see cref="GetReadyStateAsync"/> is <see cref="LOADING"/> else it sets the result to <see langword="null"/>.
90+
/// </summary>
91+
/// <param name="blob">The <see cref="Blob"/> read that should be terminated.</param>
92+
/// <returns></returns>
6793
public async Task AbortAsync(Blob blob)
6894
{
6995
await JSReference.InvokeVoidAsync("abort", blob.JSReference);
@@ -73,14 +99,18 @@ public async Task AbortAsync(Blob blob)
7399
public const ushort LOADING = 1;
74100
public const ushort DONE = 2;
75101

102+
/// <summary>
103+
/// Gets the state of the <see cref="FileReader"/>.
104+
/// </summary>
105+
/// <returns>As a standard either <see cref="EMPTY"/>, <see cref="LOADING"/> or <see cref="DONE"/></returns>
76106
public async Task<ushort> GetReadyStateAsync()
77107
{
78108
IJSObjectReference helper = await helperTask.Value;
79109
return await helper.InvokeAsync<ushort>("getAttribute", JSReference, "readyState");
80110
}
81111

82112
/// <summary>
83-
/// Checks whether the result is a either a string or a byte array.
113+
/// Checks whether the result is a either a <see langword="string"/> or a byte array.
84114
/// </summary>
85115
/// <returns>Either the type of <see langword="string"/> or type of <see cref="byte"/>[].</returns>
86116
public async Task<Type?> GetResultTypeAsync()
@@ -90,12 +120,20 @@ public async Task<ushort> GetReadyStateAsync()
90120
return isArrayBuffer ? typeof(byte[]) : typeof(string);
91121
}
92122

123+
/// <summary>
124+
/// Gets the result of the read a <see langword="string"/>.
125+
/// </summary>
126+
/// <returns>A <see langword="string"/> representing the read. If there was no result from the read or if the read has not ended yet then it will be <see langword="null"/>.</returns>
93127
public async Task<string?> GetResultAsStringAsync()
94128
{
95129
IJSObjectReference helper = await helperTask.Value;
96130
return await helper.InvokeAsync<string>("getAttribute", JSReference, "result");
97131
}
98132

133+
/// <summary>
134+
/// Gets the result of the read a <see langword="byte"/>[].
135+
/// </summary>
136+
/// <returns>A <see langword="byte"/>[] representing the read. If there was no result from the read or if the read has not ended yet then it will be <see langword="null"/>.</returns>
99137
public async Task<byte[]?> GetResultAsByteArrayAsync()
100138
{
101139
IJSObjectReference helper = await helperTask.Value;
@@ -104,7 +142,7 @@ public async Task<ushort> GetReadyStateAsync()
104142
}
105143

106144
/// <summary>
107-
/// Gets the error object reference which will be null if no error occured.
145+
/// Gets the error object reference which will be <see langword="null"/> if no error occured.
108146
/// </summary>
109147
/// <returns>A nullable IJSObjectReference because it was out of scope to wrap the Exception API.</returns>
110148
public async Task<IJSObjectReference?> GetErrorAsync()
@@ -113,21 +151,39 @@ public async Task<ushort> GetReadyStateAsync()
113151
return await helper.InvokeAsync<IJSObjectReference?>("getAttribute", JSReference, "error");
114152
}
115153

154+
/// <summary>
155+
/// Invoked when a load starts.
156+
/// </summary>
116157
[JsonIgnore]
117158
public Func<ProgressEvent, Task>? OnLoadStart { get; set; }
118159

160+
/// <summary>
161+
/// Invoked when the progress of a load changes which includes when it ends.
162+
/// </summary>
119163
[JsonIgnore]
120164
public Func<ProgressEvent, Task>? OnProgress { get; set; }
121165

166+
/// <summary>
167+
/// Invoked when a load ends successfully.
168+
/// </summary>
122169
[JsonIgnore]
123170
public Func<ProgressEvent, Task>? OnLoad { get; set; }
124171

172+
/// <summary>
173+
/// Invoked when a load is aborted.
174+
/// </summary>
125175
[JsonIgnore]
126176
public Func<ProgressEvent, Task>? OnAbort { get; set; }
127177

178+
/// <summary>
179+
/// Invoked when a load fails due to an error.
180+
/// </summary>
128181
[JsonIgnore]
129182
public Func<ProgressEvent, Task>? OnError { get; set; }
130183

184+
/// <summary>
185+
/// invoked when a load finishes successfully or not.
186+
/// </summary>
131187
[JsonIgnore]
132188
public Func<ProgressEvent, Task>? OnLoadEnd { get; set; }
133189

@@ -172,6 +228,4 @@ public async Task InvokeOnLoadEnd(IJSObjectReference jsProgressEvent)
172228
if (OnLoadEnd is null) return;
173229
await OnLoadEnd.Invoke(new ProgressEvent(jSRuntime, jsProgressEvent));
174230
}
175-
176-
177231
}

0 commit comments

Comments
 (0)