Documentation ¶
Index ¶
- Constants
- type Content
- type DefaultFile
- type File
- func (f *File) Add(data []byte, overWrite bool) (int, error)
- func (f *File) CurrentVersion() (int, error)
- func (f *File) Delete() error
- func (f *File) DeleteAllVersions() error
- func (f *File) GetFile() (*StorageFile, error)
- func (f *File) Version(version uint32) *VersionedFile
- func (f *File) Versions() ([]string, error)
- type ReadOnlyContent
- type ReadWriteContent
- type Storage
- type StorageFile
- type VersionedFile
Examples ¶
Constants ¶
const CidBufferSize = 64
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct {
Id uint32
}
Example ¶
package main import ( "fmt" "io" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.ContentMockData{Id: 2}.Mock() content, err := storage.Create() if err != nil { return } _, err = content.Write([]byte("Hello World!")) if err != nil { return } _, err = content.Seek(0, 0) if err != nil { return } cid, err := content.Push() if err != nil { return } newContent, err := storage.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 { return } fmt.Println(string(data)) }
Output: Hello World!
func (*Content) Push ¶
Push adds the file into the network. Updates the cid of the file. Returns cid and an error
type DefaultFile ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
func (*File) Add ¶
Add uses the data and overwrite given and adds the file to the storage. If overwrite is set to true then the current version number is not updated, and the data for the current version is updated. If overwrite is set to false, then for versioning enabled storages a new version is created For versioning disabled storages, file is only added if there is no file with the same name in the current storage. Returns the current version of the file.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.FileMockData{ StorageId: 5, StorageName: "testStorage", FileName: "testFile", Version: 2, Data: []byte("Hello World"), }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") version, err := file.Add([]byte("Hello World"), true) if err != nil { return } fmt.Println(version) }
Output: 3
func (*File) CurrentVersion ¶
Current version looks up in the storage the latest version that is stored for that specific file. Returns the latest version for the file, if found, and an error.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.FileMockData{ StorageId: 5, StorageName: "testStorage", FileName: "testFile", Version: 2, }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") version, err := file.CurrentVersion() if err != nil { return } fmt.Println(version) }
Output: 2
func (*File) Delete ¶
Delete uses the current file structure and the given version to delete the specific version of a file from the storage. Returns an error
Example ¶
package main import ( "fmt" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") err = file.Delete() if err != nil { return } fmt.Println("Success") }
Output: Success
func (*File) DeleteAllVersions ¶
DeleteAllVersions uses the current file and deletes all version of it in the storage. Returns an error
Example ¶
package main import ( "fmt" "github.com/taubyte/go-sdk/storage" ) func main() { db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") err = file.DeleteAllVersions() if err != nil { return } fmt.Println("Success") }
Output: Success
func (*File) GetFile ¶
func (f *File) GetFile() (*StorageFile, error)
GetFile grabs the the file from the storage Returns the file and an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.FileMockData{ StorageId: 5, StorageName: "testStorage", Id: 10, FileName: "testFile", FileId: 25, }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") _, err = file.GetFile() if err != nil { return } fmt.Println("Success") }
Output: Success
func (*File) Version ¶
func (f *File) Version(version uint32) *VersionedFile
Version uses current file and given versions to create a new instance of VersionedFile Returns the created VersionedFile structure.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.FileMockData{ StorageId: 5, StorageName: "testStorage", Id: 10, FileName: "testFile", FileId: 25, }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") versionedFile := file.Version(12) if versionedFile == nil { return } fmt.Println("Success") }
Output: Success
func (*File) Versions ¶
ListVersions uses the current file and looks up all version of the file. Returns []string of all the versions and an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.FileMockData{ StorageId: 5, StorageName: "testStorage", FileName: "testFile", Versions: map[string][]string{"testFile": {"1", "2", "3"}}, }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") versions, err := file.Versions() if err != nil { return } fmt.Println(versions) }
Output: [1 2 3]
type ReadOnlyContent ¶
type ReadOnlyContent interface { io.ReadSeekCloser Cid() (cid.Cid, error) }
func Open ¶
func Open(_cid cid.Cid) (ReadOnlyContent, error)
Open creates a new content using the cid given as the file. Returns a new content.
Example ¶
// Mocking the calls to the vm for usage in tests and playground symbols.MockOpen(11, "QmQUXYRNqU2U351aE8mrPFAyqXtKupF9bDspXKLsdkTLGn") testCid, err := cid.Parse("QmQUXYRNqU2U351aE8mrPFAyqXtKupF9bDspXKLsdkTLGn") if err != nil { return } content, err := storage.Open(testCid) if err != nil { return } fmt.Println(content)
Output: &{11}
type ReadWriteContent ¶
type ReadWriteContent interface { io.ReadWriteSeeker io.Closer Push() (cid.Cid, error) }
func Create ¶
func Create() (ReadWriteContent, error)
Create creates and returns the new content.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockCreate(10) content, err := storage.Create() if err != nil { return } fmt.Println(content) }
Output: &{10}
type Storage ¶
type Storage uint32
func Get ¶
Get returns the storage with given name. Returns the storage if it exists and an error.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockGet(map[string]uint32{"exampleStorage": 16}, 16) db, err := storage.Get("exampleStorage") if err != nil { return } fmt.Println(db) }
Output: 16
func New ¶
New creates a new storage Returns a storage and an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockNew(32, "exampleStorage") db, err := storage.New("exampleStorage") if err != nil { return } fmt.Println(db) }
Output: 32
func (Storage) Cid ¶
Cid looks up the given filename in the given storage. Returns the cid corresponding to the file if found and an error.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.StorageMockData{ StorageId: 2, StorageName: "testStorage", FileId: 15, FileName: "testFile", Cid: "bafybeiavzbz2ugyergky6plyluts2evta5hu6ehhicmuow4zm6vd42pugq", }.Mock() db, err := storage.New("testStorage") if err != nil { return } cid, err := db.Cid("testFile") if err != nil { return } fmt.Println(cid) }
Output: bafybeiavzbz2ugyergky6plyluts2evta5hu6ehhicmuow4zm6vd42pugq
func (Storage) File ¶
File uses the name passed in and creates a new instance of File that holds the storage and filename. Returns the File structure.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.StorageMockData{ StorageId: 2, StorageName: "testStorage", }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") fmt.Println(file) }
Output: &{2 testFile 0}
func (Storage) ListFiles ¶
ListFiles looks up all saved files in the given storage. Returns an array of all Files found in the storage and an error.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.StorageMockData{ StorageId: 2, StorageName: "testStorage", Files: "file/testFile1/1/file/testFile2/2", }.Mock() db, err := storage.New("testStorage") if err != nil { return } files, err := db.ListFiles() if err != nil { return } fmt.Println(files) }
Output: [{2 testFile1 1} {2 testFile2 2}]
func (Storage) RemainingCapacity ¶
Remaining capacity loops through to given storage and calculates how much space left is available. Returns the remaining space available and an error.
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.StorageMockData{ StorageId: 2, StorageName: "testStorage", Used: 25, Capacity: 100, }.Mock() db, err := storage.New("testStorage") if err != nil { return } remaining, err := db.RemainingCapacity() if err != nil { return } fmt.Println(remaining) }
Output: 75
type StorageFile ¶
type StorageFile struct {
// contains filtered or unexported fields
}
func (*StorageFile) Close ¶
func (file *StorageFile) Close() error
Close closes the current file Returns an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.StorageFileMockData{StorageId: 5, StorageName: "testStorage", }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") dbFile, err := file.GetFile() if err != nil { return } err = dbFile.Close() if err != nil { return } fmt.Println("Success") }
Output: Success
func (*StorageFile) Read ¶
func (file *StorageFile) Read(p []byte) (int, error)
Read reads the given bytes Returns an int of how much was read and an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/storage" "github.com/taubyte/go-sdk/storage" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.StorageFileMockData{ StorageId: 5, StorageName: "testStorage", FileId: 10, Data: []byte("Hello World"), }.Mock() db, err := storage.New("testStorage") if err != nil { return } file := db.File("testFile") dbFile, err := file.GetFile() if err != nil { return } p := make([]byte, len("Hello World")) read, err := dbFile.Read(p) if err != nil { return } fmt.Println(read) }
Output: 11
type VersionedFile ¶
type VersionedFile struct {
DefaultFile
}