buckets

package
v0.0.0-...-8c3b319 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const API = "https://api.internxt.com"

Variables

This section is empty.

Functions

func CalculateFileHash

func CalculateFileHash(reader io.Reader) (string, error)

Calculates the hash of a file

func DecryptReader

func DecryptReader(src io.Reader, key, iv []byte) (io.Reader, error)

DecryptReader wraps the provided src reader in a StreamReader that decrypts data encrypted with AES‑256‑CTR (no padding):

encryptedSrc -> source -> …

func DownloadFile

func DownloadFile(cfg *config.Config, fileID, destPath string) error

DownloadFile downloads and decrypts the first shard of the given file.

func DownloadFileStream

func DownloadFileStream(cfg *config.Config, fileUUID string, optionalRange ...string) (io.ReadCloser, error)

DownloadFileStream returns a ReadCloser that streams the decrypted contents of the file with the given UUID. The caller must close the returned ReadCloser. It takes an optional range header in the format of either "bytes=100-199" or "bytes=100-".

func EncryptReader

func EncryptReader(src io.Reader, key, iv []byte) (io.Reader, error)

EncryptReader wraps the provided src reader in a StreamReader that encrypts all data through AES‑256‑CTR (no padding):

source -> cipher -> …

func GenerateBucketKey

func GenerateBucketKey(mnem string, bucketID []byte) (string, error)

GenerateBucketKey generates a 64-character hexadecimal bucket key from a mnemonic and bucket ID.

func GenerateFileBucketKey

func GenerateFileBucketKey(mnemonic, bucketID string) ([]byte, error)

GenerateFileBucketKey derives a bucket-level key from mnemonic and bucketID

func GenerateFileKey

func GenerateFileKey(mnemonic, bucketID, indexHex string) (key, iv []byte, err error)

GenerateFileKey derives the per-file key and IV from mnemonic, bucketID, and plaintext index

func GetDeterministicKey

func GetDeterministicKey(key []byte, data []byte) ([]byte, error)

func GetFileDeterministicKey

func GetFileDeterministicKey(key, data []byte) []byte

GetFileDeterministicKey returns SHA512(key||data)

func NewAES256CTRCipher

func NewAES256CTRCipher(key, iv []byte) (cipher.Stream, error)

NewAES256CTRCipher returns a cipher.Stream that performs AES‑256‑CTR encryption with the given 32‑byte key and 16‑byte IV, exactly like Node.js’s createCipheriv('aes-256-ctr', key, iv).

func Transfer

func Transfer(part UploadPart, r io.Reader, size int64) error

Types

type BucketFileInfo

type BucketFileInfo struct {
	Bucket   string      `json:"bucket"`
	Index    string      `json:"index"`
	Size     int64       `json:"size"`
	Version  int         `json:"version"`
	Created  string      `json:"created"`
	Renewal  string      `json:"renewal"`
	Mimetype string      `json:"mimetype"`
	Filename string      `json:"filename"`
	ID       string      `json:"id"`
	Shards   []ShardInfo `json:"shards"`
}

BucketFileInfo is the metadata returned by GET /buckets/{bucketID}/files/{fileID}/info

func GetBucketFileInfo

func GetBucketFileInfo(cfg *config.Config, bucketID, fileID string) (*BucketFileInfo, error)

GetBucketFileInfo calls the correct /info endpoint and parses its JSON.

type CreateMetaRequest

type CreateMetaRequest struct {
	Name             string    `json:"name"`
	Bucket           string    `json:"bucket"`
	FileID           string    `json:"fileId"`
	EncryptVersion   string    `json:"encryptVersion"`
	FolderUuid       string    `json:"folderUuid"`
	Size             int64     `json:"size"`
	PlainName        string    `json:"plainName"`
	Type             string    `json:"type"`
	CreationTime     time.Time `json:"creationTime"`
	Date             time.Time `json:"date"`
	ModificationTime time.Time `json:"modificationTime"`
}

type CreateMetaResponse

type CreateMetaResponse struct {
	UUID           string      `json:"uuid"`
	Name           string      `json:"name"`
	Bucket         string      `json:"bucket"`
	FileID         string      `json:"fileId"`
	EncryptVersion string      `json:"encryptVersion"`
	FolderUuid     string      `json:"folderUuid"`
	Size           json.Number `json:"size"`
	PlainName      string      `json:"plainName"`
	Type           string      `json:"type"`
	Created        string      `json:"created"`
}

func CreateMetaFile

func CreateMetaFile(cfg *config.Config, name, bucketID, fileID, encryptVersion, folderUuid, plainName, fileType string, size int64, modTime time.Time) (*CreateMetaResponse, error)

func UploadFile

func UploadFile(cfg *config.Config, filePath, targetFolderUUID string, modTime time.Time) (*CreateMetaResponse, error)

func UploadFileStream

func UploadFileStream(cfg *config.Config, targetFolderUUID, fileName string, in io.Reader, plainSize int64, modTime time.Time) (*CreateMetaResponse, error)

UploadFileStream uploads data from the provided io.Reader into Internxt, encrypting it on the fly and creating the metadata file in the target folder. It returns the CreateMetaResponse of the created file entry.

type FinishUploadResp

type FinishUploadResp struct {
	Bucket   string `json:"bucket"`
	Index    string `json:"index"`
	ID       string `json:"id"`
	Version  int    `json:"version"`
	Created  string `json:"created"`
	Renewal  string `json:"renewal"`
	Mimetype string `json:"mimetype"`
	Filename string `json:"filename"`
}

func FinishUpload

func FinishUpload(cfg *config.Config, bucketID, index string, shards []Shard) (*FinishUploadResp, error)

type Shard

type Shard struct {
	Hash string `json:"hash"`
	UUID string `json:"uuid"`
}

type ShardInfo

type ShardInfo struct {
	Index int    `json:"index"`
	Hash  string `json:"hash"`
	URL   string `json:"url"`
}

ShardInfo mirrors the per‑shard info returned by /files/{fileID}/info

type StartUploadResp

type StartUploadResp struct {
	Uploads []UploadPart `json:"uploads"`
}

func StartUpload

func StartUpload(cfg *config.Config, bucketID string, parts []UploadPartSpec) (*StartUploadResp, error)

StartUpload reserves all parts at once

type UploadPart

type UploadPart struct {
	Index int    `json:"index"`
	UUID  string `json:"uuid"`
	URL   string `json:"url"`
}

type UploadPartSpec

type UploadPartSpec struct {
	Index int   `json:"index"`
	Size  int64 `json:"size"`
}

UploadPartSpec defines each part’s index and size for the start call

Jump to

Keyboard shortcuts

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