drive

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PathSlice

func PathSlice(path string) []string

PathSlice convert a path into a slice containing segments of the path TODO: make the unit test for PathSlice

Types

type DeleteFileOpts

type DeleteFileOpts struct {
}

type DriveIndex

type DriveIndex struct {
	// contains filtered or unexported fields
}

DriveIndex an in-memory list of drives which acts as a testing infra for DriveStore

func NewDriveStore

func NewDriveStore() *DriveIndex

NewDriveStore create a DriveIndex with an empty list of drives

func (*DriveIndex) Put

func (di *DriveIndex) Put(d UserDrive) error

Put a new drive in the DriveStore, if the drive already exists, returns a "drive already exists" error

func (*DriveIndex) Resolve

func (di *DriveIndex) Resolve(userDID string) (UserDrive, error)

Resolve a Drive based on UserDID, if the drive does not exist returns a "Drive not found" error

func (*DriveIndex) ResolveCreate

func (di *DriveIndex) ResolveCreate(userDID string) (UserDrive, error)

ResolveCreate resolve a Drive based on UserDID, if the drive does not exist creates one, puts it in the store and returns it

func (*DriveIndex) Update

func (di *DriveIndex) Update(d UserDrive) error

Update an existing drive in the Drive store, if the drive does not exist, returns a "drive does not exist" error

type DrivePrivateSpace

type DrivePrivateSpace struct {
	DriveSpace
}

DrivePrivateSpace implement private space inside a Drive

func (*DrivePrivateSpace) ReadFile

func (ds *DrivePrivateSpace) ReadFile(p string, options ReadFileOpts) (pfs.EncodedFile, error)

Reads a file from private space in a drive at a give location, it returns and additional JWE byte array

func (*DrivePrivateSpace) WriteFile

func (ds *DrivePrivateSpace) WriteFile(p string, file files.File, jwe []byte, options WriteFileOpts) (string, error)

WriteFile writes a file into private space in a drive at a given location, it takes a byte array called JWE in addition to DrivePublicSpace.WriteFile

type DrivePublicSpace

type DrivePublicSpace struct {
	DriveSpace
}

DrivePublicSpace implement public space inside a Drive

func (*DrivePublicSpace) ReadFile

func (ds *DrivePublicSpace) ReadFile(p string, options ReadFileOpts) (files.File, error)

ReadFile reads a file from the drive at a given location

func (*DrivePublicSpace) WriteFile

func (ds *DrivePublicSpace) WriteFile(p string, file files.File, options WriteFileOpts) (string, error)

WriteFile writes a file into drive at a given location (in public space).

type DriveSpace

type DriveSpace struct {
	Ctx       context.Context
	Api       fxiface.CoreAPI
	SpaceType DriveSpaceType
	RootCid   string
	RootDir   files.Directory
	Drive     *UserDrive
}

DriveSpace holds information about a space inside a user's drive A drive space can be either Private or Public, SpaceType indicates this

func (*DriveSpace) DeleteFile

func (ds *DriveSpace) DeleteFile(p string, options DeleteFileOpts) (string, error)

DeleteFile deletes a file at a given location on the drive

func (*DriveSpace) ListEntries

func (ds *DriveSpace) ListEntries(p string, options ListEntriesOpts) (<-chan ipfsifsce.DirEntry, error)

List all of entries in a path

func (*DriveSpace) MkDir

func (ds *DriveSpace) MkDir(p string, options MkDirOpts) (string, error)

MkDir creates a new directory inside a DriveSpace given a path

func (*DriveSpace) Save added in v0.4.7

func (ds *DriveSpace) Save()

Save sets the space's root cid in it's parent drive This should be called before UserDrive.Publish()

type DriveSpaceType

type DriveSpaceType string
const (
	PublicDriveSpaceType  DriveSpaceType = "public"
	PrivateDriveSpaceType DriveSpaceType = "private"
)

type DriveStore

type DriveStore interface {
	Resolve(string) (UserDrive, error)
	ResolveCreate(string) (UserDrive, error)
	Put(UserDrive) error
	Update(UserDrive) error
}

DriveStore Interface for a Drive Store. DriveStore handles logic for discovering, updating and persisting a drive

type ListEntriesOpts

type ListEntriesOpts struct {
}

type ListEntry

type ListEntry struct {
	ipfsifsce.DirEntry
}

type MkDirOpts

type MkDirOpts struct {
}

type ReadFileOpts

type ReadFileOpts struct {
}

type UserDrive

type UserDrive struct {
	UserDID         string
	PrivateSpaceCid string
	PublicSpaceCid  string
	Dirs            map[string]string
	// contains filtered or unexported fields
}

UserDrive holds necessary info to identify a user's drive on the network It holds info about user's ID, root cids for each space and a DriveStore instance

func NewDrive

func NewDrive(userDID string, ds DriveStore) UserDrive

NewDrive create a new null Drive, the only field set is the UserDID, other fields are initialized by first call to Publish

func (*UserDrive) IsNull

func (ud *UserDrive) IsNull() bool

IsNull check if a drive is null

func (*UserDrive) PrivateSpace

func (ud *UserDrive) PrivateSpace(ctx context.Context, api fxiface.CoreAPI) (*DrivePrivateSpace, error)

PrivateSpace create a DrivePrivateSpace struct. PrivateSpace creates a Directory instance by getting the root cid of the drive using FS API

func (*UserDrive) PublicSpace

func (ud *UserDrive) PublicSpace(ctx context.Context, api fxiface.CoreAPI) (*DrivePublicSpace, error)

PublicSpace create a DrivePublicSpace struct. PublicSpace creates a Directory instance by getting the root cid of the drive using FS API

func (*UserDrive) Publish

func (ud *UserDrive) Publish(ctx context.Context, api fxiface.CoreAPI) error

Publish a Drive If the drive is null, it will create two directories for Private and Public space, stores a file containing UserDID in them Publish uses DriveStore to update the drive reference

type WriteFileOpts

type WriteFileOpts struct {
}

Jump to

Keyboard shortcuts

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