utils

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: MIT Imports: 39 Imported by: 0

Documentation

Overview

Package utils provides utility functions for the obscure application

Index

Constants

View Source
const (
	KeyLength = 32
)

Variables

This section is empty.

Functions

func CheckIfGCSObjectExists

func CheckIfGCSObjectExists(bucket, object string) (bool, error)

func CheckIfIDriveObjectExists

func CheckIfIDriveObjectExists(bucket, key string) (bool, error)

CheckIfIDriveObjectExists checks if an object exists in IDrive E2

func CheckIfS3CompatibleObjectExists

func CheckIfS3CompatibleObjectExists(providerKey, bucket, key string) (bool, error)

CheckIfS3CompatibleObjectExists checks if an object exists in S3-compatible storage

func CheckIfS3ObjectExists

func CheckIfS3ObjectExists(bucket, key string) (bool, error)

func CheckIfStorjObjectExists

func CheckIfStorjObjectExists(bucket, object string) (bool, error)

func CompressDirectoryToZstd

func CompressDirectoryToZstd(srcDir string) (*bytes.Buffer, error)

CompressDirectoryToZstd creates a .tar.zst archive from a directory

func DecompressZstdToDirectory

func DecompressZstdToDirectory(reader io.Reader, outputDir string) error

DecompressZstdToDirectory extracts a .tar.zst archive into a directory

func DecryptStream

func DecryptStream(encStream io.Reader, password string) (io.Reader, error)

DecryptStream decrypts a streamed .obscure backup from S3. Format assumed: [16-byte salt][12-byte nonce][ciphertext...]

func DeleteFromIDrive

func DeleteFromIDrive(bucket, key string) error

DeleteFromIDrive deletes an object from IDrive E2

func DeleteFromS3Compatible

func DeleteFromS3Compatible(providerKey, bucket, key string) error

DeleteFromS3Compatible deletes an object from S3-compatible storage

func DeriveKey

func DeriveKey(password string, salt []byte) ([]byte, error)

func DownloadFromB2Stream

func DownloadFromB2Stream(objectKey string) (io.ReadCloser, int64, error)

DownloadFromB2Stream downloads a file from B2 and returns a reader and file size

func DownloadFromGCSStream

func DownloadFromGCSStream(objectKey string) (io.ReadCloser, int64, error)

func DownloadFromIDriveStream

func DownloadFromIDriveStream(bucket, key string) (io.ReadCloser, error)

DownloadFromIDriveStream downloads a file from IDrive E2 and returns a reader

func DownloadFromS3CompatibleStream

func DownloadFromS3CompatibleStream(providerKey, bucket, key string) (io.ReadCloser, error)

DownloadFromS3CompatibleStream downloads a file from S3-compatible storage and returns a reader

func DownloadFromS3Stream

func DownloadFromS3Stream(bucket, key string) (io.ReadCloser, error)

func DownloadFromStorjStream

func DownloadFromStorjStream(bucket, object string) (io.ReadCloser, error)

func EncryptBuffer

func EncryptBuffer(plainBuf *bytes.Buffer, password string) (*bytes.Buffer, error)

func EncryptStream

func EncryptStream(w io.Writer, password string) (io.WriteCloser, error)

EncryptStream creates a writer that encrypts data using AES-GCM

func ExtractSaltFromEncryptedFile

func ExtractSaltFromEncryptedFile(filepath string) ([]byte, error)

func ExtractTarArchive

func ExtractTarArchive(reader io.Reader, outputDir string) error

ExtractTarArchive extracts a tar archive from a reader to the specified directory

func FetchUserDefaultProvider

func FetchUserDefaultProvider(email string) (string, error)

func GenerateSalt

func GenerateSalt() ([]byte, error)

func GetGCSClient

func GetGCSClient() (*storage.Client, error)

func GetIDriveClient

func GetIDriveClient() (*s3.Client, error)

GetIDriveClient creates an S3 client configured for IDrive E2

func GetIDriveObjectSize

func GetIDriveObjectSize(bucket, key string) (int64, error)

GetIDriveObjectSize gets the size of an object in IDrive E2

func GetObjectSize

func GetObjectSize(bucket, key string) (int64, error)

func GetS3Client

func GetS3Client() *s3.Client

func GetS3CompatibleClient

func GetS3CompatibleClient(providerKey string) (*s3.Client, error)

GetS3CompatibleClient creates an S3 client configured for any S3-compatible service

func GetS3CompatibleObjectSize

func GetS3CompatibleObjectSize(providerKey, bucket, key string) (int64, error)

GetS3CompatibleObjectSize gets the size of an object in S3-compatible storage

func GetStorjObjectSize

func GetStorjObjectSize(bucket, object string) (int64, error)

func GetUserID

func GetUserID() (string, error)

GetUserID retrieves the AWS user ID using STS

func ListIDriveObjects

func ListIDriveObjects(bucket, prefix string) ([]string, error)

ListIDriveObjects lists objects in IDrive E2 with a prefix

func ListS3CompatibleObjects

func ListS3CompatibleObjects(providerKey, bucket, prefix string) ([]string, error)

ListS3CompatibleObjects lists objects in S3-compatible storage with a prefix

func NewCompressWriter

func NewCompressWriter(w io.Writer) io.WriteCloser

NewCompressWriter creates a zstd compression writer

func PromptEmail

func PromptEmail(prompt string) (string, error)

PromptEmail prompts for an email address

func PromptForCloudProvider

func PromptForCloudProvider() (string, error)

func PromptLine

func PromptLine(prompt string) (string, error)

PromptLine prompts for a single line of input

func PromptPassword

func PromptPassword(prompt string) (string, error)

PromptPassword prompts for a password

func PromptPasswordConfirm

func PromptPasswordConfirm(prompt string) (string, error)

PromptPasswordConfirm prompts for a password and confirmation, returning the password if they match

func PromptUsername

func PromptUsername(prompt string) (string, error)

func ReadDirectoryAsBytes

func ReadDirectoryAsBytes(dirPath string) ([]byte, error)

ReadDirectoryAsBytes reads a directory and returns its contents as a byte slice

func UploadToGCSBackend

func UploadToGCSBackend(encryptedData []byte, username, tag, version, backendURL, authToken string, isDirect bool) error

func UploadToIDrive

func UploadToIDrive(bucket, key string, reader io.Reader, metadata map[string]string) error

UploadToIDrive uploads a file to IDrive E2

func UploadToS3Compatible

func UploadToS3Compatible(providerKey, bucket, key string, reader io.Reader, metadata map[string]string) error

UploadToS3Compatible uploads a file to S3-compatible storage

Types

type BackupInfo

type BackupInfo struct {
	Key      string
	Size     int64
	Modified time.Time
	Metadata map[string]string
}

type ProgressBuffer

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

func NewProgressBuffer

func NewProgressBuffer(data []byte, description string, barWidth int) *ProgressBuffer

func (*ProgressBuffer) Read

func (pb *ProgressBuffer) Read(p []byte) (int, error)

func (*ProgressBuffer) Seek

func (pb *ProgressBuffer) Seek(offset int64, whence int) (int64, error)

type ProgressReader

type ProgressReader struct {
	Reader      io.Reader
	Description string
	TotalBytes  int64
	ReadBytes   int64
	BarWidth    int
	LastPrint   time.Time
	StartTime   time.Time // Add start time tracking
}

func NewProgressReader

func NewProgressReader(r io.Reader, totalBytes int64, description string, barWidth int) *ProgressReader

func (*ProgressReader) Read

func (pr *ProgressReader) Read(p []byte) (int, error)

type ProgressWriter

type ProgressWriter struct {
	Writer      io.Writer
	Description string
	BarWidth    int
	TotalBytes  int64
	// contains filtered or unexported fields
}

func NewProgressWriter

func NewProgressWriter(w io.Writer, description string, barWidth int, totalBytes int64) *ProgressWriter

func (*ProgressWriter) Write

func (pw *ProgressWriter) Write(p []byte) (int, error)

type StorageProvider

type StorageProvider interface {
	Upload(filePath string, metadata map[string]string) (string, error)
	Download(objectKey string, destinationPath string) error
	List(prefix string) ([]BackupInfo, error)
}

Jump to

Keyboard shortcuts

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