Skip to content

Instantly share code, notes, and snippets.

@tobowers
Created August 23, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobowers/4e505a8e0df4d8d8670aee925cfd1397 to your computer and use it in GitHub Desktop.
Save tobowers/4e505a8e0df4d8d8670aee925cfd1397 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"github.com/ipsn/go-ipfs/core"
"github.com/ipsn/go-ipfs/core/coreunix"
)
func main() {
node, err := core.NewNode(context.TODO(), &core.BuildCfg{Online: true})
if err != nil {
log.Fatalf("Failed to start IPFS node: %v", err)
}
dataa := ioutil.NopCloser(bytes.NewBufferString("testfileA"))
str, err := coreunix.Add(node, dataa)
if err != nil {
panic(err)
}
fmt.Printf("str: %s\n", str)
reader, err := coreunix.Cat(context.TODO(), node, str)
if err != nil {
log.Fatalf("Failed: %v", err)
}
blob, err := ioutil.ReadAll(reader)
if err != nil {
log.Fatalf("Failed to retrieve: %v", err)
}
fmt.Println(string(blob))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment