1
1
# go-w3s-client
2
2
3
- ⚠️ WIP. A client to the web3.storage API.
3
+ A client to the Web3.Storage API.
4
4
5
5
## Install
6
6
@@ -14,15 +14,52 @@ go get .com/web3-storage/go-w3s-client
14
14
package main
15
15
16
16
import (
17
+ " io/fs"
17
18
" os"
18
19
" .com/web3-storage/go-w3s-client"
19
20
)
20
21
21
22
func main () {
22
23
c , _ := w3s.NewClient (w3s.WithToken (" <AUTH_TOKEN>" ))
23
24
f , _ := os.Open (" images/pinpie.jpg" )
25
+
26
+ // OR add a whole directory:
27
+ //
28
+ // f, _ := os.Open("images")
29
+ //
30
+ // OR create your own directory:
31
+ //
32
+ // img0, _ := os.Open("aliens.jpg")
33
+ // img1, _ := os.Open("donotresist.jpg")
34
+ // f := w3fs.NewDir("images", []fs.File{img0, img1})
35
+
36
+ // Write a file/directory
24
37
cid , _ := c.Put (context.Background (), f)
25
- fmt.Printf (" https://%v .ipfs.dweb.link\n " , cid)
38
+ fmt.Printf (" https://%v .ipfs.dweb.link\n " , cid)
39
+
40
+ // Retrieve a file/directory
41
+ f , fsys , _ := c.Get (context.Background (), cid)
42
+
43
+ // List directory entries
44
+ if d , ok := f.(fs.ReadDirFile ); ok {
45
+ ents , _ := d.ReadDir (0 )
46
+ for _ , ent := range ents {
47
+ fmt.Println (ent.Name ())
48
+ }
49
+ }
50
+
51
+ // Walk whole directory contents (including nested directories)
52
+ fs.WalkDir (fsys, " /" , func (path string , d fs.DirEntry , err error ) error {
53
+ info , _ := d.Info ()
54
+ fmt.Printf (" %s (%d bytes)\n " , path, info.Size ())
55
+ return err
56
+ })
57
+
58
+ // Open a file in a directory
59
+ img , _ := fsys.Open (" pinpie.jpg" )
60
+ // img.Stat()
61
+ // img.Read(...)
62
+ // img.Close()
26
63
}
27
64
```
28
65
0 commit comments