client

package
Version: v0.1.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2022 License: GPL-3.0 Imports: 6 Imported by: 2

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 New

func New() (Client, error)

func (Client) Create added in v0.1.23

func (c Client) Create() (ReadWriteContent, error)

Creates creates and returns the new content.

func (Client) Open added in v0.1.23

func (c Client) Open(_cid cid.Cid) (ReadOnlyContent, error)

Open creates a new content using the cid given as the file. Returns a 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

func (c *Content) Cid() (cid.Cid, error)

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

func (c *Content) Close() error

Close closes the file associated with the content. Returns an error.

func (*Content) Push added in v0.1.23

func (c *Content) Push() (cid.Cid, error)

Push adds the file into the network then closes the file Returns cid and an error

func (*Content) Read added in v0.1.23

func (c *Content) Read(p []byte) (int, error)

func (*Content) Seek added in v0.1.23

func (c *Content) Seek(offset int64, whence int) (int64, error)

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

func (*Content) Write added in v0.1.23

func (c *Content) Write(p []byte) (int, error)

Write writes the passed in data into the file. Returns how much was written 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

type ReadWriteContent interface {
	io.ReadWriteSeeker
	io.Closer
	Push() (cid.Cid, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL