forked from ipfs/go-ipfs-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unixfs.go
50 lines (41 loc) · 835 Bytes
/
unixfs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package shell
import (
"context"
"encoding/json"
"fmt"
)
type UnixLsObject struct {
Hash string
Size uint64
Type string
Links []*UnixLsLink
}
type UnixLsLink struct {
Hash string
Name string
Size uint64
Type string
}
type lsOutput struct {
Objects map[string]*UnixLsObject
}
// FileList entries at the given path using the UnixFS commands
func (s *Shell) FileList(path string) (*UnixLsObject, error) {
resp, err := s.newRequest(context.Background(), "file/ls", path).Send(s.httpcli)
if err != nil {
return nil, err
}
defer resp.Close()
if resp.Error != nil {
return nil, resp.Error
}
var out lsOutput
err = json.NewDecoder(resp.Output).Decode(&out)
if err != nil {
return nil, err
}
for _, object := range out.Objects {
return object, nil
}
return nil, fmt.Errorf("no object in results")
}