Skip to content

Commit a44b8f8

Browse files
refactor(IpfsClient): remove synchronous versions of DoCommand and Download
If you really need a synchronous command use .Result or .Wait
1 parent 2344db7 commit a44b8f8

File tree

3 files changed

+7
-82
lines changed

3 files changed

+7
-82
lines changed

src/IpfsClient.cs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -458,77 +458,7 @@ public async Task<String> UploadAsync(string command, byte[] data, params string
458458
}
459459
}
460460

461-
/// <summary>
462-
/// Perform an <see href="https://ipfs.io/docs/api/">IPFS API command</see> returning a string.
463-
/// </summary>
464-
/// <param name="command">
465-
/// The <see href="https://ipfs.io/docs/api/">IPFS API command</see>, such as
466-
/// <see href="https://ipfs.io/docs/api/#apiv0filels">"file/ls"</see>.
467-
/// </param>
468-
/// <param name="arg">
469-
/// The optional argument to the command.
470-
/// </param>
471-
/// <param name="options">
472-
/// The optional flags to the command.
473-
/// </param>
474-
/// <returns>
475-
/// A string representation of the command's result.
476-
/// </returns>
477-
public string DoCommand(string command, string arg = null, params string[] options)
478-
{
479-
return DoCommandAsync(command, arg, options).Result;
480-
}
481-
482-
/// <summary>
483-
/// Perform an <see href="https://ipfs.io/docs/api/">IPFS API command</see> returning
484-
/// a specific <see cref="Type"/>.
485-
/// </summary>
486-
/// <typeparam name="T">
487-
/// The <see cref="Type"/> of object to return.
488-
/// </typeparam>
489-
/// <param name="command">
490-
/// The <see href="https://ipfs.io/docs/api/">IPFS API command</see>, such as
491-
/// <see href="https://ipfs.io/docs/api/#apiv0filels">"file/ls"</see>.
492-
/// </param>
493-
/// <param name="arg">
494-
/// The optional argument to the command.
495-
/// </param>
496-
/// <param name="options">
497-
/// The optional flags to the command.
498-
/// </param>
499-
/// <returns>
500-
/// A <typeparamref name="T"/>.
501-
/// </returns>
502-
/// <remarks>
503-
/// The command's response is converted to <typeparamref name="T"/> using
504-
/// <c>JsonConvert</c>.
505-
/// </remarks>
506-
public T DoCommand<T>(string command, string arg = null, params string[] options)
507-
{
508-
return DoCommandAsync<T>(command, arg, options).Result;
509-
}
510461

511-
/// <summary>
512-
/// Perform an <see href="https://ipfs.io/docs/api/">IPFS API command</see> returning a
513-
/// <see cref="Stream"/>.
514-
/// </summary>
515-
/// <param name="command">
516-
/// The <see href="https://ipfs.io/docs/api/">IPFS API command</see>, such as
517-
/// <see href="https://ipfs.io/docs/api/#apiv0filels">"file/ls"</see>.
518-
/// </param>
519-
/// <param name="arg">
520-
/// The optional argument to the command.
521-
/// </param>
522-
/// <param name="options">
523-
/// The optional flags to the command.
524-
/// </param>
525-
/// <returns>
526-
/// A <see cref="Stream"/> containing the command's result.
527-
/// </returns>
528-
public Stream Download(string command, string arg = null, params string[] options)
529-
{
530-
return DownloadAsync(command, arg, options).Result;
531-
}
532462

533463
/// <summary>
534464
///

src/MerkleNode.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,7 @@ public byte[] DataBytes
169169
{
170170
get
171171
{
172-
using (var stream = DataStream)
173-
using (var data = new MemoryStream())
174-
{
175-
stream.CopyTo(data);
176-
return data.ToArray();
177-
}
172+
return IpfsClient.Block.GetAsync(Hash).Result.DataBytes;
178173
}
179174
}
180175

@@ -183,7 +178,7 @@ public Stream DataStream
183178
{
184179
get
185180
{
186-
return IpfsClient.Download("block/get", Hash);
181+
return IpfsClient.Block.GetAsync(Hash).Result.DataStream;
187182
}
188183
}
189184

src/TrustedPeerCollection.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void Add(MultiAddress peer)
4141
if (peer == null)
4242
throw new ArgumentNullException();
4343

44-
ipfs.DoCommand("bootstrap/add", peer.ToString());
44+
ipfs.DoCommandAsync("bootstrap/add", peer.ToString()).Wait();
4545
peers = null;
4646
}
4747

@@ -53,7 +53,7 @@ public void Add(MultiAddress peer)
5353
/// </remarks>
5454
public void AddDefaultNodes()
5555
{
56-
ipfs.DoCommand("bootstrap/add", null, "default=true");
56+
ipfs.DoCommandAsync("bootstrap/add", null, "default=true").Wait();
5757
peers = null;
5858
}
5959

@@ -65,7 +65,7 @@ public void AddDefaultNodes()
6565
/// </remarks>
6666
public void Clear()
6767
{
68-
ipfs.DoCommand("bootstrap/rm", null, "all=true");
68+
ipfs.DoCommandAsync("bootstrap/rm", null, "all=true").Wait();
6969
peers = null;
7070
}
7171

@@ -111,7 +111,7 @@ public bool Remove(MultiAddress peer)
111111
if (peer == null)
112112
throw new ArgumentNullException();
113113

114-
ipfs.DoCommand("bootstrap/rm", peer.ToString());
114+
ipfs.DoCommandAsync("bootstrap/rm", peer.ToString()).Wait();
115115
peers = null;
116116
return true;
117117
}
@@ -132,7 +132,7 @@ IEnumerator IEnumerable.GetEnumerator()
132132

133133
void Fetch()
134134
{
135-
peers = ipfs.DoCommand<BootstrapListResponse>("bootstrap/list").Peers;
135+
peers = ipfs.DoCommandAsync<BootstrapListResponse>("bootstrap/list").Result.Peers;
136136
}
137137
}
138138
}

0 commit comments

Comments
 (0)