utils.go
func unescapeFilepath(path string) (string, error) {
	buf := make([]byte, 0, len(path))
	llen := len(path)
	for i := 0; i < llen; {
		if path[i] == '\\' {
			if llen < i+4 {
				return "", fmt.Errorf("Invalid octal code: too short")
			}
			octalCode := path[(i + 1):(i + 4)]
			val, err := strconv.ParseUint(octalCode, 8, 8)
			if err != nil {
				return "", fmt.Errorf("Invalid octal code: %v", err)
			}
			buf = append(buf, byte(val))
			i += 4
		} else {
			buf = append(buf, path[i])
			i++
		}
	}
	return string(buf), nil
}
func unescapeFilepath(path string) (string, error) {
	buf := make([]byte, 0, len(path))
	llen := len(path)
	for i := 0; i < llen; {
		if path[i] == '\\' {
			if llen < i+4 {
				return "", fmt.Errorf("Invalid octal code: too short")
			}
			octalCode := path[(i + 1):(i + 4)]
			val, err := strconv.ParseUint(octalCode, 8, 8)
			if err != nil {
				return "", fmt.Errorf("Invalid octal code: %v", err)
			}
			buf = append(buf, byte(val))
			i += 4
		} else {
			buf = append(buf, path[i])
			i++
		}
	}
	return string(buf), nil
}
func unescapeFilepath ( path string ) ( string , error ) { buf := make ( [ ] byte , 0 , len ( path ) ) llen := len ( path ) for i := 0 ; i < llen ; { if path [ i ] == '\\' { if llen < i + 4 { return " " , fmt . Errorf ( " " ) } octalCode := path [ ( i + 1 ) : ( i + 4 ) ] val , err := strconv . ParseUint ( octalCode , 8 , 8 ) if err != nil { return " " , fmt . Errorf ( " " , err ) } buf = append ( buf , byte ( val ) ) i += 4 } else { buf = append ( buf , path [ i ] ) i ++ } } return string ( buf ) , nil }
/*
 * from zfs diff`s escape function:
 *
 * Prints a file name out a character at a time.  If the character is
 * not in the range of what we consider "printable" ASCII, display it
 * as an escaped 3-digit octal value.  ASCII values less than a space
 * are all control characters and we declare the upper end as the
 * DELete character.  This also is the last 7-bit ASCII character.
 * We choose to treat all 8-bit ASCII as not printable for this
 * application.
 */
/ * from zfs diff s escape function : Prints a file name out a character at a time . If the character is not in the range of what we consider printable ASCII display it as an escaped 3 - digit octal value . ASCII values less than a space are all control characters and we declare the upper end as the DELete character . This also is the last 7 - bit ASCII character . We choose to treat all 8 - bit ASCII as not printable for this application .