项目作者: subosito

项目描述 :
Filename sanitization for Go
高级语言: Go
项目地址: git://github.com/subosito/gozaru.git
创建时间: 2014-08-12T23:56:47Z
项目社区:https://github.com/subosito/gozaru

开源协议:MIT License

下载


gozaru

Build Status
codecov

Filename sanitization for Go

Installation

  1. $ go get github.com/subosito/gozaru

Usage

Gozaru basically normalizes, filters and truncates given filename to generates safe and cross-platform filename. For example:

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/subosito/gozaru"
  5. )
  6. func main() {
  7. name := gozaru.Sanitize(" what\\ēver//wëird:user:înput:")
  8. fmt.Println(name) // => "whatēverwëirduserînput"
  9. }

You can add extra room for filename by using SanitizePad, see differences here:

  1. // import "strings"
  2. name := strings.Repeat("A", 400)
  3. gozaru.Sanitize(name)
  4. // => resulting filename is 255 characters long
  5. gozaru.SanitizePad(name, 100)
  6. // => resulting filename is 155 characters long

Filenames overview

Best practices for having a safe and cross-platform filenames are:

Credits

Gozaru is a Go port of zaru by @madrobby. Thanks a lot for him.