Comments (5)
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.
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.
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.
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.
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)
- Consolidating supported TargetFrameworks to netstandard2.0 HOT 1
- Migrate to modern CI
- Set up publishing of nuget packages HOT 1
- Move to Multiformats wherever possible HOT 1
- Publishing of nuget packages HOT 1
- Welcome to the Shipyard
- Set up .editorconfig and clean up code HOT 2
- Add support for Kubo MFS HOT 1
- Mass-mark deprecated APIs with [Obsolete] HOT 1
- "The IPFS network protocol 'quic-v1' is unknown."
- Let's go for a multi-project layout rather than splitting code HOT 10
- Add strong name to Ipfs.Core
- Enable nullable globally, fix issues and set to error
- Use central package management to ensure package version consistency HOT 1
- MultiHash support for libp2p-key, PeerId as base32 Cidv1 HOT 1
- API doesn't support working with Filestore
- `dag put` API doesn't serialize Cid properties into dag links
- Uses outdated crypto library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from net-ipfs-core.