Versions in this module Expand all Collapse all v0 v0.2.1 Sep 26, 2026 v0.2.0 Sep 22, 2026 Changes in this version + const DefaultChunkSize + var ErrAlreadyExists = errors.New("binary: already exists") + var ErrInvalidArgument = errors.New("binary: invalid argument") + var ErrNotFound = errors.New("binary: not found") + var ErrRetentionLocked = errors.New("binary: retention locked") + var ErrSessionClosed = errors.New("binary: session closed") + var ErrUnsupported = errors.New("binary: unsupported") + var ErrUploadIncomplete = errors.New("binary: upload incomplete") + func AsStore(blobs BlobStore) store.BlobStore + func BuildAttachmentMetadata(contentType string, ref BlobReference) (map[string]interface{}, error) + func BuildBinaryMetadataJSON(id, contentType string, ref BlobReference) ([]byte, error) + func ChunkBytes(data []byte, size int) [][]byte + func CopyChunks(r io.Reader, size int, write func(index int, chunk []byte) error) (digest string, total int64, count int, err error) + func EmbedDocumentAttachment(docJSON []byte, contentIndex int, contentType string, ref BlobReference) ([]byte, error) + func FileObjectKey(prefix, path string) (string, error) + func HashReaderSHA256(r io.Reader) (string, error) + func HashSHA256(data []byte) string + func IsBlobMissing(err error) bool + func MarshalPointerJSON(p StoragePointer) ([]byte, error) + func ResourceHasPayloadBytes(data []byte) bool + type BackendKind string + const BackendLocalFile + const BackendPostgres + const BackendS3 + const BackendSQLite + type BinaryLink struct + BlobID string + CreatedAt time.Time + ResourceID string + type BlobDescriptor struct + Backend BackendKind + BlobID string + ContentType string + Encryption *BlobEncryption + Pointer StoragePointer + Retention *BlobRetention + SHA256 string + Size int64 + func PutBlobStream(ctx context.Context, blobs BlobStore, blobID string, r io.Reader, size int64, ...) (*BlobDescriptor, error) + type BlobEncryption struct + Algorithm EncryptionAlgorithm + KeyID string + Nonce string + type BlobManifest struct + ChunkCount int + ChunkSize int64 + CreatedAt time.Time + Descriptor BlobDescriptor + FinalizedAt *time.Time + type BlobReference struct + BlobID string + ContentType string + Pointer StoragePointer + SHA256 string + Size int64 + func DescriptorToReference(desc BlobDescriptor) BlobReference + func ExtractBinaryBlobRef(data []byte) (*BlobReference, error) + func ExtractBlobReferences(data []byte) ([]BlobReference, error) + type BlobRetention struct + Mode RetentionMode + RetainUntil time.Time + type BlobStore interface + Delete func(ctx context.Context, blobID string) error + Get func(ctx context.Context, blobID string) ([]byte, *BlobDescriptor, error) + Head func(ctx context.Context, blobID string) (*BlobDescriptor, error) + Put func(ctx context.Context, blobID string, data []byte, contentType string) (*BlobDescriptor, error) + func NewLocalFileBlobStoreAdapter(files *LocalFileBlobStore, manifest MetadataStore) BlobStore + type BlobStoreWithOpen interface + Open func(ctx context.Context, blobID string) (io.ReadCloser, *BlobDescriptor, error) + type BlobStoreWithOptions interface + PutWithOptions func(ctx context.Context, blobID string, data []byte, opts BlobWriteOptions) (*BlobDescriptor, error) + type BlobStoreWithStream interface + PutStream func(ctx context.Context, blobID string, r io.Reader, size int64, ...) (*BlobDescriptor, error) + type BlobSyncStatus string + const SyncComplete + const SyncDownloading + const SyncFailed + const SyncPending + const SyncUploaded + const SyncUploading + type BlobWriteOptions struct + ContentType string + Retention *BlobRetention + type ChunkReader struct + func NewChunkReader(ctx context.Context, count int, ...) *ChunkReader + func (r *ChunkReader) Close() error + func (r *ChunkReader) Read(p []byte) (int, error) + type ChunkStore interface + AppendChunk func(ctx context.Context, key string, index int, data []byte) error + DeleteChunks func(ctx context.Context, key string) error + ListChunkCount func(ctx context.Context, key string) (int, error) + ReadChunk func(ctx context.Context, key string, index int) ([]byte, error) + type ChunkSyncPlan struct + BlobID string + ChunkCount int + ChunkSize int64 + ContentType string + CreatedAt time.Time + SHA256 string + Size int64 + type ChunkSyncService struct + func NewChunkSyncService(transfers *TransferService) (*ChunkSyncService, error) + func (s *ChunkSyncService) ApplyChunk(ctx context.Context, sessionID string, chunk SyncChunk) (*UploadSession, error) + func (s *ChunkSyncService) ExportChunk(ctx context.Context, blobID string, index int) (*SyncChunk, error) + func (s *ChunkSyncService) ExportPlan(ctx context.Context, blobID string) (*ChunkSyncPlan, error) + func (s *ChunkSyncService) FinalizeImport(ctx context.Context, sessionID string) (*BlobManifest, error) + func (s *ChunkSyncService) StartImport(ctx context.Context, plan ChunkSyncPlan, encryptionKeyID string, ...) (*UploadSession, error) + type DocumentAttachmentLink struct + BlobID string + ContentIndex int + CreatedAt time.Time + DocumentID string + type DownloadSession struct + BlobID string + ChunkSize int64 + CreatedAt time.Time + DownloadedBytes int64 + DownloadedChunks int + ID string + Status BlobSyncStatus + TotalChunks int + UpdatedAt time.Time + type EncryptionAlgorithm string + const EncryptionAES256GCM + const EncryptionNone + type KeyResolver func(ctx context.Context, keyID string) ([]byte, error) + type LifecycleService struct + func NewLifecycleService(blobs BlobStore, meta MetadataStore) (*LifecycleService, error) + func (s *LifecycleService) DeleteBlob(ctx context.Context, blobID string, now time.Time) error + type LinkService struct + func NewLinkService(meta MetadataStore) *LinkService + func (s *LinkService) DeleteBinaryLink(ctx context.Context, resourceID string) error + func (s *LinkService) DeleteDocumentAttachmentLink(ctx context.Context, documentID string, contentIndex int) error + func (s *LinkService) GetBinaryLink(ctx context.Context, resourceID string) (*BinaryLink, error) + func (s *LinkService) GetDocumentAttachmentLink(ctx context.Context, documentID string, contentIndex int) (*DocumentAttachmentLink, error) + func (s *LinkService) LinkBinary(ctx context.Context, resourceID, blobID string) error + func (s *LinkService) LinkDocumentAttachment(ctx context.Context, documentID string, contentIndex int, blobID string) error + type LocalFileBlobStore struct + func NewLocalFileBlobStore(root string) (*LocalFileBlobStore, error) + func (s *LocalFileBlobStore) AppendChunk(ctx context.Context, key string, index int, data []byte) error + func (s *LocalFileBlobStore) AssembleChunks(ctx context.Context, key string) ([]byte, error) + func (s *LocalFileBlobStore) Delete(ctx context.Context, sha256 string) error + func (s *LocalFileBlobStore) DeleteChunks(ctx context.Context, key string) error + func (s *LocalFileBlobStore) FinalizeChunks(ctx context.Context, key string, blobID string, contentType string) (*BlobManifest, error) + func (s *LocalFileBlobStore) Get(ctx context.Context, blobID string, sha256 string) ([]byte, error) + func (s *LocalFileBlobStore) GetByHash(ctx context.Context, sha256 string) ([]byte, error) + func (s *LocalFileBlobStore) Head(ctx context.Context, blobID string, sha256 string, contentType string) (*BlobDescriptor, error) + func (s *LocalFileBlobStore) ListChunkCount(ctx context.Context, key string) (int, error) + func (s *LocalFileBlobStore) OpenBlob(sha256 string) (io.ReadCloser, error) + func (s *LocalFileBlobStore) Put(ctx context.Context, blobID string, data []byte, contentType string) (*BlobDescriptor, error) + func (s *LocalFileBlobStore) PutStream(ctx context.Context, blobID string, r io.Reader, size int64, ...) (*BlobDescriptor, error) + func (s *LocalFileBlobStore) ReadChunk(ctx context.Context, key string, index int) ([]byte, error) + type MetadataStore interface + DeleteBinaryLink func(ctx context.Context, resourceID string) error + DeleteDocumentLink func(ctx context.Context, documentID string, contentIndex int) error + DeleteManifest func(ctx context.Context, blobID string) error + DeleteSyncStatus func(ctx context.Context, blobID string) error + GetBinaryLink func(ctx context.Context, resourceID string) (*BinaryLink, error) + GetDocumentLink func(ctx context.Context, documentID string, contentIndex int) (*DocumentAttachmentLink, error) + GetManifest func(ctx context.Context, blobID string) (*BlobManifest, error) + GetManifestByHash func(ctx context.Context, sha256 string) (*BlobManifest, error) + GetSyncStatus func(ctx context.Context, blobID string) (BlobSyncStatus, error) + PutBinaryLink func(ctx context.Context, link BinaryLink) error + PutDocumentLink func(ctx context.Context, link DocumentAttachmentLink) error + PutManifest func(ctx context.Context, manifest BlobManifest) error + PutSyncStatus func(ctx context.Context, blobID string, status BlobSyncStatus) error + func MetadataFromWriteSession(ws store.WriteSession) (MetadataStore, bool) + type PrefixedFileStore struct + func NewPrefixedFileStore(blobs store.BlobStore, prefix, pkgName, defaultContentType string) *PrefixedFileStore + func (s *PrefixedFileStore) Delete(ctx context.Context, path string) error + func (s *PrefixedFileStore) Get(ctx context.Context, path string) ([]byte, string, error) + func (s *PrefixedFileStore) Open(ctx context.Context, path string) (io.ReadCloser, string, error) + func (s *PrefixedFileStore) Put(ctx context.Context, path string, data []byte, contentType string) error + func (s *PrefixedFileStore) PutStream(ctx context.Context, path string, r io.Reader, size int64, contentType string) error + type RetentionMode string + const RetentionCompliance + const RetentionGovernance + const RetentionNone + type S3BlobStore struct + func NewS3BlobStore(cfg S3Config) (*S3BlobStore, error) + func (s *S3BlobStore) Delete(ctx context.Context, blobID string) error + func (s *S3BlobStore) Get(ctx context.Context, blobID string) ([]byte, *BlobDescriptor, error) + func (s *S3BlobStore) Head(ctx context.Context, blobID string) (*BlobDescriptor, error) + func (s *S3BlobStore) Open(ctx context.Context, blobID string) (io.ReadCloser, *BlobDescriptor, error) + func (s *S3BlobStore) Put(ctx context.Context, blobID string, data []byte, contentType string) (*BlobDescriptor, error) + func (s *S3BlobStore) PutStream(ctx context.Context, blobID string, r io.Reader, size int64, ...) (*BlobDescriptor, error) + func (s *S3BlobStore) PutWithOptions(ctx context.Context, blobID string, data []byte, opts BlobWriteOptions) (*BlobDescriptor, error) + func (s *S3BlobStore) SignedGetURL(ctx context.Context, blobID string, ttl time.Duration) (*SignedAccessURL, error) + func (s *S3BlobStore) SignedPutURL(ctx context.Context, blobID string, ttl time.Duration, contentType string) (*SignedAccessURL, error) + type S3Config struct + AccessKeyID string + Bucket string + Endpoint string + HTTPClient *http.Client + Region string + SecretAccessKey string + SessionToken string + UsePathStyle bool + type SignedAccessURL struct + ExpiresAt time.Time + Headers map[string]string + Method string + URL string + type SignedURLProvider interface + SignedGetURL func(ctx context.Context, blobID string, ttl time.Duration) (*SignedAccessURL, error) + SignedPutURL func(ctx context.Context, blobID string, ttl time.Duration, contentType string) (*SignedAccessURL, error) + type StoragePointer struct + Backend BackendKind + Ref string + func UnmarshalPointerJSON(data []byte) (StoragePointer, error) + type SyncChunk struct + BlobID string + Data []byte + Index int + TotalChunks int + type TransferConfig struct + Blobs BlobStore + ChunkSize int64 + Chunks ChunkStore + Metadata MetadataStore + ResolveKey KeyResolver + Transfers TransferStore + type TransferKind string + const TransferDownload + const TransferUpload + type TransferService struct + func NewTransferService(cfg TransferConfig) (*TransferService, error) + func (s *TransferService) DownloadChunk(ctx context.Context, sessionID string, index int) ([]byte, *DownloadSession, error) + func (s *TransferService) FinalizeUpload(ctx context.Context, sessionID string) (*BlobManifest, error) + func (s *TransferService) MarkSyncPending(ctx context.Context, blobID string) error + func (s *TransferService) ReadBlob(ctx context.Context, blobID string) ([]byte, *BlobManifest, error) + func (s *TransferService) StartDownload(ctx context.Context, blobID string) (*DownloadSession, error) + func (s *TransferService) StartUpload(ctx context.Context, blobID string, size int64, contentType string, ...) (*UploadSession, error) + func (s *TransferService) StartUploadWithOptions(ctx context.Context, req UploadRequest) (*UploadSession, error) + func (s *TransferService) UploadChunk(ctx context.Context, sessionID string, index int, data []byte) (*UploadSession, error) + type TransferStore interface + CreateDownloadSession func(ctx context.Context, session DownloadSession) error + CreateUploadSession func(ctx context.Context, session UploadSession) error + DeleteDownloadSession func(ctx context.Context, id string) error + DeleteUploadSession func(ctx context.Context, id string) error + GetDownloadSession func(ctx context.Context, id string) (*DownloadSession, error) + GetUploadSession func(ctx context.Context, id string) (*UploadSession, error) + UpdateDownloadSession func(ctx context.Context, session DownloadSession) error + UpdateUploadSession func(ctx context.Context, session UploadSession) error + type UploadRequest struct + BlobID string + ContentType string + EncryptionKeyID string + ExpectedChunks int + Retention *BlobRetention + Size int64 + type UploadSession struct + BlobID string + ChunkSize int64 + ContentType string + CreatedAt time.Time + Encryption *BlobEncryption + ExpectedChunks int + ID string + Retention *BlobRetention + SHA256 string + Size int64 + Status BlobSyncStatus + UpdatedAt time.Time + UploadedBytes int64 + UploadedChunks int + type WriteSessionExtension interface + BinaryMetadataStore func() MetadataStore