storage

package
v0.0.0-...-19f3ddf Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Copyright 2021 The ChromiumOS Authors Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var ErrBucketNotExist = errors.New("bucket does not exist")
View Source
var ErrObjectNotExist = errors.New("object does not exist")

Functions

This section is empty.

Types

type GSClient

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

func NewGSClient

func NewGSClient(ctx context.Context, credentialsFile string) (*GSClient, error)

func NewGSTestClient

func NewGSTestClient(client StorageClientInterface) *GSClient

func (*GSClient) Close

func (c *GSClient) Close()

func (*GSClient) DownloadFile

func (c *GSClient) DownloadFile(ctx context.Context, gsUrl, destLocalPath string) error

DownloadFile downloads a file from a designated gsURL to a given path on the local file system. If the bucket does not exist, returns ErrBucketNotExist. If the object does not exist, returns ErrObjectNotExist.

func (*GSClient) Upload

func (c *GSClient) Upload(ctx context.Context, localFolder string, gsUrl string) error

Upload uploads localFolder (which may be a file) to designated gsURL uploads here are done in parallel

type GSClientInterface

type GSClientInterface interface {
	Upload(ctx context.Context, localFolder string, gsUrl string) error
	Close()
}

For testing

type GSObject

type GSObject struct {
	Bucket string
	Object string
}

Storage metadata for remote file

func (GSObject) Extend

func (o GSObject) Extend(addendum string) GSObject

Extend adds addendum to the end of object for a GSObject

type LocalObject

type LocalObject struct {
	FullPath string
	RelPath  string
}

Storage metadata for local file

type StorageClient

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

func NewStorageClientWithCredsFile

func NewStorageClientWithCredsFile(ctx context.Context, credentialsFile string) (*StorageClient, error)

func NewStorageClientWithDefaultAccount

func NewStorageClientWithDefaultAccount(ctx context.Context) (*StorageClient, error)

func (*StorageClient) Close

func (c *StorageClient) Close()

func (*StorageClient) Read

func (c *StorageClient) Read(ctx context.Context, gsObject GSObject, destFilePath string) (retErr error)

Read downloads a file from GCS to the given local path. If the bucket does not exist in GCS, the method returns ErrBucketNotExist. If the object does not exist in GCS, the method returns ErrObjectNotExist.

func (*StorageClient) Write

func (c *StorageClient) Write(ctx context.Context, filePath string, gsObject GSObject) error

Write a single file to GCS.

type StorageClientInterface

type StorageClientInterface interface {
	Close()
	Write(ctx context.Context, filePath string, gsObject GSObject) error
	Read(ctx context.Context, gsObject GSObject, destFilePath string) error
}

This file exists to provide a mockable interface to the google storage client

Jump to

Keyboard shortcuts

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