files

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

README

File Storage Files SDK for API version 2023-11-03

This package allows you to interact with the Files File Storage API

Supported Authorizers

  • Azure Active Directory (for the Resource Endpoint https://storage.azure.com)
  • SharedKeyLite (Blob, File & Queue)

Limitations

  • At this time the headers x-ms-file-permission and x-ms-file-attributes are hard-coded (to inherit and None, respectively).

Example Usage

package main

import (
	"context"
	"fmt"

	"github.com/hashicorp/go-azure-sdk/sdk/auth"
	"github.com/tombuildsstuff/giovanni/storage/2023-11-03/file/files"
)

func Example() error {
	accountName := "storageaccount1"
    storageAccountKey := "ABC123...."
    shareName := "myshare"
    directoryName := "myfiles"
    fileName := "example.txt"
	domainSuffix := "core.windows.net"

	auth, err := auth.NewSharedKeyAuthorizer(accountName, storageAccountKey, auth.SharedKey)
	if err != nil {
		return fmt.Errorf("building SharedKey authorizer: %+v", err)
	}
	
    filesClient, err := files.NewWithBaseUri(fmt.Sprintf("https://%s.file.%s", accountName, domainSuffix))
	if err != nil {
		return fmt.Errorf("building client for environment: %+v", err)
	}
    filesClient.Client.SetAuthorizer(auth)
    
    ctx := context.TODO()
    input := files.CreateInput{}
    if _, err := filesClient.Create(ctx, shareName, directoryName, fileName, input); err != nil {
        return fmt.Errorf("Error creating File: %s", err)
    }
    
    return nil 
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCopyAndWaitPoller

func NewCopyAndWaitPoller(client *Client, shareName, path, fileName string) *copyAndWaitPoller

Types

type ClearByteRangeInput

type ClearByteRangeInput struct {
	StartBytes int64
	EndBytes   int64
}

type ClearByteRangeOptions

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

func (ClearByteRangeOptions) ToHeaders

func (c ClearByteRangeOptions) ToHeaders() *client.Headers

func (ClearByteRangeOptions) ToOData

func (c ClearByteRangeOptions) ToOData() *odata.Query

func (ClearByteRangeOptions) ToQuery

type ClearByteRangeResponse

type ClearByteRangeResponse struct {
	HttpResponse *http.Response
}

type Client

type Client struct {
	Client *storage.Client
}

Client is the base client for File Storage Shares.

func NewWithBaseUri

func NewWithBaseUri(baseUri string) (*Client, error)

func (Client) AbortCopy

func (c Client) AbortCopy(ctx context.Context, shareName, path, fileName string, input CopyAbortInput) (result CopyAbortResponse, err error)

AbortCopy aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata

func (Client) ClearByteRange

func (c Client) ClearByteRange(ctx context.Context, shareName, path, fileName string, input ClearByteRangeInput) (result ClearByteRangeResponse, err error)

ClearByteRange clears the specified Byte Range from within the specified File

func (Client) Copy

func (c Client) Copy(ctx context.Context, shareName, path, fileName string, input CopyInput) (result CopyResponse, err error)

Copy copies a blob or file to a destination file within the storage account asynchronously.

func (Client) CopyAndWait

func (c Client) CopyAndWait(ctx context.Context, shareName, path, fileName string, input CopyInput) (result CopyResponse, err error)

CopyAndWait is a convenience method which doesn't exist in the API, which copies the file and then waits for the copy to complete

func (Client) Create

func (c Client) Create(ctx context.Context, shareName, path, fileName string, input CreateInput) (result CreateResponse, err error)

Create creates a new file or replaces a file.

func (Client) Delete

func (c Client) Delete(ctx context.Context, shareName, path, fileName string) (result DeleteResponse, err error)

Delete immediately deletes the file from the File Share.

func (Client) GetByteRange

func (c Client) GetByteRange(ctx context.Context, shareName, path, fileName string, input GetByteRangeInput) (result GetByteRangeResponse, err error)

GetByteRange returns the specified Byte Range from the specified File.

func (Client) GetFile

func (c Client) GetFile(ctx context.Context, shareName, path, fileName string, input GetFileInput) (result GetFileResponse, err error)

GetFile is a helper method to download a file by chunking it automatically

func (Client) GetMetaData

func (c Client) GetMetaData(ctx context.Context, shareName, path, fileName string) (result GetMetaDataResponse, err error)

GetMetaData returns the MetaData for the specified File.

func (Client) GetProperties

func (c Client) GetProperties(ctx context.Context, shareName, path, fileName string) (result GetResponse, err error)

GetProperties returns the Properties for the specified file

func (Client) ListRanges

func (c Client) ListRanges(ctx context.Context, shareName, path, fileName string) (result ListRangesResponse, err error)

ListRanges returns the list of valid ranges for the specified File.

func (Client) PutByteRange

func (c Client) PutByteRange(ctx context.Context, shareName, path, fileName string, input PutByteRangeInput) (result PutRangeResponse, err error)

PutByteRange puts the specified Byte Range in the specified File.

func (Client) PutFile

func (c Client) PutFile(ctx context.Context, shareName, path, fileName string, file *os.File, parallelism int) error

PutFile is a helper method which takes a file, and automatically chunks it up, rather than having to do this yourself

func (Client) SetMetaData

func (c Client) SetMetaData(ctx context.Context, shareName, path, fileName string, input SetMetaDataInput) (result SetMetaDataResponse, err error)

SetMetaData updates the specified File to have the specified MetaData.

func (Client) SetProperties

func (c Client) SetProperties(ctx context.Context, shareName, path, fileName string, input SetPropertiesInput) (result SetPropertiesResponse, err error)

SetProperties sets the specified properties on the specified File

type CopyAbortInput

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

type CopyAbortOptions

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

func (CopyAbortOptions) ToHeaders

func (c CopyAbortOptions) ToHeaders() *client.Headers

func (CopyAbortOptions) ToOData

func (c CopyAbortOptions) ToOData() *odata.Query

func (CopyAbortOptions) ToQuery

func (c CopyAbortOptions) ToQuery() *client.QueryParams

type CopyAbortResponse

type CopyAbortResponse struct {
	HttpResponse *http.Response
}

type CopyInput

type CopyInput struct {
	// Specifies the URL of the source file or blob, up to 2 KB in length.
	//
	// To copy a file to another file within the same storage account, you may use Shared Key to authenticate
	// the source file. If you are copying a file from another storage account, or if you are copying a blob from
	// the same storage account or another storage account, then you must authenticate the source file or blob using a
	// shared access signature. If the source is a public blob, no authentication is required to perform the copy
	// operation. A file in a share snapshot can also be specified as a copy source.
	CopySource string

	MetaData map[string]string
}

type CopyOptions

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

func (CopyOptions) ToHeaders

func (c CopyOptions) ToHeaders() *client.Headers

func (CopyOptions) ToOData

func (c CopyOptions) ToOData() *odata.Query

func (CopyOptions) ToQuery

func (c CopyOptions) ToQuery() *client.QueryParams

type CopyResponse

type CopyResponse struct {
	HttpResponse *http.Response

	// The CopyID, which can be passed to AbortCopy to abort the copy.
	CopyID string

	// Either `success` or `pending`
	CopySuccess string
}

type CreateInput

type CreateInput struct {
	// This header specifies the maximum size for the file, up to 1 TiB.
	ContentLength int64

	// The MIME content type of the file
	// If not specified, the default type is application/octet-stream.
	ContentType *string

	// Specifies which content encodings have been applied to the file.
	// This value is returned to the client when the Get File operation is performed
	// on the file resource and can be used to decode file content.
	ContentEncoding *string

	// Specifies the natural languages used by this resource.
	ContentLanguage *string

	// The File service stores this value but does not use or modify it.
	CacheControl *string

	// Sets the file's MD5 hash.
	ContentMD5 *string

	// Sets the file’s Content-Disposition header.
	ContentDisposition *string

	// The time at which this file was created at - if omitted, this'll be set to "now"
	// This maps to the `x-ms-file-creation-time` field.
	CreatedAt *time.Time

	// The time at which this file was last modified - if omitted, this'll be set to "now"
	// This maps to the `x-ms-file-last-write-time` field.
	LastModified *time.Time

	// MetaData is a mapping of key value pairs which should be assigned to this file
	MetaData map[string]string
}

type CreateOptions

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

func (CreateOptions) ToHeaders

func (c CreateOptions) ToHeaders() *client.Headers

func (CreateOptions) ToOData

func (c CreateOptions) ToOData() *odata.Query

func (CreateOptions) ToQuery

func (c CreateOptions) ToQuery() *client.QueryParams

type CreateResponse

type CreateResponse struct {
	HttpResponse *http.Response
}

type DeleteResponse

type DeleteResponse struct {
	HttpResponse *http.Response
}

type FileId added in v0.22.0

type FileId struct {
	// AccountId specifies the ID of the Storage Account where this File exists.
	AccountId accounts.AccountId

	// ShareName specifies the name of the File Share containing this File.
	ShareName string

	// DirectoryPath specifies the path representing the Directory where this File exists.
	DirectoryPath string

	// FileName specifies the name of the File.
	FileName string
}

func NewFileID added in v0.22.0

func NewFileID(accountId accounts.AccountId, shareName, directoryPath, fileName string) FileId

func ParseFileID added in v0.22.0

func ParseFileID(input, domainSuffix string) (*FileId, error)

ParseFileID parses `input` into a File ID using a known `domainSuffix`

func (FileId) ID added in v0.22.0

func (b FileId) ID() string

func (FileId) String added in v0.22.0

func (b FileId) String() string

type GetByteRangeInput

type GetByteRangeInput struct {
	StartBytes int64
	EndBytes   int64
}

type GetByteRangeOptions

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

func (GetByteRangeOptions) ToHeaders

func (g GetByteRangeOptions) ToHeaders() *client.Headers

func (GetByteRangeOptions) ToOData

func (g GetByteRangeOptions) ToOData() *odata.Query

func (GetByteRangeOptions) ToQuery

func (g GetByteRangeOptions) ToQuery() *client.QueryParams

type GetByteRangeResponse

type GetByteRangeResponse struct {
	HttpResponse *http.Response
	Contents     *[]byte
}

type GetFileInput

type GetFileInput struct {
	Parallelism int
}

type GetFileResponse

type GetFileResponse struct {
	HttpResponse *http.Response
	OutputBytes  *[]byte
}

type GetMetaDataResponse

type GetMetaDataResponse struct {
	HttpResponse *http.Response

	MetaData map[string]string
}

type GetMetadataOptions

type GetMetadataOptions struct{}

func (GetMetadataOptions) ToHeaders

func (m GetMetadataOptions) ToHeaders() *client.Headers

func (GetMetadataOptions) ToOData

func (m GetMetadataOptions) ToOData() *odata.Query

func (GetMetadataOptions) ToQuery

func (m GetMetadataOptions) ToQuery() *client.QueryParams

type GetResponse

type GetResponse struct {
	HttpResponse *http.Response

	CacheControl          string
	ContentDisposition    string
	ContentEncoding       string
	ContentLanguage       string
	ContentLength         *int64
	ContentMD5            string
	ContentType           string
	CopyID                string
	CopyStatus            string
	CopySource            string
	CopyProgress          string
	CopyStatusDescription string
	CopyCompletionTime    string
	Encrypted             bool

	MetaData map[string]string
}

type ListRangeOptions

type ListRangeOptions struct{}

func (ListRangeOptions) ToHeaders

func (l ListRangeOptions) ToHeaders() *client.Headers

func (ListRangeOptions) ToOData

func (l ListRangeOptions) ToOData() *odata.Query

func (ListRangeOptions) ToQuery

func (l ListRangeOptions) ToQuery() *client.QueryParams

type ListRangesResponse

type ListRangesResponse struct {
	HttpResponse *http.Response

	Ranges []Range `xml:"Range"`
}

type PutByteRangeInput

type PutByteRangeInput struct {
	StartBytes int64
	EndBytes   int64

	// Content is the File Contents for the specified range
	// which can be at most 4MB
	Content []byte
}

type PutRangeOptions

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

func (PutRangeOptions) ToHeaders

func (p PutRangeOptions) ToHeaders() *client.Headers

func (PutRangeOptions) ToOData

func (p PutRangeOptions) ToOData() *odata.Query

func (PutRangeOptions) ToQuery

func (p PutRangeOptions) ToQuery() *client.QueryParams

type PutRangeResponse

type PutRangeResponse struct {
	HttpResponse *http.Response
}

type Range

type Range struct {
	Start string `xml:"Start"`
	End   string `xml:"End"`
}

type SetMetaDataInput

type SetMetaDataInput struct {
	MetaData map[string]string
}

type SetMetaDataOptions

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

func (SetMetaDataOptions) ToHeaders

func (s SetMetaDataOptions) ToHeaders() *client.Headers

func (SetMetaDataOptions) ToOData

func (s SetMetaDataOptions) ToOData() *odata.Query

func (SetMetaDataOptions) ToQuery

func (s SetMetaDataOptions) ToQuery() *client.QueryParams

type SetMetaDataResponse

type SetMetaDataResponse struct {
	HttpResponse *http.Response
}

type SetPropertiesInput

type SetPropertiesInput struct {
	// Resizes a file to the specified size.
	// If the specified byte value is less than the current size of the file,
	// then all ranges above the specified byte value are cleared.
	ContentLength int64

	// Modifies the cache control string for the file.
	// If this property is not specified on the request, then the property will be cleared for the file.
	// Subsequent calls to Get File Properties will not return this property,
	// unless it is explicitly set on the file again.
	ContentControl *string

	// Sets the file’s Content-Disposition header.
	// If this property is not specified on the request, then the property will be cleared for the file.
	// Subsequent calls to Get File Properties will not return this property,
	// unless it is explicitly set on the file again.
	ContentDisposition *string

	// Sets the file's content encoding.
	// If this property is not specified on the request, then the property will be cleared for the file.
	// Subsequent calls to Get File Properties will not return this property,
	// unless it is explicitly set on the file again.
	ContentEncoding *string

	// Sets the file's content language.
	// If this property is not specified on the request, then the property will be cleared for the file.
	// Subsequent calls to Get File Properties will not return this property,
	// unless it is explicitly set on the file again.
	ContentLanguage *string

	// Sets the file's MD5 hash.
	// If this property is not specified on the request, then the property will be cleared for the file.
	// Subsequent calls to Get File Properties will not return this property,
	// unless it is explicitly set on the file again.
	ContentMD5 *string

	// Sets the file's content type.
	// If this property is not specified on the request, then the property will be cleared for the file.
	// Subsequent calls to Get File Properties will not return this property,
	// unless it is explicitly set on the file again.
	ContentType *string

	// The time at which this file was created at - if omitted, this'll be set to "now"
	// This maps to the `x-ms-file-creation-time` field.
	CreatedAt *time.Time

	// The time at which this file was last modified - if omitted, this'll be set to "now"
	// This maps to the `x-ms-file-last-write-time` field.
	LastModified *time.Time

	// MetaData is a mapping of key value pairs which should be assigned to this file
	MetaData map[string]string
}

type SetPropertiesOptions

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

func (SetPropertiesOptions) ToHeaders

func (s SetPropertiesOptions) ToHeaders() *client.Headers

func (SetPropertiesOptions) ToOData

func (s SetPropertiesOptions) ToOData() *odata.Query

func (SetPropertiesOptions) ToQuery

type SetPropertiesResponse

type SetPropertiesResponse struct {
	HttpResponse *http.Response
}

type StorageFile

type StorageFile interface {
	PutByteRange(ctx context.Context, shareName string, path string, fileName string, input PutByteRangeInput) (PutRangeResponse, error)
	GetByteRange(ctx context.Context, shareName string, path string, fileName string, input GetByteRangeInput) (GetByteRangeResponse, error)
	ClearByteRange(ctx context.Context, shareName string, path string, fileName string, input ClearByteRangeInput) (ClearByteRangeResponse, error)
	SetProperties(ctx context.Context, shareName string, path string, fileName string, input SetPropertiesInput) (SetPropertiesResponse, error)
	PutFile(ctx context.Context, shareName string, path string, fileName string, file *os.File, parallelism int) error
	Copy(ctx context.Context, shareName, path, fileName string, input CopyInput) (CopyResponse, error)
	SetMetaData(ctx context.Context, shareName string, path string, fileName string, input SetMetaDataInput) (SetMetaDataResponse, error)
	GetMetaData(ctx context.Context, shareName string, path string, fileName string) (GetMetaDataResponse, error)
	AbortCopy(ctx context.Context, shareName string, path string, fileName string, input CopyAbortInput) (CopyAbortResponse, error)
	GetFile(ctx context.Context, shareName string, path string, fileName string, input GetFileInput) (GetFileResponse, error)
	ListRanges(ctx context.Context, shareName, path, fileName string) (ListRangesResponse, error)
	GetProperties(ctx context.Context, shareName string, path string, fileName string) (GetResponse, error)
	Delete(ctx context.Context, shareName string, path string, fileName string) (DeleteResponse, error)
	Create(ctx context.Context, shareName string, path string, fileName string, input CreateInput) (CreateResponse, error)
	CopyAndWait(ctx context.Context, shareName, path, fileName string, input CopyInput) (CopyResponse, error)
}

Jump to

Keyboard shortcuts

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