Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const CidBufferSize = 64
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client uint32
Example ¶
package main
import (
"fmt"
"io"
symbols "bitbucket.org/taubyte/go-sdk-symbols/ipfs/client"
"bitbucket.org/taubyte/go-sdk/ipfs/client"
)
func main() {
// Mocking the calls to the vm for usage in tests and playground
symbols.MockData{}.Mock()
ipfsClient, err := client.New()
if err != nil {
return
}
content, err := ipfsClient.Create()
if err != nil {
return
}
_, err = content.Write([]byte("Hello, world!"))
if err != nil {
return
}
cid, err := content.Push()
if err != nil {
return
}
newContent, err := ipfsClient.Open(cid)
if err != nil {
return
}
data, err := io.ReadAll(newContent)
if err != nil {
return
}
err = newContent.Close()
if err != nil {
return
}
newCid, err := newContent.Cid()
if err != nil || cid != newCid {
fmt.Println(err)
return
}
fmt.Println(string(data))
}
Output: Hello, world!
func (Client) Create ¶ added in v0.1.23
func (c Client) Create() (ReadWriteContent, error)
Creates creates and returns the new content.
type Content ¶ added in v0.1.23
type Content struct {
// contains filtered or unexported fields
}
func (*Content) Cid ¶ added in v0.1.23
Cid returns the cid of the file and an error.
Example ¶
_cid, _ := cid.Parse("bafkreibrl5n5w5wqpdcdxcwaazheualemevr7ttxzbutiw74stdvrfhn2m")
symbols.MockData{
Files: map[cid.Cid]*os.File{
_cid: nil,
},
}.Mock()
client, err := client.New()
if err != nil {
return
}
content, err := client.Open(_cid)
if err != nil {
return
}
cid, err := content.Cid()
if err != nil {
return
}
fmt.Println("Cid:", cid.String())
Output: Cid: bafkreibrl5n5w5wqpdcdxcwaazheualemevr7ttxzbutiw74stdvrfhn2m
func (*Content) Close ¶ added in v0.1.23
Close closes the file associated with the content. Returns an error.
func (*Content) Push ¶ added in v0.1.23
Push adds the file into the network then closes the file Returns cid and an error
func (*Content) Seek ¶ added in v0.1.23
Seek moves to a position inside the file. Offset is how much to move the current position Whence has three options: 0 = SeekStart, 1 = SeekCurrent, or 2 = SeekEnd Combines both offset and whence to find a new offset inside the file Returns the new offset and an error
type ReadOnlyContent ¶ added in v0.1.32
type ReadOnlyContent interface {
io.ReadSeekCloser
Cid() (cid.Cid, error)
}
type ReadWriteContent ¶ added in v0.1.32
Click to show internal directories.
Click to hide internal directories.