/
methods.go
41 lines (32 loc) · 957 Bytes
/
methods.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
package client
import (
"fmt"
"github.com/ipfs/go-cid"
ipfsClientSym "github.com/taubyte/go-sdk-symbols/ipfs/client"
"github.com/taubyte/go-sdk/utils/codec"
)
// Creates creates and returns the new content.
func (c Client) Create() (ReadWriteContent, error) {
newContent := &Content{client: c}
err := ipfsClientSym.IpfsNewContent(uint32(c), &newContent.id)
if err != 0 {
return nil, fmt.Errorf("Failed creating new content with %v", err)
}
return newContent, nil
}
// Open creates a new content using the cid given as the file.
// Returns a new content.
func (c Client) Open(_cid cid.Cid) (ReadOnlyContent, error) {
content := &Content{
client: c,
}
writer, err := codec.CidWriter(_cid)
if err != nil {
return nil, err
}
err0 := ipfsClientSym.IpfsOpenFile(uint32(c), &content.id, writer.Ptr())
if err0 != 0 {
return nil, fmt.Errorf("opening file from cid `%s` failed with: %v", _cid.String(), err)
}
return content, nil
}