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