downloader

package
v7.25.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 34 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetURLStrings added in v7.23.0

func GetURLStrings(ctx context.Context, provider DownloadURLsProvider, objectName string, options *GenerateOptions) ([]string, error)

GetURLStrings 从 DownloadURLsProvider 读取出所有 URL 并转换成字符串返回

func GetURLs added in v7.23.0

func GetURLs(ctx context.Context, provider DownloadURLsProvider, objectName string, options *GenerateOptions) ([]*url.URL, error)

GetURLs 从 DownloadURLsProvider 读取出所有 URL 返回

Types

type ConcurrentDownloaderOptions

type ConcurrentDownloaderOptions struct {
	DownloaderOptions
	Concurrency       uint                                // 并发度
	PartSize          uint64                              // 分片大小
	ResumableRecorder resumablerecorder.ResumableRecorder // 可恢复记录仪
}

并发下载器选项

type DefaultSrcURLsProviderOptions

type DefaultSrcURLsProviderOptions struct {
	region.BucketRegionsQueryOptions

	// Bucket 服务器地址
	BucketHosts region.Endpoints
}

默认源站域名下载 URL 生成器选项

type DestinationDownloadOptions

type DestinationDownloadOptions struct {
	// 对象下载附加 HTTP Header
	Header http.Header
	// 对象下载进度
	OnDownloadingProgress func(*DownloadingProgress)
	// 对象 Header 获取回调
	OnResponseHeader func(http.Header)
}

目标下载选项

type DestinationDownloader

type DestinationDownloader interface {
	Download(context.Context, URLsIter, destination.Destination, *DestinationDownloadOptions) (uint64, error)
}

目标下载器

func NewConcurrentDownloader

func NewConcurrentDownloader(options *ConcurrentDownloaderOptions) DestinationDownloader

创建并发下载器

type DirectoryOptions

type DirectoryOptions struct {
	// 是否使用 HTTP 协议,默认为不使用
	UseInsecureProtocol bool

	// 空间名称
	BucketName string

	// 对象前缀
	ObjectPrefix string

	// 下载并发度
	ObjectConcurrency int

	// 下载 URL 生成器
	DownloadURLsProvider DownloadURLsProvider

	// 下载前回调函数
	BeforeObjectDownload func(objectName string, objectOptions *ObjectOptions)

	// 下载进度
	OnDownloadingProgress func(objectName string, progress *DownloadingProgress)

	// 对象下载成功后回调
	OnObjectDownloaded func(objectName string, info *DownloadedObjectInfo)

	// 是否下载指定对象
	ShouldDownloadObject func(objectName string) bool

	// 分隔符,默认为 /
	PathSeparator string
}

目录下载参数

type DomainsQueryURLsProviderOptions

type DomainsQueryURLsProviderOptions struct {
	http_client.Options

	// 压缩周期(默认:60s)
	CompactInterval time.Duration

	// 持久化路径(默认:$TMPDIR/qiniu-golang-sdk/domain_v2_01.cache.json)
	PersistentFilePath string

	// 持久化周期(默认:60s)
	PersistentDuration time.Duration

	// 缓存有效周期(默认:3600s)
	CacheTTL time.Duration

	// 缓存刷新时间(默认:1800s)
	CacheRefreshAfter time.Duration
}

基于域名查询的下载 URL 生成器选项

type DownloadManager

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

下载管理器

func NewDownloadManager

func NewDownloadManager(options *DownloadManagerOptions) *DownloadManager

创建下载管理器

func (*DownloadManager) DownloadDirectory

func (downloadManager *DownloadManager) DownloadDirectory(ctx context.Context, targetDirPath string, options *DirectoryOptions) error

下载目录

func (*DownloadManager) DownloadToFile

func (downloadManager *DownloadManager) DownloadToFile(ctx context.Context, objectName, filePath string, options *ObjectOptions) (uint64, error)

下载对象到文件

func (*DownloadManager) DownloadToWriter

func (downloadManager *DownloadManager) DownloadToWriter(ctx context.Context, objectName string, writer io.Writer, options *ObjectOptions) (uint64, error)

下载对象到 io.Writer

type DownloadManagerOptions

type DownloadManagerOptions struct {
	// HTTP 客户端选项
	httpclient.Options

	// 目标下载器
	DestinationDownloader DestinationDownloader

	// 分片列举版本,如果不填写,默认为 V1
	ListerVersion objects.ListerVersion

	// 下载 URL 生成器
	DownloadURLsProvider DownloadURLsProvider
}

下载管理器选项

type DownloadURLsProvider

type DownloadURLsProvider interface {
	GetURLsIter(context.Context, string, *GenerateOptions) (URLsIter, error)
}

获取对象下载 URL 接口

func CombineDownloadURLsProviders

func CombineDownloadURLsProviders(providers ...DownloadURLsProvider) DownloadURLsProvider

合并多个下载 URL 生成器

func NewDefaultSrcURLsProvider

func NewDefaultSrcURLsProvider(accessKey string, options *DefaultSrcURLsProviderOptions) DownloadURLsProvider

创建默认源站域名下载 URL 生成器

func NewDomainsQueryURLsProvider

func NewDomainsQueryURLsProvider(options *DomainsQueryURLsProviderOptions) (DownloadURLsProvider, error)

创建基于域名查询的下载 URL 生成器

func NewStaticDomainBasedURLsProvider

func NewStaticDomainBasedURLsProvider(domains []string) DownloadURLsProvider

创建静态域名下载 URL 生成器

func SignURLsProvider

func SignURLsProvider(provider DownloadURLsProvider, signer Signer, options *SignOptions) DownloadURLsProvider

为下载 URL 获取结果签名

type DownloadedObjectInfo

type DownloadedObjectInfo struct {
	Size uint64 // 对象大小
}

已经下载的对象信息

type DownloaderOptions

type DownloaderOptions struct {
	Client   clientv2.Client   // HTTP 客户端,如果不配置则使用默认的 HTTP 客户端
	RetryMax int               // 最大重试次数,如果不配置,默认为 9
	Backoff  backoff.Backoff   // 重试时间间隔 v2,优先级高于 RetryInterval
	Resolver resolver.Resolver // 主备域名解析器
	Chooser  chooser.Chooser   // IP 选择器

	BeforeResolve func(*http.Request)                                         // 域名解析前回调函数
	AfterResolve  func(*http.Request, []net.IP)                               // 域名解析后回调函数
	ResolveError  func(*http.Request, error)                                  // 域名解析错误回调函数
	BeforeBackoff func(*http.Request, *retrier.RetrierOptions, time.Duration) // 退避前回调函数
	AfterBackoff  func(*http.Request, *retrier.RetrierOptions, time.Duration) // 退避后回调函数
	BeforeRequest func(*http.Request, *retrier.RetrierOptions)                // 请求前回调函数
	AfterResponse func(*http.Response, *retrier.RetrierOptions, error)        // 请求后回调函数
}

下载器选项

type DownloadingProgress

type DownloadingProgress struct {
	Downloaded uint64 // 已经下载的数据量,单位为字节
	TotalSize  uint64 // 总数据量,单位为字节
}

下载进度

type GenerateOptions

type GenerateOptions struct {
	// 空间名称,可选
	BucketName string

	// 文件处理命令,可选
	Command string

	// 是否使用 HTTP 协议,默认为不使用
	UseInsecureProtocol bool
}

对象下载 URL 生成选项

type ObjectOptions

type ObjectOptions struct {
	DestinationDownloadOptions
	GenerateOptions

	// 下载 URL 生成器
	DownloadURLsProvider DownloadURLsProvider
}

对象下载参数

type SignOptions

type SignOptions struct {
	// 签名有效期,如果不填写,默认为 3 分钟
	TTL time.Duration
}

对象签名选项

type Signer

type Signer interface {
	Sign(context.Context, *url.URL, *SignOptions) error
}

对下载 URL 签名

func NewCredentialsSigner

func NewCredentialsSigner(credentials credentials.CredentialsProvider) Signer

创建基于七牛鉴权的下载 URL 签名

type URLsIter

type URLsIter interface {
	// 获取首个 URL
	Peek(*url.URL) (bool, error)
	// 切换到下一个 URL
	Next()
	// 重置迭代器
	Reset()
	// 复制迭代器
	Clone() URLsIter
}

获取 URL 迭代器

func NewURLsIter

func NewURLsIter(urls []*url.URL) URLsIter

将 URL 列表转换为迭代器

func SignURLs

func SignURLs(ctx context.Context, urlsIter URLsIter, signer Signer, options *SignOptions) URLsIter

为 URL 列表签名

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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