Documentation
¶
Index ¶
- Constants
- func BoolPtr(v bool) *bool
- func BuildProxyUrl(scheme, host, usr, pwd string) *url.URL
- func ByteFmt(size int64) string
- func CheckDuplicateAndRename(path string) (string, error)
- func CopyDir(source string, target string, excludeDir ...string) error
- func CreateDirIfNotExist(dir string) error
- func DeepClone[T any](v *T) *T
- func Dir(path string) string
- func Filepath(path string, originName string, customName string) string
- func IsExistsFile(path string) bool
- func MapToStruct(s any, v any) error
- func Match(pattern string, u string) bool
- func ParseDataUri(uri string) (string, []byte)
- func ParseSchema(url string) string
- func ProxyUrlToHandler(proxyUrl *url.URL) func(*http.Request) (*url.URL, error)
- func Ptr[T any](v T) *T
- func ReplaceInvalidFilename(path string) string
- func ReplacePathPlaceholders(path string) string
- func SafeFilename(filename string) string
- func SafeRemove(name string) error
- func TruncateFilename(filename string, maxLength int) string
- func TryUrlPathUnescape(s string) string
- func TryUrlQueryUnescape(s string) string
- type Timer
Constants ¶
const (
// MaxFilenameLength is the maximum length in bytes for a filename
MaxFilenameLength = 100
)
Variables ¶
This section is empty.
Functions ¶
func BuildProxyUrl ¶ added in v1.5.1
BuildProxyUrl builds a proxy url with given host, username and password.
func CheckDuplicateAndRename ¶
CheckDuplicateAndRename rename duplicate file, add suffix (1) (2) ... if file name is a.txt, rename to a (1).txt if directory name is a, rename to a (1) return new name
func CopyDir ¶ added in v1.4.0
CopyDir Copy all files to the target directory, if the file already exists, it will be overwritten. Remove target file if the source file is not exist.
func CreateDirIfNotExist ¶ added in v1.3.5
func IsExistsFile ¶ added in v1.3.8
IsExistsFile check file exists and is a file
func MapToStruct ¶
func Match ¶ added in v1.4.0
Match url with pattern by chrome extension match pattern style https://developer.chrome.com/docs/extensions/mv3/match_patterns/
func ParseDataUri ¶ added in v1.3.8
ParseDataUri parses a data URI and returns the MIME type and decode data.
func ParseSchema ¶
func ProxyUrlToHandler ¶ added in v1.5.7
ProxyUrlToHandler gets the proxy handler from the proxy url.
func ReplaceInvalidFilename ¶ added in v1.5.2
ReplaceInvalidFilename replace invalid path characters Deprecated: Use SafeFilename instead which also handles length truncation
func ReplacePathPlaceholders ¶ added in v1.8.3
ReplacePathPlaceholders replaces date placeholders in a path with actual values Supported placeholders:
- %year% - Current year (e.g., 2025)
- %month% - Current month (01-12)
- %day% - Current day (01-31)
- %date% - Full date format (2025-01-01)
func SafeFilename ¶ added in v1.9.0
SafeFilename sanitizes a filename by replacing invalid characters and truncating to a safe length. It performs two operations: 1. Replaces invalid path characters (platform-specific) with underscores 2. Truncates filename to MaxFilenameLength bytes while preserving the file extension The function handles UTF-8 multi-byte characters correctly by truncating at valid boundaries.
func SafeRemove ¶
SafeRemove remove file safely, ignoring errors if the path does not exist.
func TruncateFilename ¶ added in v1.9.0
TruncateFilename truncates a filename to a maximum byte length while preserving the extension. Deprecated: Use SafeFilename instead which also handles invalid character replacement
func TryUrlPathUnescape ¶ added in v1.9.0
TryUrlPathUnescape tries to unescape a URL path-encoded string. Unlike QueryUnescape, PathUnescape does not treat '+' as a space. This is the correct function to use for decoding URL paths and filenames where %2B should decode to '+', not to a space.
If unescaping fails, it returns the original string.
func TryUrlQueryUnescape ¶ added in v1.8.1
TryUrlQueryUnescape tries to unescape a URL-encoded string.
If unescaping fails, it returns the original string.