gozaru

package module
v0.0.0-...-416082c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2019 License: MIT Imports: 3 Imported by: 3

README

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.

Documentation

Index

Constants

View Source
const (
	CharacterFilter   = `[\x00-\x1F\/\\:\*\?\"<>\|]`
	UnicodeWhitespace = `[[:space:]]+`
)

Variables

View Source
var (
	FallbackFilename     = "file"
	WindowsReservedNames = [...]string{
		"CON", "PRN", "AUX", "NUL",
		"COM1", "COM2", "COM3", "COM4", "COM5",
		"COM6", "COM7", "COM8", "COM9",
		"LPT1", "LPT2", "LPT3", "LPT4", "LPT5",
		"LPT6", "LPT7", "LPT8", "LPT9",
	}
)

Functions

func Sanitize

func Sanitize(s string) string

func SanitizeFallback

func SanitizeFallback(s string, fallback string) string

func SanitizePad

func SanitizePad(s string, n int) string

func SanitizePadFallback

func SanitizePadFallback(s string, n int, fallback string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL