Documentation ¶
Overview ¶
Package file 提供文件处理、上传和水印功能
Index ¶
- Constants
- Variables
- func Basename(path string) string
- func Chdir(dir string) (err error)
- func Create(path string) (*os.File, error)
- func Dir(path string) string
- func Exists(path string) bool
- func Ext(path string) string
- func InitFileSystem()
- func IsAllowedImageExt(ext string) bool
- func IsDir(path string) bool
- func IsFile(path string) bool
- func Join(paths ...string) string
- func Mkdir(path string) (err error)
- func Move(src string, dst string) (err error)
- func ProcessFilesInParallel(files []string, processor func(string) error, maxConcurrency int64) error
- func ProcessLargeFile(filePath string, processor ChunkProcessor) error
- func Pwd() string
- func RealPath(path string) string
- func RefreshAllFileCache()
- func RefreshFileCache(fullPath string) error
- func Rename(src string, dst string) error
- func Search(name string, prioritySearchPaths ...string) (string, error)
- func SetCacheExpiration(duration time.Duration)
- func Stat(path string) (os.FileInfo, error)
- func Temp(names ...string) string
- type ChunkProcessor
- type File
- func (f *File) ChunkRead(chunkSize int64, handler func([]byte) error) error
- func (f *File) Ext() string
- func (f *File) FullPath() string
- func (f *File) ModifyTime() (time.Time, error)
- func (f *File) Name() string
- func (f *File) Path() string
- func (f *File) ReadAll() ([]byte, error)
- func (f *File) ReadBlock(size int64) ([]byte, int64, error)
- func (f *File) ReadLine() (string, error)
- func (f *File) Size() (int64, error)
- func (f *File) StreamRead(handler func([]byte) error) error
- func (f *File) Truncate() error
- func (f *File) Write(b []byte) error
- func (f *File) WriteAppend(b []byte) error
- func (f *File) WriteAt(b []byte, offset int64) (int, error)
- type FileError
- type FileHandler
- type FileInfoCache
- type Filer
- type UploadConfig
- type UploadResult
- type Watermark
- type WatermarkConfig
- type WatermarkPos
Constants ¶
const (
Separator = string(filepath.Separator)
)
Variables ¶
var FileCache = struct { sync.RWMutex m map[string]*FileInfoCache }{/* contains filtered or unexported fields */}
FileCache 全局文件信息缓存
Functions ¶
func Chdir ¶ added in v0.1.6
Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError.
func Create ¶ added in v0.1.6
Create creates a file with given `path` recursively. The parameter `path` is suggested to be absolute path.
func IsDir ¶ added in v0.1.6
IsDir checks whether given `path` a directory. Note that it returns false if the `path` does not exist.
func IsFile ¶ added in v0.1.6
IsFile checks whether given `path` a file, which means it's not a directory. Note that it returns false if the `path` does not exist.
func Mkdir ¶ added in v0.1.6
Mkdir creates directories recursively with given `path`. The parameter `path` is suggested to be an absolute path instead of relative one.
func Move ¶ added in v0.1.6
Move renames (moves) `src` to `dst` path. If `dst` already exists and is not a directory, it'll be replaced.
func ProcessFilesInParallel ¶
func ProcessFilesInParallel(files []string, processor func(string) error, maxConcurrency int64) error
ProcessFilesInParallel 并行处理多个文件,带并发限制
func ProcessLargeFile ¶
func ProcessLargeFile(filePath string, processor ChunkProcessor) error
ProcessLargeFile 处理大文件
func Pwd ¶ added in v0.1.6
func Pwd() string
Pwd returns absolute path of current working directory. Note that it returns an empty string if retrieving current working directory failed.
func RealPath ¶ added in v0.1.6
RealPath converts the given `path` to its absolute path and checks if the file path exists. If the file does not exist, return an empty string.
func Search ¶ added in v0.1.0
Search searches for a file by name in the given priority search paths, current working directory, and executable directory. It returns the absolute file path if found, or an empty string and error if not found.
func SetCacheExpiration ¶
SetCacheExpiration 设置缓存过期时间
Types ¶
type ChunkProcessor ¶
ChunkProcessor 用于处理大文件的分块处理器
type File ¶
type File struct {
// contains filtered or unexported fields
}
File 文件类
func (*File) StreamRead ¶
StreamRead 流式读取文件
type FileHandler ¶
type FileHandler struct {
// contains filtered or unexported fields
}
FileHandler 处理文件上传和水印
func NewFileHandler ¶
func NewFileHandler(cfg UploadConfig) (*FileHandler, error)
NewFileHandler 创建一个新的 FileHandler 实例
func (*FileHandler) Upload ¶
func (fh *FileHandler) Upload(field string, r *http.Request) ([]UploadResult, error)
Upload 执行上传操作
type FileInfoCache ¶
type FileInfoCache struct {
// contains filtered or unexported fields
}
FileInfoCache 用于缓存文件信息
type Filer ¶
type Filer interface { Size() (int64, error) ReadAll() ([]byte, error) ReadLine() (string, error) ReadBlock(size int64) ([]byte, int64, error) Write(b []byte) error WriteAt(b []byte, offset int64) (int, error) WriteAppend(b []byte) error Truncate() error Ext() string Name() string Path() string FullPath() string ModifyTime() (time.Time, error) StreamRead(handler func([]byte) error) error ChunkRead(chunkSize int64, handler func([]byte) error) error }
Filer 文件接口
type UploadConfig ¶
type UploadConfig struct { Dir string Format string MaxSize int64 AllowedExt []string Watermark *WatermarkConfig }
UploadConfig 上传配置
type UploadResult ¶
UploadResult 表示单个文件的上传结果
type Watermark ¶
type Watermark struct {
// contains filtered or unexported fields
}
Watermark 用于给图片添加水印功能
func NewWatermark ¶
func NewWatermark(cfg *WatermarkConfig) (*Watermark, error)
NewWatermark 创建一个新的 Watermark 实例
type WatermarkConfig ¶
type WatermarkConfig struct { Path string Padding int Pos WatermarkPos Transparency uint8 Rotation float64 }
WatermarkConfig 水印配置
type WatermarkPos ¶
type WatermarkPos int
WatermarkPos 表示水印的位置
const ( TopLeft WatermarkPos = iota TopRight BottomLeft BottomRight Center )
水印的位置常量