You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
793 B

  1. package data
  2. import (
  3. "os"
  4. "fmt"
  5. "bytes"
  6. "io/ioutil"
  7. shell "github.com/ipfs/go-ipfs-api"
  8. )
  9. func publish(object []byte) (string) {
  10. sh := shell.NewShell("localhost:5001")
  11. cid, err := sh.Add(bytes.NewBuffer(object))
  12. if err != nil {
  13. fmt.Fprintf(os.Stderr, "error: %s", err)
  14. os.Exit(1)
  15. }
  16. return cid
  17. }
  18. func pin(path string) {
  19. sh := shell.NewShell("localhost:5001")
  20. err := sh.Pin(path)
  21. if err != nil{
  22. fmt.Fprintf(os.Stderr, "error: %s", err)
  23. os.Exit(1)
  24. }
  25. }
  26. func retrieve(hash string) ([]byte){
  27. sh := shell.NewShell("localhost:5001")
  28. reader, err := sh.Cat(hash)
  29. if err != nil {
  30. fmt.Fprintf(os.Stderr, "error: %s", err)
  31. os.Exit(1)
  32. }
  33. content, err := ioutil.ReadAll(reader)
  34. if err != nil {
  35. fmt.Fprintf(os.Stderr, "error: %s", err)
  36. os.Exit(1)
  37. }
  38. return content
  39. }