public string GetTextFromIPFS(string cid)
 {
     using (var data = ipfs.PostDownloadAsync("cat", default, cid).GetAwaiter().GetResult())
         using (var text = new StreamReader(data))
         {
             return(text.ReadToEndAsync().GetAwaiter().GetResult());
         }
 }
Example #2
0
        public async Task <CmsFile?> ReadFile(string fileName)
        {
            //FileSystem.ReadFileAsyn does a GET, but should be a POST
            //var response = await _client.FileSystem.ReadFileAsync(fileName);
            var response = await _client.PostDownloadAsync("cat", default(CancellationToken), fileName);

            using (MemoryStream ms = new MemoryStream())
            {
                response.CopyTo(ms);
                return(new CmsFile {
                    Bytes = ms.ToArray(), ContentType = string.Empty
                });
            }
        }
        public async Task <T> RetrieveAsync <T>(Hash <T> hash, CancellationToken cancellationToken = default)
        {
            var cid = new Cid {
                ContentType = "raw", Hash = new MultiHash("sha2-256", hash.Bytes)
            };

            // NOTE: The Ipfs.Http.Client library uses a GET request for Block.GetAsync, which doesn't work since go-ipfs v0.5.
            // See https://github.com/richardschneider/net-ipfs-http-client/issues/62 for more details.
            // var block = await _ipfs.Block.GetAsync(multihash);

            var stream = await _ipfs.PostDownloadAsync("block/get", cancellationToken, cid);

            return((await JsonSerializer.DeserializeAsync <T>(stream, ApocryphSerializationOptions.JsonSerializerOptions, cancellationToken)) !);
        }