Skip to content
This repository has been archived by the owner. It is now read-only.

Go error when reading BTFS #2

Closed
zillerium opened this issue Aug 27, 2019 · 1 comment
Closed

Go error when reading BTFS #2

zillerium opened this issue Aug 27, 2019 · 1 comment

Comments

@zillerium
Copy link

zillerium commented Aug 27, 2019

I have a file in BTFS but when I try accessing via Go and just get headers and Nil. Code -

  //QmXEQPcQsPfGfFoannQG9jiH84P1BxwVAJ5sLapZDZfvWp
   sh := shell.NewShell("localhost:5001")

   for _, elem := range indArray {
         fmt.Printf("hash code  %s ", elem.Hash)
         cid, err := sh.Cat(elem.Hash)
         if err!=nil {
             fmt.Printf("\nerror: %s ", err)
         }

Output -

&{%!s(*http.Response=&{200 OK 200 HTTP/1.1 1 1 map[Access-Control-Expose-Headers:[X-Stream-Output, X-Chunked-Output, X-Content-Length] Vary:[Origin] Date:[Tue, 27 Aug 2019 07:30:00 GMT] X-Content-Length:[15355] X-Stream-Output:[1] Access-Control-Allow-Headers:[X-Stream-Output, X-Chunked-Output, X-Content-Length] Content-Type:[text/plain] Server:[go-ipfs/0.1.0]] 0xc420066e00 -1 [chunked] true false map[X-Stream-Error:[]] 0xc420276400 })}

There is a nil at the end of the output. The file is in BTFS and I have checked at the CLI. Is Go supported? I am using -
shell "github.com/ipfs/go-ipfs-api"
and
BTFS is running -

btfs daemon
Initializing daemon...
go-btfs version: 0.1.0-703320c84
Repo version: 7
System version: amd64/linux
Golang version: go1.12.4
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/172.31.25.22/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/54.92.219.108/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

@zillerium
Copy link
Author

zillerium commented Aug 27, 2019

args := ctx.Args()
if len(args) != 1 {
	utils.Fatalf(`Usage: xcare ipfs cat <file hash>`)
}

hash := args[0]

s := shell.NewShell(shellUrl)

rc, err := s.Cat(fmt.Sprintf("/ipfs/%s", hash))

if err != nil{
	return err
}

buf := new(bytes.Buffer)
buf.ReadFrom(rc)
fileBytes := buf.String()

fmt.Printf("%+v", fileBytes)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant