How to calculate file/directory hash?

@alexander Thanks! :slight_smile:

1 Like

Hi, I am working on an open source IoT project written in python, and will be happy to share it when the solution comes. Please keep this going!

2 Likes

Did you happen to find an answer this this? I’m just stumbling across the same problem, and haven’t found a solution yet.

1 Like

I’m curious if anyone has generated the same hashes as ipfs add in Go without running a daemon.

1 Like

hi,

you can see that https://github.com/multiformats/multihash

regards

1 Like

Hey @josselinchevalay, correct me if I’m wrong, but I was thinking multihash isn’t enough. To get the output from ipfs add you need to chunk the file, build a dag and hash it. A wrapper is added around files as well I believe.

Here’s the code for add.

1 Like

hi,

yep you have reason

1 Like

Hi all, I solved this a while ago with go-ipfs so I’d figure I will share it here:

	dstore := datastore.NewMapDatastore()
	bstore := blockstore.NewBlockstore(dstore)
	bserv := blockservice.New(bstore, offline.Exchange(bstore))
	dserv := merkledag.NewDAGService(bserv)
	n := &core.IpfsNode{
		Blockstore: blockstore.NewGCBlockstore(bstore, blockstore.NewGCLocker()),
		Pinning:    pin.NewPinner(dstore, dserv, dserv),
		DAG:        dserv,
	}
	r, err := os.Open(filename)
	if err != nil {
		return err
	}
	// key is the hash from ipfs add.
	key, err := coreunix.Add(n, r)
	if err != nil {
		return err
	}
3 Likes

Just curious…

Is there a way to differentiate or recognize the folder from a file by the encoding done using Multihash?

@flyingzumwalt or anyone can probably help me answer that question.

TIA!

1 Like

I would appreciate if someone test my little example project producing CID out of the raw data:

We have discussed it with the guys here, and it seems working.

1 Like