Skip to content

Commit 4acdc9f

Browse files
committed
Inherit fixes and breaking changes from IpfsShipyard.Ipfs.Core 0.3.0
1 parent 80bf6d9 commit 4acdc9f

File tree

5 files changed

+43
-70
lines changed

5 files changed

+43
-70
lines changed

src/CoreApi/BitswapApi.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ internal BitswapApi(IpfsClient ipfs)
1616
this.ipfs = ipfs;
1717
}
1818

19-
public Task<IDataBlock> GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
20-
{
21-
return ipfs.Block.GetAsync(id, cancel);
22-
}
23-
2419
public async Task<IEnumerable<Cid>> WantsAsync(MultiHash peer = null, CancellationToken cancel = default(CancellationToken))
2520
{
2621
var json = await ipfs.DoCommandAsync("bitswap/wantlist", cancel, peer?.ToString());
@@ -35,11 +30,6 @@ internal BitswapApi(IpfsClient ipfs)
3530
return Cid.Decode(obj["/"].ToString());
3631
});
3732
}
38-
39-
public async Task UnwantAsync(Cid id, CancellationToken cancel = default(CancellationToken))
40-
{
41-
await ipfs.DoCommandAsync("bitswap/unwant", cancel, id);
42-
}
4333

4434
public async Task<BitswapLedger> LedgerAsync(Peer peer, CancellationToken cancel = default(CancellationToken))
4535
{

src/CoreApi/BlockApi.cs

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Ipfs.CoreApi;
1+
using Ipfs.CoreApi;
22
using Newtonsoft.Json.Linq;
33
using System.Collections.Generic;
4-
using System.IO;
4+
using System.IO;
55
using System.Net.Http;
66
using System.Threading;
77
using System.Threading.Tasks;
8-
8+
99
namespace Ipfs.Http
1010
{
1111
class BlockApi : IBlockApi
@@ -17,70 +17,64 @@ internal BlockApi(IpfsClient ipfs)
1717
this.ipfs = ipfs;
1818
}
1919

20-
public async Task<IDataBlock> GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
20+
public async Task<byte[]> GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
2121
{
22-
var data = await ipfs.DownloadBytesAsync("block/get", cancel, id);
23-
return new Block
24-
{
25-
DataBytes = data,
26-
Id = id,
27-
Size = data.Length,
28-
};
22+
return await ipfs.DownloadBytesAsync("block/get", cancel, id);
2923
}
3024

3125
public async Task<Cid> PutAsync(
32-
byte[] data,
26+
byte[] data,
3327
string contentType = Cid.DefaultContentType,
3428
string multiHash = MultiHash.DefaultAlgorithmName,
3529
string encoding = MultiBase.DefaultAlgorithmName,
3630
bool pin = false,
3731
CancellationToken cancel = default(CancellationToken))
3832
{
3933
var options = new List<string>();
40-
if (multiHash != MultiHash.DefaultAlgorithmName ||
41-
contentType != Cid.DefaultContentType ||
42-
encoding != MultiBase.DefaultAlgorithmName)
43-
{
44-
options.Add($"mhtype={multiHash}");
45-
options.Add($"format={contentType}");
46-
options.Add($"cid-base={encoding}");
34+
if (multiHash != MultiHash.DefaultAlgorithmName ||
35+
contentType != Cid.DefaultContentType ||
36+
encoding != MultiBase.DefaultAlgorithmName)
37+
{
38+
options.Add($"mhtype={multiHash}");
39+
options.Add($"format={contentType}");
40+
options.Add($"cid-base={encoding}");
4741
}
48-
var json = await ipfs.UploadAsync("block/put", cancel, data, options.ToArray());
49-
var info = JObject.Parse(json);
42+
var json = await ipfs.UploadAsync("block/put", cancel, data, options.ToArray());
43+
var info = JObject.Parse(json);
5044
Cid cid = (string)info["Key"];
5145

52-
if (pin)
53-
{
54-
await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
46+
if (pin)
47+
{
48+
await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
5549
}
5650

5751
return cid;
5852
}
5953

6054
public async Task<Cid> PutAsync(
61-
Stream data,
55+
Stream data,
6256
string contentType = Cid.DefaultContentType,
6357
string multiHash = MultiHash.DefaultAlgorithmName,
6458
string encoding = MultiBase.DefaultAlgorithmName,
6559
bool pin = false,
6660
CancellationToken cancel = default(CancellationToken))
6761
{
6862
var options = new List<string>();
69-
if (multiHash != MultiHash.DefaultAlgorithmName ||
70-
contentType != Cid.DefaultContentType ||
71-
encoding != MultiBase.DefaultAlgorithmName)
72-
{
73-
options.Add($"mhtype={multiHash}");
74-
options.Add($"format={contentType}");
75-
options.Add($"cid-base={encoding}");
63+
if (multiHash != MultiHash.DefaultAlgorithmName ||
64+
contentType != Cid.DefaultContentType ||
65+
encoding != MultiBase.DefaultAlgorithmName)
66+
{
67+
options.Add($"mhtype={multiHash}");
68+
options.Add($"format={contentType}");
69+
options.Add($"cid-base={encoding}");
7670
}
77-
var json = await ipfs.UploadAsync("block/put", cancel, data, null, options.ToArray());
78-
var info = JObject.Parse(json);
71+
var json = await ipfs.UploadAsync("block/put", cancel, data, null, options.ToArray());
72+
var info = JObject.Parse(json);
7973
Cid cid = (string)info["Key"];
8074

81-
if (pin)
82-
{
83-
await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
75+
if (pin)
76+
{
77+
await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
8478
}
8579

8680
return cid;
@@ -89,7 +83,7 @@ public async Task<Cid> PutAsync(
8983
public async Task<IDataBlock> StatAsync(Cid id, CancellationToken cancel = default(CancellationToken))
9084
{
9185
var json = await ipfs.DoCommandAsync("block/stat", cancel, id);
92-
var info = JObject.Parse(json);
86+
var info = JObject.Parse(json);
9387
return new Block
9488
{
9589
Size = (long)info["Size"],
@@ -107,8 +101,8 @@ public async Task<Cid> PutAsync(
107101
if (error != null)
108102
throw new HttpRequestException(error);
109103
return (Cid)(string)result["Hash"];
110-
}
111-
104+
}
105+
112106
}
113107

114108
}

src/IpfsHttpClient.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<PackageReleaseNotes>
4444
--- 0.2.0 ---
4545
[Breaking]
46-
Inherited breaking changes from IpfsShipyard.Ipfs.Core 0.2.0.
46+
Inherited breaking changes from IpfsShipyard.Ipfs.Core 0.2.0 and 0.3.0.
4747
IDataBlock.DataStream was removed. This pattern encouraged async calls behind synchronous property getters, which is a bad practice and can cause deadlocks. Call the async methods directly on the API instead.
4848
The obsolete IFileSystemApi.ListFileAsync was removed due to prior deprecation and removal in Kubo 0.26.0. Use IFileSystemApi.ListAsync and MfsApi.StatAsync instead. See https://github.com/ipfs/kubo/issues/7493#issuecomment-2016563729.
4949

@@ -57,7 +57,7 @@ Added missing IFileSystemApi.ListAsync. Doesn't fully replace the removed IFileS
5757
</ItemGroup>
5858

5959
<ItemGroup>
60-
<PackageReference Include="IpfsShipyard.Ipfs.Core" Version="0.2.0" />
60+
<PackageReference Include="IpfsShipyard.Ipfs.Core" Version="0.3.0" />
6161
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
6262
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
6363
<PackageReference Include="Multiformats.Base" Version="2.0.2" />

test/BlockTest.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,5 @@ public void DataBytes()
1717
CollectionAssert.AreEqual(someBytes, block.DataBytes);
1818
}
1919

20-
[TestMethod]
21-
public void DataStream()
22-
{
23-
var block = new Block
24-
{
25-
DataBytes = someBytes
26-
};
27-
var stream = block.DataStream;
28-
Assert.AreEqual(1, stream.ReadByte());
29-
Assert.AreEqual(2, stream.ReadByte());
30-
Assert.AreEqual(3, stream.ReadByte());
31-
Assert.AreEqual(-1, stream.ReadByte(), "at eof");
32-
}
33-
3420
}
3521
}

test/CoreApi/BlockApiTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ public class BlockApiTest
1616
private byte[] blob = Encoding.UTF8.GetBytes("blorb");
1717

1818
[TestMethod]
19-
public void Put_Bytes()
19+
public async Task Put_Bytes()
2020
{
21-
var cid = ipfs.Block.PutAsync(blob).Result;
21+
var cid = await ipfs.Block.PutAsync(blob);
2222
Assert.AreEqual(id, (string)cid);
2323

24-
var data = ipfs.Block.GetAsync(cid).Result;
24+
var data = await ipfs.Block.GetAsync(cid);
2525
Assert.AreEqual(blob.Length, data.Size);
26-
CollectionAssert.AreEqual(blob, data.DataBytes);
26+
27+
var stream = await ipfs.FileSystem.ReadFileAsync(cid);
28+
var
29+
CollectionAssert.AreEqual(blob, );
2730
}
2831

2932
[TestMethod]

0 commit comments

Comments
 (0)