Giter Club home page Giter Club logo

Comments (5)

Arlodotexe avatar Arlodotexe commented on July 17, 2024

If you need to start using IPFS in your apps today, I would recommend using the downloader and bootstrapper in the OwlCore.Kubo library until a WASI implementation of IPFS is available.

Bringing net-ipfs-engine up to par with Kubo would take an extraordinary amount of time and effort that we (the community) aren't able to provide right now.


As for wrapping in UnixFS objects, it looks like under both Go and JS, they've created separate packages for this:

Because interacting with UnixFS is an implementation detail rather than an API or model, code for this would be in net-ipfs-engine, instead of net-ipfs-core or net-ipfs-http-client.

We don't have a package for this, but you might be able to borrow code from here to build what you need without running an IPFS daemon.

from net-ipfs-core.

Arlodotexe avatar Arlodotexe commented on July 17, 2024

The easy way to generate a Multihash/Cid from a byte array:

var multihash = MultiHash.ComputeHash(bytes);

This type has an implicit conversion between MultiHash and Cid, so simply use one in place of the other:

// Create multihash from byte array
var multihash = MultiHash.ComputeHash(bytes);

// Implicit cast to Cid
MethodThatNeedsCID(multihash);

void MethodThatNeedsCID(Cid contentId)
{
}

from net-ipfs-core.

jacob-jarick avatar jacob-jarick commented on July 17, 2024

I have tried casting the output of MultiHash.ComputeHash(bytes) to Cid, I get the same result as if I didnt cast it.

  string test1 = "hello world";
  var bytes = Encoding.ASCII.GetBytes(test1);

  var options = new AddFileOptions { OnlyHash = true };
  var fsn = await ipfs.FileSystem.AddTextAsync(test1, options);
  Console.WriteLine("'" + test1 + "' ipfs.FileSystem.AddTextAsync = " + (string)fsn.Id);

  Cid cid = (Cid) MultiHash.ComputeHash(bytes);
  Console.WriteLine("'" + test1 + "MultiHash.ComputeHash casted to Cid = " + cid.ToString());

  var multihash = MultiHash.ComputeHash(bytes);
  Console.WriteLine("'" + test1 + "' MultiHash.ComputeHash = " + multihash.ToString());

output:

'hello world' ipfs.FileSystem.AddTextAsync = Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD
'hello world' MultiHash.ComputeHash casted to Cid = QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4
'hello world' MultiHash.ComputeHash = QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4

the ipfs.FileSystem.AddTextAsync output is as expected, it matches what the desktop IPFS client shows for a textfile with the contents "hello world"

from net-ipfs-core.

Arlodotexe avatar Arlodotexe commented on July 17, 2024

I have tried casting the output of MultiHash.ComputeHash(bytes) to Cid, I get the same result as if I didnt cast it.

That's because Console.WriteLine is implicitly converting it to a string. Calling .ToString(), casting to a string, or concatenating with a string are expected to have the same output.

A Cid and a MultiHash will output the same value when converted to a string.


the ipfs.FileSystem.AddTextAsync output is as expected, it matches what the desktop IPFS client shows for a textfile with the contents "hello world"

That's odd 🤔. Maybe one of the default settings in Kubo has changed since this was last updated by @richardschneider. I'll get back to you on this one.

from net-ipfs-core.

Arlodotexe avatar Arlodotexe commented on July 17, 2024

I imagine this is because extremely small content can be inlined into a single UnixFS block, where larger content requires splitting the content into multiple blocks.

The way each content is split into blocks, and in turn the way that the CID is generated, is dictated entirely by the IPFS implementation being used. This is why I suggested to borrow code from here to build what you need without running an IPFS daemon.

There's no guarantee the CID will match what you get with Kubo/Iroh/Helia, unless the UnixFS implementation used to chunk content also matches.

That in mind, I would recommend matching (or just using) the implementation you've chosen to create the CID you're after.
If you're using Kubo, a good option is to use the bootstrapper in the OwlCore.Kubo library until a WASI implementation of IPFS is available to us.

from net-ipfs-core.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.