@@ -11,7 +11,6 @@ namespace OwlCore.Kubo;
11
11
/// </summary>
12
12
public class MfsStream : Stream
13
13
{
14
- private readonly string _path ;
15
14
private long _length ;
16
15
17
16
/// <summary>
@@ -22,7 +21,7 @@ public class MfsStream : Stream
22
21
/// <param name="client">The client to use for interacting with IPFS.</param>
23
22
public MfsStream ( string path , long length , ICoreApi client )
24
23
{
25
- _path = path ;
24
+ Path = path ;
26
25
_length = length ;
27
26
Client = client ;
28
27
}
@@ -31,6 +30,11 @@ public MfsStream(string path, long length, ICoreApi client)
31
30
/// The IPFS Client to use for retrieving the content.
32
31
/// </summary>
33
32
public ICoreApi Client { get ; }
33
+
34
+ /// <summary>
35
+ /// The MFS path to the file. Relative to the root of MFS.
36
+ /// </summary>
37
+ public string Path { get ; }
34
38
35
39
/// <inheritdoc/>
36
40
public override bool CanRead => true ;
@@ -53,13 +57,13 @@ public MfsStream(string path, long length, ICoreApi client)
53
57
/// <inheritdoc/>
54
58
public override void Flush ( )
55
59
{
56
- _ = Client . Mfs . FlushAsync ( _path ) . Result ;
60
+ _ = Client . Mfs . FlushAsync ( Path ) . Result ;
57
61
}
58
62
59
63
/// <inheritdoc/>
60
64
public override Task FlushAsync ( CancellationToken cancellationToken )
61
65
{
62
- return Client . Mfs . FlushAsync ( _path , cancellationToken ) ;
66
+ return Client . Mfs . FlushAsync ( Path , cancellationToken ) ;
63
67
}
64
68
65
69
/// <inheritdoc/>
@@ -71,10 +75,9 @@ public override int Read(byte[] buffer, int offset, int count)
71
75
/// <inheritdoc/>
72
76
public override async Task < int > ReadAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
73
77
{
74
- Guard . IsLessThanOrEqualTo ( offset + count , Length ) ;
75
78
Guard . IsGreaterThanOrEqualTo ( offset , 0 ) ;
76
79
77
- var result = await Client . Mfs . ReadFileStreamAsync ( _path , offset : Position + offset , count : count , cancellationToken ) ;
80
+ var result = await Client . Mfs . ReadFileStreamAsync ( Path , offset : Position , count : count , cancellationToken ) ;
78
81
var bytes = await result . ToBytesAsync ( cancellationToken ) ;
79
82
80
83
for ( var i = 0 ; i < bytes . Length ; i ++ )
@@ -150,13 +153,13 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc
150
153
SetLength ( Position + count ) ;
151
154
}
152
155
153
- await Client . Mfs . WriteAsync ( _path , buffer , new ( ) { Offset = Position , Count = count , Create = true } , cancellationToken ) ;
156
+ await Client . Mfs . WriteAsync ( Path , buffer , new ( ) { Offset = Position , Count = count , Create = true } , cancellationToken ) ;
154
157
Position += count ;
155
158
}
156
159
157
160
static string GetFileName ( string path )
158
161
{
159
- var dirName = Path . GetDirectoryName ( path ) ;
162
+ var dirName = System . IO . Path . GetDirectoryName ( path ) ;
160
163
return path . Replace ( '/' , '\\ ' ) . Replace ( dirName ?? string . Empty , string . Empty ) . Trim ( '/' ) . Trim ( '\\ ' ) ;
161
164
}
162
165
}
0 commit comments