@@ -22,7 +22,7 @@ internal FileSystemApi(IpfsClient ipfs)
22
22
this . emptyFolder = new Lazy < DagNode > ( ( ) => ipfs . Object . NewDirectoryAsync ( ) . Result ) ;
23
23
}
24
24
25
- public async Task < IFileSystemNode > AddFileAsync ( string path , AddFileOptions options = null , CancellationToken cancel = default ( CancellationToken ) )
25
+ public async Task < IFileSystemNode > AddFileAsync ( string path , AddFileOptions options = null , CancellationToken cancel = default )
26
26
{
27
27
using ( var stream = new FileStream ( path , FileMode . Open , FileAccess . Read , FileShare . Read ) )
28
28
{
@@ -31,15 +31,16 @@ internal FileSystemApi(IpfsClient ipfs)
31
31
}
32
32
}
33
33
34
- public Task < IFileSystemNode > AddTextAsync ( string text , AddFileOptions options = null , CancellationToken cancel = default ( CancellationToken ) )
34
+ public Task < IFileSystemNode > AddTextAsync ( string text , AddFileOptions options = null , CancellationToken cancel = default )
35
35
{
36
36
return AddAsync ( new MemoryStream ( Encoding . UTF8 . GetBytes ( text ) , false ) , "" , options , cancel ) ;
37
37
}
38
38
39
- public async Task < IFileSystemNode > AddAsync ( Stream stream , string name = "" , AddFileOptions options = null , CancellationToken cancel = default ( CancellationToken ) )
39
+ public async Task < IFileSystemNode > AddAsync ( Stream stream , string name = "" , AddFileOptions options = null , CancellationToken cancel = default )
40
40
{
41
41
if ( options == null )
42
42
options = new AddFileOptions ( ) ;
43
+
43
44
var opts = new List < string > ( ) ;
44
45
if ( ! options . Pin )
45
46
opts . Add ( "pin=false" ) ;
@@ -59,6 +60,7 @@ internal FileSystemApi(IpfsClient ipfs)
59
60
opts . Add ( $ "cid-base=${ options . Encoding } ") ;
60
61
if ( ! string . IsNullOrWhiteSpace ( options . ProtectionKey ) )
61
62
opts . Add ( $ "protect={ options . ProtectionKey } ") ;
63
+
62
64
opts . Add ( $ "chunker=size-{ options . ChunkSize } ") ;
63
65
64
66
var response = await ipfs . Upload2Async ( "add" , cancel , stream , name , opts . ToArray ( ) ) ;
@@ -92,7 +94,6 @@ internal FileSystemApi(IpfsClient ipfs)
92
94
Size = long . Parse ( ( string ) r [ "Size" ] ) ,
93
95
IsDirectory = false ,
94
96
Name = name ,
95
- IpfsClient = ipfs
96
97
} ;
97
98
}
98
99
}
@@ -102,7 +103,7 @@ internal FileSystemApi(IpfsClient ipfs)
102
103
return fsn ;
103
104
}
104
105
105
- public async Task < IFileSystemNode > AddDirectoryAsync ( string path , bool recursive = true , AddFileOptions options = null , CancellationToken cancel = default ( CancellationToken ) )
106
+ public async Task < IFileSystemNode > AddDirectoryAsync ( string path , bool recursive = true , AddFileOptions options = null , CancellationToken cancel = default )
106
107
{
107
108
if ( options == null )
108
109
options = new AddFileOptions ( ) ;
@@ -145,7 +146,6 @@ internal FileSystemApi(IpfsClient ipfs)
145
146
Links = links ,
146
147
IsDirectory = true ,
147
148
Size = directory . Size ,
148
- IpfsClient = ipfs
149
149
} ;
150
150
151
151
}
@@ -163,7 +163,7 @@ internal FileSystemApi(IpfsClient ipfs)
163
163
/// <returns>
164
164
/// The contents of the <paramref name="path"/> as a <see cref="string"/>.
165
165
/// </returns>
166
- public async Task < String > ReadAllTextAsync ( string path , CancellationToken cancel = default ( CancellationToken ) )
166
+ public async Task < String > ReadAllTextAsync ( string path , CancellationToken cancel = default )
167
167
{
168
168
using ( var data = await ReadFileAsync ( path , cancel ) )
169
169
using ( var text = new StreamReader ( data ) )
@@ -186,12 +186,12 @@ internal FileSystemApi(IpfsClient ipfs)
186
186
/// <returns>
187
187
/// A <see cref="Stream"/> to the file contents.
188
188
/// </returns>
189
- public Task < Stream > ReadFileAsync ( string path , CancellationToken cancel = default ( CancellationToken ) )
189
+ public Task < Stream > ReadFileAsync ( string path , CancellationToken cancel = default )
190
190
{
191
191
return ipfs . PostDownloadAsync ( "cat" , cancel , path ) ;
192
192
}
193
193
194
- public Task < Stream > ReadFileAsync ( string path , long offset , long length = 0 , CancellationToken cancel = default ( CancellationToken ) )
194
+ public Task < Stream > ReadFileAsync ( string path , long offset , long length = 0 , CancellationToken cancel = default )
195
195
{
196
196
// https://github.com/ipfs/go-ipfs/issues/5380
197
197
if ( offset > int . MaxValue )
@@ -206,33 +206,36 @@ internal FileSystemApi(IpfsClient ipfs)
206
206
$ "length={ length } ") ;
207
207
}
208
208
209
+ /// <inheritdoc cref="ListAsync"/>
210
+ public Task < IFileSystemNode > ListFileAsync ( string path , CancellationToken cancel = default )
211
+ {
212
+ return ListAsync ( path , cancel ) ;
213
+ }
214
+
209
215
/// <summary>
210
- /// Get information about the file or directory.
216
+ /// Get information about the directory.
211
217
/// </summary>
212
218
/// <param name="path">
213
- /// A path to an existing file or directory, such as "QmXarR6rgkQ2fDSHjSY5nM2kuCXKYGViky5nohtwgF65Ec/about"
214
- /// or "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"
219
+ /// A path to an existing directory, such as "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"
215
220
/// </param>
216
221
/// <param name="cancel">
217
- /// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
222
+ /// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
218
223
/// </param>
219
224
/// <returns></returns>
220
- public async Task < IFileSystemNode > ListFileAsync ( string path , CancellationToken cancel = default ( CancellationToken ) )
225
+ public async Task < IFileSystemNode > ListAsync ( string path , CancellationToken cancel = default )
221
226
{
222
- var json = await ipfs . DoCommandAsync ( "file/ ls" , cancel , path ) ;
227
+ var json = await ipfs . DoCommandAsync ( "ls" , cancel , path ) ;
223
228
var r = JObject . Parse ( json ) ;
224
- var hash = ( string ) r [ "Arguments" ] [ path ] ;
225
- var o = ( JObject ) r [ "Objects" ] [ hash ] ;
229
+ var o = ( JObject ) r [ "Objects" ] ? [ 0 ] ;
230
+
226
231
var node = new FileSystemNode ( )
227
232
{
228
233
Id = ( string ) o [ "Hash" ] ,
229
- Size = ( long ) o [ "Size" ] ,
230
- IsDirectory = ( string ) o [ "Type" ] == "Directory" ,
231
- Links = new FileSystemLink [ 0 ] ,
232
- IpfsClient = ipfs
234
+ IsDirectory = true ,
235
+ Links = Array . Empty < FileSystemLink > ( ) ,
233
236
} ;
234
- var links = o [ "Links" ] as JArray ;
235
- if ( links != null )
237
+
238
+ if ( o [ "Links" ] is JArray links )
236
239
{
237
240
node . Links = links
238
241
. Select ( l => new FileSystemLink ( )
@@ -245,9 +248,9 @@ internal FileSystemApi(IpfsClient ipfs)
245
248
}
246
249
247
250
return node ;
248
- }
249
-
250
- public Task < Stream > GetAsync ( string path , bool compress = false , CancellationToken cancel = default ( CancellationToken ) )
251
+ }
252
+
253
+ public Task < Stream > GetAsync ( string path , bool compress = false , CancellationToken cancel = default )
251
254
{
252
255
return ipfs . PostDownloadAsync ( "get" , cancel , path , $ "compress={ compress } ") ;
253
256
}
0 commit comments