1
1
using KristofferStrube . Blazor . Streams ;
2
+ using KristofferStrube . Blazor . WebIDL ;
2
3
using Microsoft . JSInterop ;
3
4
4
5
namespace KristofferStrube . Blazor . FileAPI ;
5
6
6
7
/// <summary>
7
8
/// <see href="https://www.w3.org/TR/FileAPI/#blob-section">Blob browser specs</see>
8
9
/// </summary>
9
- public class BlobInProcess : Blob
10
+ [ IJSWrapperConverter ]
11
+ public class BlobInProcess : Blob , IJSInProcessCreatable < BlobInProcess , Blob >
10
12
{
11
- public new IJSInProcessObjectReference JSReference ;
12
- protected readonly IJSInProcessObjectReference inProcessHelper ;
13
+ /// <inheritdoc />
14
+ public new IJSInProcessObjectReference JSReference { get ; }
13
15
14
16
/// <summary>
15
- /// Constructs a wrapper instance for a given JS Instance of a <see cref="Blob"/> .
17
+ /// A lazily loaded task that evaluates to a helper module instance from the Blazor.FileAPI library .
16
18
/// </summary>
17
- /// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
18
- /// <param name="jSReference">A JS reference to an existing <see cref="Blob"/>.</param>
19
- /// <returns>A wrapper instance for a <see cref="Blob"/>.</returns >
19
+ protected IJSInProcessObjectReference InProcessHelper { get ; }
20
+
21
+ /// <inheritdoc/ >
20
22
public static async Task < BlobInProcess > CreateAsync ( IJSRuntime jSRuntime , IJSInProcessObjectReference jSReference )
23
+ {
24
+ return await CreateAsync ( jSRuntime , jSReference , new ( ) ) ;
25
+ }
26
+
27
+ /// <inheritdoc/>
28
+ public static async Task < BlobInProcess > CreateAsync ( IJSRuntime jSRuntime , IJSInProcessObjectReference jSReference , CreationOptions options )
21
29
{
22
30
IJSInProcessObjectReference inProcessHelper = await jSRuntime . GetInProcessHelperAsync ( ) ;
23
- return new BlobInProcess ( jSRuntime , inProcessHelper , jSReference ) ;
31
+ return new BlobInProcess ( jSRuntime , inProcessHelper , jSReference , options ) ;
24
32
}
25
33
26
34
/// <summary>
@@ -41,19 +49,14 @@ public static async Task<BlobInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInP
41
49
} )
42
50
. ToArray ( ) ;
43
51
IJSInProcessObjectReference jSInstance = await inProcessHelper . InvokeAsync < IJSInProcessObjectReference > ( "constructBlob" , jsBlobParts , options ) ;
44
- return new BlobInProcess ( jSRuntime , inProcessHelper , jSInstance ) ;
52
+ return new BlobInProcess ( jSRuntime , inProcessHelper , jSInstance , new ( ) { DisposesJSReference = true } ) ;
45
53
}
46
54
47
- /// <summary>
48
- /// Constructs a wrapper instance for a given JS Instance of a <see cref="Blob"/>.
49
- /// </summary>
50
- /// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
51
- /// <param name="inProcessHelper">An in process helper instance.</param>
52
- /// <param name="jSReference">A JS reference to an existing <see cref="Blob"/>.</param>
53
- internal BlobInProcess ( IJSRuntime jSRuntime , IJSInProcessObjectReference inProcessHelper , IJSInProcessObjectReference jSReference ) : base ( jSRuntime , jSReference )
55
+ /// <inheritdoc cref="CreateAsync(IJSRuntime, IJSInProcessObjectReference, CreationOptions)"/>
56
+ protected internal BlobInProcess ( IJSRuntime jSRuntime , IJSInProcessObjectReference inProcessHelper , IJSInProcessObjectReference jSReference , CreationOptions options ) : base ( jSRuntime , jSReference , options )
54
57
{
55
- this . inProcessHelper = inProcessHelper ;
56
58
JSReference = jSReference ;
59
+ InProcessHelper = inProcessHelper ;
57
60
}
58
61
59
62
/// <summary>
@@ -63,20 +66,20 @@ internal BlobInProcess(IJSRuntime jSRuntime, IJSInProcessObjectReference inProce
63
66
public new async Task < ReadableStreamInProcess > StreamAsync ( )
64
67
{
65
68
IJSInProcessObjectReference jSInstance = JSReference . Invoke < IJSInProcessObjectReference > ( "stream" ) ;
66
- return await ReadableStreamInProcess . CreateAsync ( jSRuntime , jSInstance ) ;
69
+ return await ReadableStreamInProcess . CreateAsync ( JSRuntime , jSInstance ) ;
67
70
}
68
71
69
72
/// <summary>
70
73
/// The size of this blob.
71
74
/// </summary>
72
75
/// <returns>A <see langword="ulong"/> representing the size of the blob in bytes.</returns>
73
- public ulong Size => inProcessHelper . Invoke < ulong > ( "getAttribute" , JSReference , "size" ) ;
76
+ public ulong Size => InProcessHelper . Invoke < ulong > ( "getAttribute" , JSReference , "size" ) ;
74
77
75
78
/// <summary>
76
79
/// The media type of this blob. This is either a parseable MIME type or an empty string.
77
80
/// </summary>
78
81
/// <returns>The MIME type of this blob.</returns>
79
- public string Type => inProcessHelper . Invoke < string > ( "getAttribute" , JSReference , "type" ) ;
82
+ public string Type => InProcessHelper . Invoke < string > ( "getAttribute" , JSReference , "type" ) ;
80
83
81
84
/// <summary>
82
85
/// Gets some range of the content of a <see cref="Blob"/> as a new <see cref="Blob"/>.
@@ -90,6 +93,6 @@ public BlobInProcess Slice(long? start = null, long? end = null, string? content
90
93
start ??= 0 ;
91
94
end ??= ( long ) Size ;
92
95
IJSInProcessObjectReference jSInstance = JSReference . Invoke < IJSInProcessObjectReference > ( "slice" , start , end , contentType ) ;
93
- return new BlobInProcess ( jSRuntime , inProcessHelper , jSInstance ) ;
96
+ return new BlobInProcess ( JSRuntime , InProcessHelper , jSInstance , new ( ) { DisposesJSReference = true } ) ;
94
97
}
95
98
}
0 commit comments