rw

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 39 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TypeCompress Type = "compress"

	CompressTypeNop    CompressType = "nop"
	CompressTypeGzip   CompressType = "gzip"
	CompressTypeSnappy CompressType = "snappy"
	CompressTypeZstd   CompressType = "zstd"

	CompressLevelFast   CompressLevel = "fast"
	CompressLevelBetter CompressLevel = "better"
	CompressLevelBest   CompressLevel = "best"
)

Variables

View Source
var (
	ErrChecksumNotMatch = errors.New("checksum not match")

	CreateBase = newBase
)

Functions

func ApplyCommonCfgToRW

func ApplyCommonCfgToRW(rw RW, cfg *ExtraCfg)

func FileExtFromCompressCfg

func FileExtFromCompressCfg(c *CompressCfg) string

func NewCmdCfg

func NewCmdCfg() *cmd.Cfg

func NewGzipReader

func NewGzipReader(r io.ReadCloser, cfg *CompressCfg) io.ReadCloser

func NewGzipWritter

func NewGzipWritter(w io.WriteCloser, cfg *CompressCfg) io.WriteCloser

func NewSnappyReader

func NewSnappyReader(r io.ReadCloser, _ *CompressCfg) io.ReadCloser

func NewSnappyWriter

func NewSnappyWriter(w io.WriteCloser, cfg *CompressCfg) io.WriteCloser

func NewZstdReader

func NewZstdReader(r io.ReadCloser, cfg *CompressCfg) io.ReadCloser

func NewZstdWriter

func NewZstdWriter(w io.WriteCloser, cfg *CompressCfg) io.WriteCloser

Types

type Cfg

type Cfg struct {
	Type     Type      `json:"type"      validate:"required" yaml:"type"`
	Cfg      any       `json:"cfg"       validate:"required" yaml:"cfg"`
	ExtraCfg *ExtraCfg `json:"extraCfg"  yaml:"extraCfg"`
	Role     Role      `json:"role"      validate:"required" yaml:"role"`
}

func (*Cfg) UnmarshalJSON added in v0.10.0

func (c *Cfg) UnmarshalJSON(data []byte) error

func (*Cfg) UnmarshalYAML added in v0.10.0

func (c *Cfg) UnmarshalYAML(data []byte) error

type Cmd

type Cmd struct {
	RW
	*cmd.Cfg
	// contains filtered or unexported fields
}

func NewCmd

func NewCmd() *Cmd

func (*Cmd) GetCfg

func (c *Cmd) GetCfg() any

func (*Cmd) Init

func (c *Cmd) Init() error

func (*Cmd) Start

func (c *Cmd) Start() error

func (*Cmd) Stop

func (c *Cmd) Stop() error

func (*Cmd) Type

func (c *Cmd) Type() any

type Compress

type Compress struct {
	RW
	*CompressCfg
	// contains filtered or unexported fields
}

func NewCompress

func NewCompress() *Compress

func (*Compress) Close

func (c *Compress) Close() error

func (*Compress) GetCfg

func (c *Compress) GetCfg() any

func (*Compress) Init

func (c *Compress) Init() error

func (*Compress) NestReader

func (c *Compress) NestReader(r io.ReadCloser)

func (*Compress) NestWriter

func (c *Compress) NestWriter(w io.WriteCloser)

func (*Compress) Type

func (c *Compress) Type() any

type CompressCfg

type CompressCfg struct {
	Type        CompressType  `json:"type"        validate:"required" yaml:"type"`
	Level       CompressLevel `json:"level"       validate:"required" yaml:"level"`
	Concurrency int           `json:"concurrency" yaml:"concurrency"`
}

func NewCompressCfg

func NewCompressCfg() *CompressCfg

type CompressLevel

type CompressLevel string

type CompressType

type CompressType string

type Copy

type Copy struct {
	RW
	*CopyCfg
}

func NewCopy

func NewCopy() *Copy

func (*Copy) GetCfg

func (cp *Copy) GetCfg() any

func (*Copy) Init

func (cp *Copy) Init() error

func (*Copy) Start

func (cp *Copy) Start() error

func (*Copy) Stop

func (cp *Copy) Stop() error

func (*Copy) Type

func (cp *Copy) Type() any

type CopyCfg

type CopyCfg struct {
	BufSize int `json:"bufSize" yaml:"bufSize"`
}

func NewCopyCfg

func NewCopyCfg() *CopyCfg

type ExtraCfg

type ExtraCfg struct {
	RateLimiterCfg     *ratelimit.RateLimiterCfg `json:"rateLimiterCfg"     yaml:"rateLimiterCfg"`
	BufSize            int                       `json:"bufSize"            yaml:"bufSize"`
	Deadline           int                       `json:"deadline"           yaml:"deadline"`
	AsyncChanBufSize   int                       `json:"asyncChanBufSize"   yaml:"asyncChanBufSize"`
	EnableMonitorSpeed bool                      `json:"enableMonitorSpeed" yaml:"enableMonitorSpeed"`
	EnableCalcHash     bool                      `json:"enableCalcHash"     yaml:"enableCalcHash"`
	EnableRateLimit    bool                      `json:"enableRateLimit"    yaml:"enableRateLimit"`
	EnableAsync        bool                      `json:"enableAsync"        yaml:"enableAsync"`
	Checksum           string                    `json:"checksum"           yaml:"checksum"`
	HashAlgo           string                    `json:"hashAlgo"           yaml:"hashAlgo"`
}

type File

type File struct {
	RW
	*FileCfg
	// contains filtered or unexported fields
}

func NewFile

func NewFile() *File

func (*File) GetCfg

func (f *File) GetCfg() any

func (*File) Init

func (f *File) Init() error

func (*File) Type

func (f *File) Type() any

type FileCfg

type FileCfg struct {
	Path string `json:"path" yaml:"path"`
	Perm uint32 `json:"perm" yaml:"perm"`
}

func NewFileCfg

func NewFileCfg() *FileCfg

type Ftp

type Ftp struct {
	RW
	*FtpCfg
}

func (*Ftp) GetCfg

func (f *Ftp) GetCfg() any

func (*Ftp) Init

func (f *Ftp) Init() error

func (*Ftp) Type

func (f *Ftp) Type() any

type FtpCfg

type FtpCfg struct {
	Addr    string `json:"addr"    validate:"required" yaml:"addr"`
	User    string `json:"user"    validate:"required" yaml:"user"`
	Pwd     string `json:"pwd"     validate:"required" yaml:"pwd"`
	Path    string `json:"path"    validate:"required" yaml:"path"`
	Timeout int    `json:"timeout" yaml:"timeout"`
	Retry   int    `json:"retry"   yaml:"retry"`
}

func NewFtpCfg

func NewFtpCfg() *FtpCfg

type Nop

type Nop struct {
	RW
	*NopCfg
}

func NewNop

func NewNop() *Nop

func (*Nop) GetCfg

func (n *Nop) GetCfg() any

func (*Nop) Type

func (n *Nop) Type() any

type NopCfg

type NopCfg struct{}

func NewNopCfg

func NewNopCfg() *NopCfg

type Null

type Null struct {
	RW
	*NullCfg
}

func NewNull

func NewNull() *Null

func (*Null) GetCfg

func (f *Null) GetCfg() any

func (*Null) Init

func (f *Null) Init() error

func (*Null) Type

func (f *Null) Type() any

type NullCfg

type NullCfg struct {
}

func NewNullCfg

func NewNullCfg() *NullCfg

type OSS

type OSS struct {
	RW
	*OSSCfg
}

func (*OSS) GetCfg

func (o *OSS) GetCfg() any

func (*OSS) Init

func (o *OSS) Init() error

func (*OSS) Type

func (o *OSS) Type() any

type OSSCfg

type OSSCfg struct {
	URL     string `json:"url"      validate:"required" yaml:"url"`
	Ak      string `json:"ak"       validate:"required" yaml:"ak"`
	Sk      string `json:"sk"       validate:"required" yaml:"sk"`
	Region  string `json:"region"   yaml:"region"`
	Append  bool   `json:"append"   yaml:"append"`
	Timeout int    `json:"timeout"  yaml:"timeout"`
	Retry   int    `json:"retry"    yaml:"retry"`
}

func NewOSSCfg

func NewOSSCfg() *OSSCfg

type RW

type RW interface {
	runner.Runner
	io.ReadWriteCloser
	plugin.Plugin

	NestReader(io.ReadCloser)
	NestWriter(io.WriteCloser)
	Reader() io.ReadCloser
	Writer() io.WriteCloser

	Flush() error

	HookRead(...ReadHook)
	HookWrite(...WriteHook)

	Nwrite() uint64
	Nread() uint64

	Hash() string

	EnableMonitorSpeed()
	EnableCalcHash(hashAlgo string)
	EnableChecksum(checksum string, hashAlgo string)
	EnableRateLimit(ratelimit.RxTxRateLimiter)
	EnableWriteBuf(bufSize int, deadline int, async bool, asyncChanBufSize int)
	EnableReadBuf(bufSize int, async bool, asyncChanBufSize int)

	IsAsyncOrDeadline() bool
	AsyncChanLen() int
	AsyncChanCap() int

	AsStarter()
	IsStarter() bool
	AsReader()
	IsReader() bool
	AsWriter()
	IsWriter() bool
	As(Role)
	Is(Role) bool
	Role() Role
}

func CreateRW

func CreateRW(rwCfg *Cfg) RW

func NewFtp

func NewFtp() RW

func NewOSS

func NewOSS() RW

func NewSSH

func NewSSH() RW

type ReadHook

type ReadHook func(n int, bs []byte, err error, cost int64, misc ...any) error

type Role

type Role string
const (
	RoleStarter Role = "starter"
	RoleReader  Role = "reader"
	RoleWriter  Role = "writer"
)

type SSH

type SSH struct {
	RW
	*SSHCfg
	// contains filtered or unexported fields
}

func (*SSH) Close

func (s *SSH) Close() error

func (*SSH) GetCfg

func (s *SSH) GetCfg() any

func (*SSH) Init

func (s *SSH) Init() error

func (*SSH) Start

func (s *SSH) Start() error

func (*SSH) Stop

func (s *SSH) Stop() error

func (*SSH) Type

func (s *SSH) Type() any

type SSHCfg

type SSHCfg struct {
	Addr       string `json:"addr"       validate:"required"  yaml:"addr"`
	User       string `json:"user"       validate:"required"  yaml:"user"`
	Pwd        string `json:"pwd"        yaml:"pwd"`
	PrivateKey string `json:"privateKey" yaml:"privateKey"`
	Timeout    int    `json:"timeout"    yaml:"timeout"`
	Path       string `json:"path"       validate:"required"  yaml:"path"`
}

func NewSSHCfg

func NewSSHCfg() *SSHCfg

type Tail

type Tail struct {
	RW
	*TailCfg
	// contains filtered or unexported fields
}

func NewTail

func NewTail() *Tail

func (*Tail) GetCfg

func (t *Tail) GetCfg() any

func (*Tail) Init

func (t *Tail) Init() error

func (*Tail) Stop

func (t *Tail) Stop() error

func (*Tail) Type

func (t *Tail) Type() any

type TailCfg

type TailCfg struct {
	Path string `json:"path" yaml:"path"`
	Pos  int64  `json:"pos"  yaml:"pos"`
}

func NewTailCfg

func NewTailCfg() *TailCfg

type Type

type Type string
const TypeCmd Type = "cmd"
const TypeCopy Type = "copy"
const TypeFile Type = "file"
const (
	TypeFtp Type = "ftp"
)
const TypeNop Type = "nop"
const TypeNull Type = "null"
const (
	TypeOss Type = "oss"
)
const (
	TypeSSH Type = "ssh"
)
const TypeTail Type = "tail"

type WriteHook

type WriteHook func(n int, bs []byte, err error, cost int64, misc ...any) error

Jump to

Keyboard shortcuts

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