drive

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ErrReasonRateLimitExceeded = "rateLimitExceeded"
View Source
const ErrReasonSizeLimitExceeded = "exportSizeLimitExceeded"
View Source
const FileTypeFolder = "application/vnd.google-apps.folder"
View Source
const FileTypeSDKPrefix = "application/vnd.google-apps.drive-sdk."
View Source
const FileTypeShortcut = "application/vnd.google-apps.shortcut"

Variables

View Source
var ErrNoExportableFormat = errors.New("no exportable format")
View Source
var ExportExtensions = map[string]string{
	"application/vnd.google-apps.document":     ".docx",
	"application/vnd.google-apps.presentation": ".pptx",
	"application/vnd.google-apps.spreadsheet":  ".xlsx",
	"application/vnd.google-apps.drawing":      ".svg",
	"application/vnd.google-apps.jam":          ".pdf",
	"application/vnd.google-apps.script":       ".json",
	"application/vnd.google-apps.form":         ".zip",
	"application/vnd.google-apps.site":         ".txt",
}
View Source
var ExportTypes = map[string]string{
	"application/vnd.google-apps.document":     "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
	"application/vnd.google-apps.presentation": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
	"application/vnd.google-apps.spreadsheet":  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
	"application/vnd.google-apps.drawing":      "image/svg+xml",
	"application/vnd.google-apps.jam":          "application/pdf",
	"application/vnd.google-apps.script":       "application/vnd.google-apps.script+json",
	"application/vnd.google-apps.form":         "application/zip",
	"application/vnd.google-apps.site":         "text/plain",
}
View Source
var SkipTypes = map[string]struct{}{
	"application/vnd.google-apps.fusiontable": {},
	"application/vnd.google-apps.map":         {},
}
View Source
var ValidPathChars = regexp.MustCompile("[^a-zA-Z0-9 !@#$%^&()\\-_=+\\[\\]{}';\\.,`~]")

ValidPathChars is the set of valid path name characters

Functions

This section is empty.

Types

type File

type File struct {
	ID             string
	Name           string
	File           *drive.File
	Files          []*File
	Parents        []*File
	ShortcutTarget *File
}

File represents a Google Drive File or Folder. A Google Drive object can have multiple parents

func NewTree

func NewTree(rootID string, list []*drive.File) (tree, orphaned *File)

NewTree parses a list of Google Drive files and returns two trees: a tree rooted at the user's Google Drive (specified by rootID) and an "Other Files" tree which includes all files not under the main tree.

func (*File) IsFolder

func (fi *File) IsFolder() bool

IsFolder returns true if the File is a folder

func (*File) Walk

func (fi *File) Walk(f func(path string, file *File) error) error

Walk walks through all of the files in the tree and calls f() on them. The current file and full path to the file is passed to f(). If f() returns an error, iteration and the error is returned.

type Service

type Service struct {
	*drive.FilesService
	// contains filtered or unexported fields
}

Service is a Google Drive file service

func NewService

func NewService(configPath, user string, initialBackoff time.Duration, tries int) (*Service, error)

NewService returns a new service using the service account credentials JSON file found at configPath for the given user initialBackoff and tries are used to configure an exponential backoff strategy. Set tries to 1 to disable retries or set tries to <= 0 to retry infinitely

To create the JSON file for configPath:

func (*Service) Download

func (s *Service) Download(file *drive.File, path string) error

Download downloads the file with id to path. Most users should use DownloadFile instead

func (*Service) DownloadFile

func (s *Service) DownloadFile(f *drive.File, path string) (downloaded bool, err error)

DownloadFile downloads f to path. It automatically resolves shortcuts and converts Google Docs, Slides, Sheets, and Drawings to downloadable formats. If downloaded is false, the file was not downloaded because the existing file matched.

func (*Service) DownloadTree

func (s *Service) DownloadTree(root *File, outpath string, downloaders int) error

DownloadTree downloads the file tree rooted at root to outpath using the specified number of downloaders. If downloaders is less than 1, runtime.NumCPU() will be used

func (*Service) Export

func (s *Service) Export(file *drive.File, mimeType, path string) error

Export exports (with specified mime type) the file with id to path. Most users should use DownloadFile instead

func (*Service) List

func (s *Service) List() ([]*drive.File, error)

List returns all files in the user's Google Drive

func (*Service) Root

func (s *Service) Root() (string, error)

Root returns the root folder ID of the user's Google Drive

Jump to

Keyboard shortcuts

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