Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
added ability to calculate multihashes
Browse files Browse the repository at this point in the history
will be updating dependencies in the following commit
  • Loading branch information
bonedaddy committed Aug 11, 2018
1 parent 74d7ca8 commit 961a457
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
Binary file modified Temporal
Binary file not shown.
5 changes: 4 additions & 1 deletion docs/IPFS_ISSUES.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
https://github.com/ipfs/go-ipfs/issues/2509
https://github.com/ipfs/go-ipfs/issues/2509

* Pinning happens in sequence, this can cause issues with many processings
> trying to pin one content, and upload another content
7 changes: 6 additions & 1 deletion docs/LINKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ https://github.com/ipfs/go-dnslink


IPFS Configuration Explanation:
https://github.com/ipfs/go-ipfs/blob/master/docs/config.md
https://github.com/ipfs/go-ipfs/blob/master/docs/config.


calculate ipfs hashes https://discuss.ipfs.io/t/how-to-calculate-file-directory-hash/777/48

Debugging https://github.com/ipfs/go-ipfs/blob/master/docs/debug-guide.md
36 changes: 36 additions & 0 deletions utils/multihash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package utils

import (
"os"

"github.com/ipsn/go-ipfs/core"
"github.com/ipsn/go-ipfs/core/coreunix"
"github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-blockservice"
datastore "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-datastore"
blockstore "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-ipfs-blockstore"
offline "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-ipfs-exchange-offline"
"github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-merkledag"
"github.com/ipsn/go-ipfs/pin"
)

// GenerateIpfsMultiHashForFile is used to calculate an IPFS multihash
// for a given file, without actually broadcasting it to the network
// or even adding it at all. It was graciously adopted thanks to @hinshun
// over on discuss.ipfs.io. Overtime we willallow calculating different hash types
func GenerateIpfsMultiHashForFile(fileName string) (string, error) {
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,
}
fileHandler, err := os.Open(fileName)
if err != nil {
return "", err
}

return coreunix.Add(n, fileHandler)
}
18 changes: 18 additions & 0 deletions utils/multihash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package utils_test

import (
"fmt"
"testing"

"github.com/RTradeLtd/Temporal/utils"
)

var testFile = "/tmp/test.txt"

func TestGenerateIpfsMultiHashForFile(t *testing.T) {
hash, err := utils.GenerateIpfsMultiHashForFile(testFile)
if err != nil {
t.Fatal(err)
}
fmt.Println("recovered hash is ", hash)
}

0 comments on commit 961a457

Please sign in to comment.