This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ability to calculate multihashes
will be updating dependencies in the following commit
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |