Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
/ gozaru Public archive

Filename sanitization for Go

License

Notifications You must be signed in to change notification settings

subosito/gozaru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gozaru

Build Status codecov

Filename sanitization for Go

Installation

$ go get github.com/subosito/gozaru

Usage

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

package main

import (
	"fmt"
	"github.com/subosito/gozaru"
)

func main() {
	name := gozaru.Sanitize("  what\\ēver//wëird:user:înput:")
	fmt.Println(name) // => "whatēverwëirduserînput"
}

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

// import "strings"

name := strings.Repeat("A", 400)

gozaru.Sanitize(name)
// => resulting filename is 255 characters long

gozaru.SanitizePad(name, 100)
// => 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.

About

Filename sanitization for Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages