Documentation ¶
Index ¶
- Constants
- Variables
- type Download
- type DownloadMsg
- type DownloadResp
- type ErrorMsg
- type Events
- type FSEvent
- type FSNode
- type FileAttr
- type FileAttrMsg
- type FileDeleteMsg
- type FileInfoMsg
- type FilesMsg
- type FilesResp
- type GenericEvent
- type GetLinkMsg
- type LoginMsg
- type LoginResp
- type Mega
- func (m *Mega) CreateDir(name string, parent *Node) (*Node, error)
- func (m *Mega) Delete(node *Node, destroy bool) error
- func (m *Mega) DownloadFile(src *Node, dstpath string, progress *chan int) error
- func (m *Mega) DownloadPublicFile(hash, key, dstpath string, progress *chan int) error
- func (m *Mega) GetQuota() (QuotaResp, error)
- func (m *Mega) GetUser() (UserResp, error)
- func (m *Mega) Link(n *Node, includeKey bool) (string, error)
- func (m *Mega) Login(email string, passwd string) error
- func (m *Mega) Move(src *Node, parent *Node) error
- func (m *Mega) MultiFactorLogin(email, passwd, multiFactor string) error
- func (m *Mega) NewDownload(src *Node) (*Download, error)
- func (m *Mega) NewPublicDownload(hash, key string) (*Download, error)
- func (m *Mega) NewUpload(parent *Node, name string, fileSize int64) (*Upload, error)
- func (m *Mega) Rename(src *Node, name string) error
- func (c *Mega) SetAPIUrl(u string)
- func (m *Mega) SetClient(client *http.Client) *Mega
- func (m *Mega) SetDebugger(debugf func(format string, v ...interface{})) *Mega
- func (c *Mega) SetDownloadWorkers(w int) error
- func (c *Mega) SetHTTPS(e bool)
- func (m *Mega) SetLogger(logf func(format string, v ...interface{})) *Mega
- func (c *Mega) SetRetries(r int)
- func (c *Mega) SetTimeOut(t time.Duration)
- func (c *Mega) SetUploadWorkers(w int) error
- func (m *Mega) UploadFile(srcpath string, parent *Node, name string, progress *chan int) (node *Node, err error)
- func (m *Mega) WaitEvents(eventChan <-chan struct{}, duration time.Duration) (timedout bool)
- func (m *Mega) WaitEventsStart() <-chan struct{}
- type MegaFS
- func (fs *MegaFS) GetChildren(n *Node) ([]*Node, error)
- func (fs *MegaFS) GetInbox() *Node
- func (fs *MegaFS) GetRoot() *Node
- func (fs *MegaFS) GetSharedRoots() []*Node
- func (fs *MegaFS) GetTrash() *Node
- func (fs *MegaFS) HashLookup(h string) *Node
- func (fs *MegaFS) PathLookup(root *Node, ns []string) ([]*Node, error)
- type MoveFileMsg
- type Node
- type NodeMeta
- type PreloginMsg
- type PreloginResp
- type QuotaMsg
- type QuotaResp
- type Upload
- type UploadCompleteMsg
- type UploadCompleteResp
- type UploadMsg
- type UploadResp
- type UserMsg
- type UserResp
Constants ¶
const ( API_URL = "https://g.api.mega.co.nz" BASE_DOWNLOAD_URL = "https://mega.co.nz" RETRIES = 10 DOWNLOAD_WORKERS = 3 MAX_DOWNLOAD_WORKERS = 30 UPLOAD_WORKERS = 1 MAX_UPLOAD_WORKERS = 30 TIMEOUT = time.Second * 10 HTTPSONLY = false )
Default settings
const ( FILE = 0 FOLDER = 1 ROOT = 2 INBOX = 3 TRASH = 4 )
Filesystem node types
Variables ¶
var ( // General errors EINTERNAL = errors.New("Internal error occured") EARGS = errors.New("Invalid arguments") EAGAIN = errors.New("Try again") ERATELIMIT = errors.New("Rate limit reached") EBADRESP = errors.New("Bad response from server") // Upload errors EFAILED = errors.New("The upload failed. Please restart it from scratch") ETOOMANY = errors.New("Too many concurrent IP addresses are accessing this upload target URL") ERANGE = errors.New("The upload file packet is out of range or not starting and ending on a chunk boundary") EEXPIRED = errors.New("The upload target URL you are trying to access has expired. Please request a fresh one") // Filesystem/Account errors ENOENT = errors.New("Object (typically, node or user) not found") ECIRCULAR = errors.New("Circular linkage attempted") EACCESS = errors.New("Access violation") EEXIST = errors.New("Trying to create an object that already exists") EINCOMPLETE = errors.New("Trying to access an incomplete resource") EKEY = errors.New("A decryption operation failed") ESID = errors.New("Invalid or expired user session, please relogin") EBLOCKED = errors.New("User blocked") EOVERQUOTA = errors.New("Request over quota") ETEMPUNAVAIL = errors.New("Resource temporarily not available, please try again later") EMACMISMATCH = errors.New("MAC verification failed") EBADATTR = errors.New("Bad node attribute") ETOOMANYCONNECTIONS = errors.New("Too many connections on this resource.") EWRITE = errors.New("File could not be written to (or failed post-write integrity check).") EREAD = errors.New("File could not be read from (or changed unexpectedly during reading).") EAPPKEY = errors.New("Invalid or missing application key.") ESSL = errors.New("SSL verification failed") EGOINGOVERQUOTA = errors.New("Not enough quota") EMFAREQUIRED = errors.New("Multi-factor authentication required") // Config errors EWORKER_LIMIT_EXCEEDED = errors.New("Maximum worker limit exceeded") )
Functions ¶
This section is empty.
Types ¶
type Download ¶
type Download struct {
// contains filtered or unexported fields
}
Download contains the internal state of a download
func (*Download) ChunkLocation ¶
ChunkLocation returns the position in the file and the size of the chunk
func (*Download) DownloadChunk ¶
DownloadChunk gets a chunk with the given number and update the mac, returning the position in the file of the chunk
type DownloadMsg ¶
type DownloadResp ¶
type Events ¶
type Events struct { W string `json:"w"` Sn string `json:"sn"` E []json.RawMessage `json:"a"` }
Events is received from a poll of the server to read the events
Each event can be an error message or a different field so we delay decoding
type FSEvent ¶
type FSEvent struct { Cmd string `json:"a"` T struct { Files []FSNode `json:"f"` } `json:"t"` Owner string `json:"ou"` N string `json:"n"` User string `json:"u"` Attr string `json:"at"` Key string `json:"k"` Ts int64 `json:"ts"` I string `json:"i"` }
FSEvent - event for various file system events
Delete (a=d) Update attr (a=u) New nodes (a=t)
type FileAttrMsg ¶
type FileDeleteMsg ¶
type FileInfoMsg ¶
type FilesResp ¶
type FilesResp struct { F []FSNode `json:"f"` Ok []struct { Hash string `json:"h"` Key string `json:"k"` } `json:"ok"` S []struct { Hash string `json:"h"` User string `json:"u"` } `json:"s"` User []struct { User string `json:"u"` C int `json:"c"` Email string `json:"m"` } `json:"u"` Sn string `json:"sn"` }
type GenericEvent ¶
type GenericEvent struct {
Cmd string `json:"a"`
}
GenericEvent is a generic event for parsing the Cmd type before decoding more specifically
type GetLinkMsg ¶
type Mega ¶
type Mega struct { // Filesystem object FS *MegaFS // contains filtered or unexported fields }
func (*Mega) DownloadFile ¶
Download file from filesystem reporting progress if not nil
func (*Mega) DownloadPublicFile ¶
Download public file from filesystem reporting progress if not nil
func (*Mega) MultiFactorLogin ¶
MultiFactorLogin - Authenticate and start a session with 2FA
func (*Mega) NewDownload ¶
Create a new Download from the src Node
Call Chunks to find out how many chunks there are, then for id = 0..chunks-1 call DownloadChunk. Finally call Finish() to receive the error status.
func (*Mega) NewPublicDownload ¶
Create a new public Download from the hash and key
Call Chunks to find out how many chunks there are, then for id = 0..chunks-1 call DownloadChunk. Finally call Finish() to receive the error status.
func (*Mega) NewUpload ¶
Create a new Upload of name into parent of fileSize
Call Chunks to find out how many chunks there are, then for id = 0..chunks-1 Call ChunkLocation then UploadChunk. Finally call Finish() to receive the error status and the *Node.
func (*Mega) SetDebugger ¶
SetDebugger sets the logger for debug messages. By default these messages are not output.
func (*Mega) SetDownloadWorkers ¶
Set concurrent download workers
func (*Mega) SetLogger ¶
SetLogger sets the logger for important messages. By default this is log.Printf. Use nil to discard the messages.
func (*Mega) SetUploadWorkers ¶
Set concurrent upload workers
func (*Mega) UploadFile ¶
func (m *Mega) UploadFile(srcpath string, parent *Node, name string, progress *chan int) (node *Node, err error)
Upload a file to the filesystem
func (*Mega) WaitEvents ¶
WaitEvents waits for all outstanding events to be received for a maximum of duration. eventChan should be a channel as returned from WaitEventStart.
If the timeout elapsed then it returns true otherwise false.
func (*Mega) WaitEventsStart ¶
func (m *Mega) WaitEventsStart() <-chan struct{}
WaitEventsStart - call this before you do the action which might generate events then use the returned channel as a parameter to WaitEvents to wait for the event(s) to be received.
type MegaFS ¶
type MegaFS struct {
// contains filtered or unexported fields
}
Mega filesystem object
func (*MegaFS) GetChildren ¶
Get the list of child nodes for a given node
func (*MegaFS) GetSharedRoots ¶
Get top level directory nodes shared by other users
func (*MegaFS) HashLookup ¶
Get a node pointer from its hash
type MoveFileMsg ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Filesystem node
func (*Node) GetTimeStamp ¶
type PreloginMsg ¶
type PreloginResp ¶
type Upload ¶
type Upload struct {
// contains filtered or unexported fields
}
Upload contains the internal state of a upload
func (*Upload) ChunkLocation ¶
ChunkLocation returns the position in the file and the size of the chunk
type UploadCompleteMsg ¶
type UploadCompleteResp ¶
type UploadCompleteResp struct {
F []FSNode `json:"f"`
}
type UploadResp ¶
type UploadResp struct {
P string `json:"p"`
}