diff --git a/src/Block.cs b/src/Block.cs
index a4cec47..84f804e 100644
--- a/src/Block.cs
+++ b/src/Block.cs
@@ -1,5 +1,4 @@
-using System.IO;
-using System.Runtime.Serialization;
+using System.Runtime.Serialization;
namespace Ipfs.Http
{
@@ -7,43 +6,18 @@ namespace Ipfs.Http
[DataContract]
public class Block : IDataBlock
{
- long? size;
-
- ///
- [DataMember]
- public Cid Id { get; set; }
+ ///
+ /// The data of the block.
+ ///
+ public byte[] DataBytes { get; set; }
///
[DataMember]
- public byte[] DataBytes { get; set; }
+ public required Cid Id { get; set; }
- ///
- public Stream DataStream
- {
- get
- {
- return new MemoryStream(DataBytes, false);
- }
- }
-
///
[DataMember]
- public long Size
- {
- get
- {
- if (size.HasValue)
- {
- return size.Value;
- }
- return DataBytes.Length;
- }
- set
- {
- size = value;
- }
- }
-
+ public required long Size { get; set; }
}
}
diff --git a/src/CoreApi/BitswapApi.cs b/src/CoreApi/BitswapApi.cs
index dc3af6c..9ee74f9 100644
--- a/src/CoreApi/BitswapApi.cs
+++ b/src/CoreApi/BitswapApi.cs
@@ -16,11 +16,6 @@ internal BitswapApi(IpfsClient ipfs)
this.ipfs = ipfs;
}
- public Task GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
- {
- return ipfs.Block.GetAsync(id, cancel);
- }
-
public async Task> WantsAsync(MultiHash peer = null, CancellationToken cancel = default(CancellationToken))
{
var json = await ipfs.DoCommandAsync("bitswap/wantlist", cancel, peer?.ToString());
@@ -35,11 +30,6 @@ internal BitswapApi(IpfsClient ipfs)
return Cid.Decode(obj["/"].ToString());
});
}
-
- public async Task UnwantAsync(Cid id, CancellationToken cancel = default(CancellationToken))
- {
- await ipfs.DoCommandAsync("bitswap/unwant", cancel, id);
- }
public async Task LedgerAsync(Peer peer, CancellationToken cancel = default(CancellationToken))
{
diff --git a/src/CoreApi/BlockApi.cs b/src/CoreApi/BlockApi.cs
index 7b1eb0b..7013eea 100644
--- a/src/CoreApi/BlockApi.cs
+++ b/src/CoreApi/BlockApi.cs
@@ -1,11 +1,11 @@
-using Ipfs.CoreApi;
+using Ipfs.CoreApi;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
-using System.IO;
+using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
-
+
namespace Ipfs.Http
{
class BlockApi : IBlockApi
@@ -17,18 +17,13 @@ internal BlockApi(IpfsClient ipfs)
this.ipfs = ipfs;
}
- public async Task GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
+ public async Task GetAsync(Cid id, CancellationToken cancel = default(CancellationToken))
{
- var data = await ipfs.DownloadBytesAsync("block/get", cancel, id);
- return new Block
- {
- DataBytes = data,
- Id = id
- };
+ return await ipfs.DownloadBytesAsync("block/get", cancel, id);
}
public async Task PutAsync(
- byte[] data,
+ byte[] data,
string contentType = Cid.DefaultContentType,
string multiHash = MultiHash.DefaultAlgorithmName,
string encoding = MultiBase.DefaultAlgorithmName,
@@ -36,28 +31,28 @@ public async Task PutAsync(
CancellationToken cancel = default(CancellationToken))
{
var options = new List();
- if (multiHash != MultiHash.DefaultAlgorithmName ||
- contentType != Cid.DefaultContentType ||
- encoding != MultiBase.DefaultAlgorithmName)
- {
- options.Add($"mhtype={multiHash}");
- options.Add($"format={contentType}");
- options.Add($"cid-base={encoding}");
+ if (multiHash != MultiHash.DefaultAlgorithmName ||
+ contentType != Cid.DefaultContentType ||
+ encoding != MultiBase.DefaultAlgorithmName)
+ {
+ options.Add($"mhtype={multiHash}");
+ options.Add($"format={contentType}");
+ options.Add($"cid-base={encoding}");
}
- var json = await ipfs.UploadAsync("block/put", cancel, data, options.ToArray());
- var info = JObject.Parse(json);
+ var json = await ipfs.UploadAsync("block/put", cancel, data, options.ToArray());
+ var info = JObject.Parse(json);
Cid cid = (string)info["Key"];
- if (pin)
- {
- await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
+ if (pin)
+ {
+ await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
}
return cid;
}
public async Task PutAsync(
- Stream data,
+ Stream data,
string contentType = Cid.DefaultContentType,
string multiHash = MultiHash.DefaultAlgorithmName,
string encoding = MultiBase.DefaultAlgorithmName,
@@ -65,21 +60,21 @@ public async Task PutAsync(
CancellationToken cancel = default(CancellationToken))
{
var options = new List();
- if (multiHash != MultiHash.DefaultAlgorithmName ||
- contentType != Cid.DefaultContentType ||
- encoding != MultiBase.DefaultAlgorithmName)
- {
- options.Add($"mhtype={multiHash}");
- options.Add($"format={contentType}");
- options.Add($"cid-base={encoding}");
+ if (multiHash != MultiHash.DefaultAlgorithmName ||
+ contentType != Cid.DefaultContentType ||
+ encoding != MultiBase.DefaultAlgorithmName)
+ {
+ options.Add($"mhtype={multiHash}");
+ options.Add($"format={contentType}");
+ options.Add($"cid-base={encoding}");
}
- var json = await ipfs.UploadAsync("block/put", cancel, data, null, options.ToArray());
- var info = JObject.Parse(json);
+ var json = await ipfs.UploadAsync("block/put", cancel, data, null, options.ToArray());
+ var info = JObject.Parse(json);
Cid cid = (string)info["Key"];
- if (pin)
- {
- await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
+ if (pin)
+ {
+ await ipfs.Pin.AddAsync(cid, recursive: false, cancel: cancel);
}
return cid;
@@ -88,7 +83,7 @@ public async Task PutAsync(
public async Task StatAsync(Cid id, CancellationToken cancel = default(CancellationToken))
{
var json = await ipfs.DoCommandAsync("block/stat", cancel, id);
- var info = JObject.Parse(json);
+ var info = JObject.Parse(json);
return new Block
{
Size = (long)info["Size"],
@@ -106,8 +101,8 @@ public async Task PutAsync(
if (error != null)
throw new HttpRequestException(error);
return (Cid)(string)result["Hash"];
- }
-
+ }
+
}
}
diff --git a/src/CoreApi/FileSystemApi.cs b/src/CoreApi/FileSystemApi.cs
index b94e702..227b636 100644
--- a/src/CoreApi/FileSystemApi.cs
+++ b/src/CoreApi/FileSystemApi.cs
@@ -22,7 +22,7 @@ internal FileSystemApi(IpfsClient ipfs)
this.emptyFolder = new Lazy(() => ipfs.Object.NewDirectoryAsync().Result);
}
- public async Task AddFileAsync(string path, AddFileOptions options = null, CancellationToken cancel = default(CancellationToken))
+ public async Task AddFileAsync(string path, AddFileOptions options = null, CancellationToken cancel = default)
{
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
@@ -31,15 +31,16 @@ internal FileSystemApi(IpfsClient ipfs)
}
}
- public Task AddTextAsync(string text, AddFileOptions options = null, CancellationToken cancel = default(CancellationToken))
+ public Task AddTextAsync(string text, AddFileOptions options = null, CancellationToken cancel = default)
{
return AddAsync(new MemoryStream(Encoding.UTF8.GetBytes(text), false), "", options, cancel);
}
- public async Task AddAsync(Stream stream, string name = "", AddFileOptions options = null, CancellationToken cancel = default(CancellationToken))
+ public async Task AddAsync(Stream stream, string name = "", AddFileOptions options = null, CancellationToken cancel = default)
{
if (options == null)
options = new AddFileOptions();
+
var opts = new List();
if (!options.Pin)
opts.Add("pin=false");
@@ -59,6 +60,7 @@ internal FileSystemApi(IpfsClient ipfs)
opts.Add($"cid-base=${options.Encoding}");
if (!string.IsNullOrWhiteSpace(options.ProtectionKey))
opts.Add($"protect={options.ProtectionKey}");
+
opts.Add($"chunker=size-{options.ChunkSize}");
var response = await ipfs.Upload2Async("add", cancel, stream, name, opts.ToArray());
@@ -92,7 +94,6 @@ internal FileSystemApi(IpfsClient ipfs)
Size = long.Parse((string)r["Size"]),
IsDirectory = false,
Name = name,
- IpfsClient = ipfs
};
}
}
@@ -102,7 +103,7 @@ internal FileSystemApi(IpfsClient ipfs)
return fsn;
}
- public async Task AddDirectoryAsync(string path, bool recursive = true, AddFileOptions options = null, CancellationToken cancel = default(CancellationToken))
+ public async Task AddDirectoryAsync(string path, bool recursive = true, AddFileOptions options = null, CancellationToken cancel = default)
{
if (options == null)
options = new AddFileOptions();
@@ -145,7 +146,6 @@ internal FileSystemApi(IpfsClient ipfs)
Links = links,
IsDirectory = true,
Size = directory.Size,
- IpfsClient = ipfs
};
}
@@ -163,7 +163,7 @@ internal FileSystemApi(IpfsClient ipfs)
///
/// The contents of the as a .
///
- public async Task ReadAllTextAsync(string path, CancellationToken cancel = default(CancellationToken))
+ public async Task ReadAllTextAsync(string path, CancellationToken cancel = default)
{
using (var data = await ReadFileAsync(path, cancel))
using (var text = new StreamReader(data))
@@ -186,12 +186,12 @@ internal FileSystemApi(IpfsClient ipfs)
///
/// A to the file contents.
///
- public Task ReadFileAsync(string path, CancellationToken cancel = default(CancellationToken))
+ public Task ReadFileAsync(string path, CancellationToken cancel = default)
{
return ipfs.PostDownloadAsync("cat", cancel, path);
}
- public Task ReadFileAsync(string path, long offset, long length = 0, CancellationToken cancel = default(CancellationToken))
+ public Task ReadFileAsync(string path, long offset, long length = 0, CancellationToken cancel = default)
{
// https://github.com/ipfs/go-ipfs/issues/5380
if (offset > int.MaxValue)
@@ -206,33 +206,36 @@ internal FileSystemApi(IpfsClient ipfs)
$"length={length}");
}
+ ///
+ public Task ListFileAsync(string path, CancellationToken cancel = default)
+ {
+ return ListAsync(path, cancel);
+ }
+
///
- /// Get information about the file or directory.
+ /// Get information about the directory.
///
///
- /// A path to an existing file or directory, such as "QmXarR6rgkQ2fDSHjSY5nM2kuCXKYGViky5nohtwgF65Ec/about"
- /// or "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"
+ /// A path to an existing directory, such as "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"
///
///
- /// Is used to stop the task. When cancelled, the is raised.
+ /// Is used to stop the task. When cancelled, the is raised.
///
///
- public async Task ListFileAsync(string path, CancellationToken cancel = default(CancellationToken))
+ public async Task ListAsync(string path, CancellationToken cancel = default)
{
- var json = await ipfs.DoCommandAsync("file/ls", cancel, path);
+ var json = await ipfs.DoCommandAsync("ls", cancel, path);
var r = JObject.Parse(json);
- var hash = (string)r["Arguments"][path];
- var o = (JObject)r["Objects"][hash];
+ var o = (JObject)r["Objects"]?[0];
+
var node = new FileSystemNode()
{
Id = (string)o["Hash"],
- Size = (long)o["Size"],
- IsDirectory = (string)o["Type"] == "Directory",
- Links = new FileSystemLink[0],
- IpfsClient = ipfs
+ IsDirectory = true,
+ Links = Array.Empty(),
};
- var links = o["Links"] as JArray;
- if (links != null)
+
+ if (o["Links"] is JArray links)
{
node.Links = links
.Select(l => new FileSystemLink()
@@ -245,9 +248,9 @@ internal FileSystemApi(IpfsClient ipfs)
}
return node;
- }
-
- public Task GetAsync(string path, bool compress = false, CancellationToken cancel = default(CancellationToken))
+ }
+
+ public Task GetAsync(string path, bool compress = false, CancellationToken cancel = default)
{
return ipfs.PostDownloadAsync("get", cancel, path, $"compress={compress}");
}
diff --git a/src/CoreApi/MfsApi.cs b/src/CoreApi/MfsApi.cs
index 43aecc4..0596018 100644
--- a/src/CoreApi/MfsApi.cs
+++ b/src/CoreApi/MfsApi.cs
@@ -61,7 +61,6 @@ public async Task> ListAsync(string path, bool? U =
Id = (string)l["Hash"],
Size = (long)l["Size"],
IsDirectory = (int)l["Type"] == 1,
- IpfsClient = ipfs
})
.ToArray();
}
diff --git a/src/FileSystemNode.cs b/src/FileSystemNode.cs
index 07bd148..e1be657 100644
--- a/src/FileSystemNode.cs
+++ b/src/FileSystemNode.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using System.IO;
using System.Runtime.Serialization;
namespace Ipfs.Http
@@ -8,57 +7,13 @@ namespace Ipfs.Http
[DataContract]
public class FileSystemNode : IFileSystemNode
{
- IpfsClient ipfsClient;
- IEnumerable links;
- long? size;
- bool? isDirectory;
-
- ///
- public byte[] DataBytes
- {
- get
- {
- using (var stream = DataStream)
- {
- if (DataStream == null)
- return null;
-
- using (var data = new MemoryStream())
- {
- stream.CopyTo(data);
- return data.ToArray();
- }
- }
- }
- }
-
- ///
- public Stream DataStream
- {
- get
- {
- return IpfsClient?.FileSystem.ReadFileAsync(Id).Result;
- }
- }
-
///
[DataMember]
- public Cid Id { get; set; }
+ public required Cid Id { get; set; }
///
[DataMember]
- public IEnumerable Links
- {
- get
- {
- if (links == null) GetInfo();
- return links;
- }
- set
- {
- links = value;
- }
- }
+ public IEnumerable Links { get; set; } = [];
///
/// Size of the file contents.
@@ -68,18 +23,7 @@ public IEnumerable Links
/// of the block.
///
[DataMember]
- public long Size
- {
- get
- {
- if (!size.HasValue) GetInfo();
- return size.Value;
- }
- set
- {
- size = value;
- }
- }
+ public long Size { get; set; }
///
/// Determines if the link is a directory (folder).
@@ -89,18 +33,7 @@ public long Size
/// the link is some type of a file.
///
[DataMember]
- public bool IsDirectory
- {
- get
- {
- if (!isDirectory.HasValue) GetInfo();
- return isDirectory.Value;
- }
- set
- {
- isDirectory = value;
- }
- }
+ public bool IsDirectory { get; set; }
///
/// The file name of the IPFS node.
@@ -119,39 +52,5 @@ public IFileSystemLink ToLink(string name = "")
};
return link;
}
-
- ///
- /// The client to IPFS.
- ///
- ///
- /// Used to fetch additional information on the node.
- ///
- public IpfsClient IpfsClient
- {
- get
- {
- if (ipfsClient == null)
- {
- lock (this)
- {
- ipfsClient = new IpfsClient();
- }
- }
- return ipfsClient;
- }
- set
- {
- ipfsClient = value;
- }
- }
-
- void GetInfo()
- {
- var node = IpfsClient.FileSystem.ListFileAsync(Id).Result;
- this.IsDirectory = node.IsDirectory;
- this.Links = node.Links;
- this.Size = node.Size;
- }
-
}
}
diff --git a/src/IpfsHttpClient.csproj b/src/IpfsHttpClient.csproj
index 6cd4566..1547d5e 100644
--- a/src/IpfsHttpClient.csproj
+++ b/src/IpfsHttpClient.csproj
@@ -9,8 +9,9 @@
true
- 0.1.0
+ 0.2.0
$(Version)
+ 12.0
IpfsShipyard.Ipfs.Http.Client
@@ -39,6 +40,16 @@
true
snupkg
.pdb;$(AllowedOutputExtensionsInPackageBuildOutputFolder)
+
+--- 0.2.0 ---
+[Breaking]
+Inherited breaking changes from IpfsShipyard.Ipfs.Core 0.2.0 and 0.3.0.
+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.
+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.
+
+[New]
+Added missing IFileSystemApi.ListAsync. Doesn't fully replace the removed IFileSystemApi.ListFileAsync, but is a step in the right direction. See https://github.com/ipfs/kubo/issues/7493#issuecomment-2016563729.
+
@@ -46,10 +57,14 @@
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/src/MerkleNode.cs b/src/MerkleNode.cs
index 33332e1..824a093 100644
--- a/src/MerkleNode.cs
+++ b/src/MerkleNode.cs
@@ -143,25 +143,6 @@ public IEnumerable Links
}
}
- ///
- [DataMember]
- public byte[] DataBytes
- {
- get
- {
- return IpfsClient.Block.GetAsync(Id).Result.DataBytes;
- }
- }
-
- ///
- public Stream DataStream
- {
- get
- {
- return IpfsClient.Block.GetAsync(Id).Result.DataStream;
- }
- }
-
///
public IMerkleLink ToLink(string name = null)
{
diff --git a/test/BlockTest.cs b/test/BlockTest.cs
deleted file mode 100644
index 8db34c8..0000000
--- a/test/BlockTest.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Ipfs.Http
-{
- [TestClass]
- public class BlockTest
- {
- private byte[] someBytes = new byte[] { 1, 2, 3 };
-
- [TestMethod]
- public void DataBytes()
- {
- var block = new Block
- {
- DataBytes = someBytes
- };
- CollectionAssert.AreEqual(someBytes, block.DataBytes);
- }
-
- [TestMethod]
- public void DataStream()
- {
- var block = new Block
- {
- DataBytes = someBytes
- };
- var stream = block.DataStream;
- Assert.AreEqual(1, stream.ReadByte());
- Assert.AreEqual(2, stream.ReadByte());
- Assert.AreEqual(3, stream.ReadByte());
- Assert.AreEqual(-1, stream.ReadByte(), "at eof");
- }
-
- }
-}
diff --git a/test/CoreApi/BitswapApiTest.cs b/test/CoreApi/BitswapApiTest.cs
index 1561aaa..77dbe60 100644
--- a/test/CoreApi/BitswapApiTest.cs
+++ b/test/CoreApi/BitswapApiTest.cs
@@ -1,9 +1,4 @@
-using Ipfs.Http;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.IO;
-using System.Linq;
-using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
namespace Ipfs.Http
@@ -13,56 +8,6 @@ public class BitswapApiTest
{
private IpfsClient ipfs = TestFixture.Ipfs;
- [TestMethod]
- public async Task Wants()
- {
- var block = new DagNode(Encoding.UTF8.GetBytes("BitswapApiTest unknown block"));
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- Task.Run(() => ipfs.Bitswap.GetAsync(block.Id).Wait());
-
- var endTime = DateTime.Now.AddSeconds(10);
- while (DateTime.Now < endTime)
- {
- await Task.Delay(100);
- var wants = await ipfs.Bitswap.WantsAsync();
- if (wants.Contains(block.Id))
- return;
- }
- Assert.Fail("wanted block is missing");
- }
-
- [TestMethod]
- [Ignore("https://github.com/ipfs/go-ipfs/issues/5295")]
- public async Task Unwant()
- {
- var block = new DagNode(Encoding.UTF8.GetBytes("BitswapApiTest unknown block 2"));
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- Task.Run(() => ipfs.Bitswap.GetAsync(block.Id).Wait());
-
- var endTime = DateTime.Now.AddSeconds(10);
- while (true)
- {
- if (DateTime.Now > endTime)
- Assert.Fail("wanted block is missing");
- await Task.Delay(100);
- var wants = await ipfs.Bitswap.WantsAsync();
- if (wants.Contains(block.Id))
- break;
- }
-
- await ipfs.Bitswap.UnwantAsync(block.Id);
- endTime = DateTime.Now.AddSeconds(10);
- while (true)
- {
- if (DateTime.Now > endTime)
- Assert.Fail("unwanted block is present");
- await Task.Delay(100);
- var wants = await ipfs.Bitswap.WantsAsync();
- if (!wants.Contains(block.Id))
- break;
- }
- }
-
[TestMethod]
public async Task Ledger()
{
diff --git a/test/CoreApi/BlockApiTest.cs b/test/CoreApi/BlockApiTest.cs
index 5f5c232..357f60d 100644
--- a/test/CoreApi/BlockApiTest.cs
+++ b/test/CoreApi/BlockApiTest.cs
@@ -16,14 +16,20 @@ public class BlockApiTest
private byte[] blob = Encoding.UTF8.GetBytes("blorb");
[TestMethod]
- public void Put_Bytes()
+ public async Task Put_Bytes()
{
- var cid = ipfs.Block.PutAsync(blob).Result;
+ var cid = await ipfs.Block.PutAsync(blob);
Assert.AreEqual(id, (string)cid);
- var data = ipfs.Block.GetAsync(cid).Result;
- Assert.AreEqual(blob.Length, data.Size);
- CollectionAssert.AreEqual(blob, data.DataBytes);
+ var data = await ipfs.Block.GetAsync(cid);
+ Assert.AreEqual(blob.Length, data.Length);
+
+ var stream = await ipfs.FileSystem.ReadFileAsync(cid);
+ using var memoryStream = new MemoryStream();
+ await stream.CopyToAsync(memoryStream);
+ var bytes = memoryStream.ToArray();
+
+ CollectionAssert.AreEqual(blob, bytes);
}
[TestMethod]
@@ -33,8 +39,8 @@ public void Put_Bytes_ContentType()
Assert.AreEqual("bafkreiaxnnnb7qz2focittuqq3ya25q7rcv3bqynnczfzako47346wosmu", (string)cid);
var data = ipfs.Block.GetAsync(cid).Result;
- Assert.AreEqual(blob.Length, data.Size);
- CollectionAssert.AreEqual(blob, data.DataBytes);
+ Assert.AreEqual(blob.Length, data.Length);
+ CollectionAssert.AreEqual(blob, data);
}
[TestMethod]
@@ -44,8 +50,8 @@ public void Put_Bytes_Hash()
Assert.AreEqual("bafkrgqelljziv4qfg5mefz36m2y3h6voaralnw6lwb4f53xcnrf4mlsykkn7vt6eno547tw5ygcz62kxrle45wnbmpbofo5tvu57jvuaf7k7e", (string)cid);
var data = ipfs.Block.GetAsync(cid).Result;
- Assert.AreEqual(blob.Length, data.Size);
- CollectionAssert.AreEqual(blob, data.DataBytes);
+ Assert.AreEqual(blob.Length, data.Length);
+ CollectionAssert.AreEqual(blob, data);
}
[TestMethod]
@@ -69,8 +75,8 @@ public void Put_Stream()
Assert.AreEqual(id, (string)cid);
var data = ipfs.Block.GetAsync(cid).Result;
- Assert.AreEqual(blob.Length, data.Size);
- CollectionAssert.AreEqual(blob, data.DataBytes);
+ Assert.AreEqual(blob.Length, data.Length);
+ CollectionAssert.AreEqual(blob, data);
}
[TestMethod]
@@ -80,8 +86,8 @@ public void Put_Stream_ContentType()
Assert.AreEqual("bafkreiaxnnnb7qz2focittuqq3ya25q7rcv3bqynnczfzako47346wosmu", (string)cid);
var data = ipfs.Block.GetAsync(cid).Result;
- Assert.AreEqual(blob.Length, data.Size);
- CollectionAssert.AreEqual(blob, data.DataBytes);
+ Assert.AreEqual(blob.Length, data.Length);
+ CollectionAssert.AreEqual(blob, data);
}
[TestMethod]
@@ -91,8 +97,8 @@ public void Put_Stream_Hash()
Assert.AreEqual("bafkrgqelljziv4qfg5mefz36m2y3h6voaralnw6lwb4f53xcnrf4mlsykkn7vt6eno547tw5ygcz62kxrle45wnbmpbofo5tvu57jvuaf7k7e", (string)cid);
var data = ipfs.Block.GetAsync(cid).Result;
- Assert.AreEqual(blob.Length, data.Size);
- CollectionAssert.AreEqual(blob, data.DataBytes);
+ Assert.AreEqual(blob.Length, data.Length);
+ CollectionAssert.AreEqual(blob, data);
}
[TestMethod]
@@ -114,10 +120,9 @@ public void Get()
{
var _ = ipfs.Block.PutAsync(blob).Result;
var block = ipfs.Block.GetAsync(id).Result;
- Assert.AreEqual(id, (string)block.Id);
- CollectionAssert.AreEqual(blob, block.DataBytes);
+ CollectionAssert.AreEqual(blob, block);
+
var blob1 = new byte[blob.Length];
- block.DataStream.Read(blob1, 0, blob1.Length);
CollectionAssert.AreEqual(blob, blob1);
}
diff --git a/test/CoreApi/FileSystemApiTest.cs b/test/CoreApi/FileSystemApiTest.cs
index 2e5ce65..6df79cb 100644
--- a/test/CoreApi/FileSystemApiTest.cs
+++ b/test/CoreApi/FileSystemApiTest.cs
@@ -236,7 +236,6 @@ public void AddDirectoryRecursive()
var xfiles = new FileSystemNode
{
Id = files[2].Id,
- IpfsClient = ipfs,
}.Links.ToArray();
Assert.AreEqual(2, xfiles.Length);
Assert.AreEqual("x.txt", xfiles[0].Name);
@@ -245,7 +244,6 @@ public void AddDirectoryRecursive()
var yfiles = new FileSystemNode
{
Id = xfiles[1].Id,
- IpfsClient = ipfs
}.Links.ToArray();
Assert.AreEqual(1, yfiles.Length);
Assert.AreEqual("y.txt", yfiles[0].Name);
@@ -253,9 +251,8 @@ public void AddDirectoryRecursive()
var y = new FileSystemNode
{
Id = yfiles[0].Id,
- IpfsClient = ipfs
};
- Assert.AreEqual("y", Encoding.UTF8.GetString(y.DataBytes));
+
Assert.AreEqual("y", ipfs.FileSystem.ReadAllTextAsync(dir.Id + "/x/y/y.txt").Result);
}
finally
diff --git a/test/FileSystemNodeTest.cs b/test/FileSystemNodeTest.cs
index 29a414c..7705ce7 100644
--- a/test/FileSystemNodeTest.cs
+++ b/test/FileSystemNodeTest.cs
@@ -15,7 +15,7 @@ public async Task Serialization()
var a = await ipfs.FileSystem.AddTextAsync("hello world");
Assert.AreEqual("Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD", (string)a.Id);
- var b = await ipfs.FileSystem.ListFileAsync(a.Id);
+ var b = await ipfs.FileSystem.ListAsync(a.Id);
var json = JsonConvert.SerializeObject(b);
var c = JsonConvert.DeserializeObject(json);
Assert.AreEqual(b.Id, c.Id);
diff --git a/test/MerkleNodeTest.cs b/test/MerkleNodeTest.cs
index 63d36b3..0ca4e2b 100644
--- a/test/MerkleNodeTest.cs
+++ b/test/MerkleNodeTest.cs
@@ -105,24 +105,5 @@ public void Value_Equality()
Assert.IsFalse(nullNode != null);
Assert.IsTrue(null != a0);
}
-
- [TestMethod]
- public void DataBytes()
- {
- var node = new MerkleNode(IpfsInfo);
- byte[] data = node.DataBytes;
- Assert.AreEqual(node.BlockSize, data.Length);
- }
-
- [TestMethod]
- public void DataStream()
- {
- var node = new MerkleNode(IpfsInfo);
- byte[] data = node.DataBytes;
- var streamData = new MemoryStream();
- node.DataStream.CopyTo(streamData);
- CollectionAssert.AreEqual(data, streamData.ToArray());
- }
-
}
}