Documentation
¶
Overview ¶
Package svach file names for consistent naming across platforms. Incase of invalid fileName, a md5Sum of provided filename is returned
Options ¶
`replaceStr`, replace invalid characters with given string, default "" (empty string)
`maxLen`, limit length of the output, default `240`
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCntrl ,Control characters exist in `replaceStr` ErrCntrl = errors.New("Control characters exist in replaceStr") // ErrInval ,Invalid characters exist in `replaceStr` ErrInval = errors.New("Invalid characters like `., <, >, :, \", /, \\, |, ?, *` exist in replaceStr") // ErrLen ,`maxLen` greater than 255 ErrLen = errors.New("maxLen can't be greater than 255") )
var DefaultSvach = &Svach{"", iMaxLen}
DefaultSvach for Name and Clean
Functions ¶
func Clean ¶ added in v0.0.2
Clean sanitizes `fileName` into more humane format.
Remove invisible and control characters, repeated separators. Replace different kinds of spaces with normal space.
Example ¶
package main import ( "fmt" "github.com/nilsocket/svach" ) func main() { res := svach.Clean(`.....Hello<>:/---\....W|orld?.!..`) fmt.Println(res) }
Output: .Hello-.World.!
Types ¶
type Svach ¶
type Svach struct {
// contains filtered or unexported fields
}
Svach object
func WithOpts ¶ added in v0.0.2
WithOpts returns Svach object, with opts set and returns error, if conditions aren't met.
Conditions:
- replaceStr can't contain Control or Invalid characters
- maxlen can't be greater than 255
Example ¶
package main import ( "fmt" "github.com/nilsocket/svach" ) func main() { s, _ := svach.WithOpts(" ", 6) res := s.Name(`.....H<>e:l.!..`) fmt.Println(res) }
Output: .H e l
Example (Error) ¶
package main import ( "fmt" "github.com/nilsocket/svach" ) func main() { _, err := svach.WithOpts("?", 6) fmt.Println(err) }
Output: Invalid characters like `., <, >, :, ", /, \, |, ?, *` exist in replaceStr