Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit bbee971

Browse files
author
Alan Shaw
committed
docs: example
1 parent 54a83bc commit bbee971

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

‎README.md

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# go-w3s-client
22

3-
⚠️ WIP. A client to the web3.storage API.
3+
A client to the Web3.Storage API.
44

55
## Install
66

@@ -14,15 +14,52 @@ go get .com/web3-storage/go-w3s-client
1414
package main
1515

1616
import (
17+
"io/fs"
1718
"os"
1819
".com/web3-storage/go-w3s-client"
1920
)
2021

2122
func main() {
2223
c, _ := w3s.NewClient(w3s.WithToken("<AUTH_TOKEN>"))
2324
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
2437
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()
2663
}
2764
```
2865

0 commit comments

Comments
 (0)