func decodeName(buf []byte) string {
	i := bytes.IndexByte(buf, 0)
	if i < 0 {
		return string(buf) // filename is UTF-8
	}

	name := buf[:i]
	encName := readBuf(buf[i+1:])
	if len(encName) < 2 {
		return "" // invalid encoding
	}
	highByte := uint16(encName.byte()) << 8
	flags := encName.byte()
	flagBits := 8
	var wchars []uint16 // decoded characters are UTF-16
	for len(wchars) < len(name) && len(encName) > 0 {
		if flagBits == 0 {
			flags = encName.byte()
			flagBits = 8
			if len(encName) == 0 {
				break
			}
		}
		switch flags >> 6 {
		case 0:
			wchars = append(wchars, uint16(encName.byte()))
		case 1:
			wchars = append(wchars, uint16(encName.byte())|highByte)
		case 2:
			if len(encName) < 2 {
				break
			}
			wchars = append(wchars, encName.uint16())
		case 3:
			n := encName.byte()
			b := name[len(wchars):]
			if l := int(n&0x7f) + 2; l < len(b) {
				b = b[:l]
			}
			if n&0x80 > 0 {
				if len(encName) < 1 {
					break
				}
				ec := encName.byte()
				for _, c := range b {
					wchars = append(wchars, uint16(c+ec)|highByte)
				}
			} else {
				for _, c := range b {
					wchars = append(wchars, uint16(c))
				}
			}
		}
		flags <<= 2
		flagBits -= 2
	}
	return string(utf16.Decode(wchars))
}
func decodeName(buf []byte) string {
	i := bytes.IndexByte(buf, 0)
	if i < 0 {
		return string(buf) 
	}

	name := buf[:i]
	encName := readBuf(buf[i+1:])
	if len(encName) < 2 {
		return "" 
	}
	highByte := uint16(encName.byte()) << 8
	flags := encName.byte()
	flagBits := 8
	var wchars []uint16 
	for len(wchars) < len(name) && len(encName) > 0 {
		if flagBits == 0 {
			flags = encName.byte()
			flagBits = 8
			if len(encName) == 0 {
				break
			}
		}
		switch flags >> 6 {
		case 0:
			wchars = append(wchars, uint16(encName.byte()))
		case 1:
			wchars = append(wchars, uint16(encName.byte())|highByte)
		case 2:
			if len(encName) < 2 {
				break
			}
			wchars = append(wchars, encName.uint16())
		case 3:
			n := encName.byte()
			b := name[len(wchars):]
			if l := int(n&0x7f) + 2; l < len(b) {
				b = b[:l]
			}
			if n&0x80 > 0 {
				if len(encName) < 1 {
					break
				}
				ec := encName.byte()
				for _, c := range b {
					wchars = append(wchars, uint16(c+ec)|highByte)
				}
			} else {
				for _, c := range b {
					wchars = append(wchars, uint16(c))
				}
			}
		}
		flags <<= 2
		flagBits -= 2
	}
	return string(utf16.Decode(wchars))
}
func decodeName ( buf [ ] byte ) string { i := bytes . IndexByte ( buf , 0 ) if i < 0 { return string ( buf ) // filename is UTF-8 } name := buf [ : i ] encName := readBuf ( buf [ i + 1 : ] ) if len ( encName ) < 2 { return " " // invalid encoding } highByte := uint16 ( encName . byte ( ) ) << 8 flags := encName . byte ( ) flagBits := 8 var wchars [ ] uint16 // decoded characters are UTF-16 for len ( wchars ) < len ( name ) && len ( encName ) > 0 { if flagBits == 0 { flags = encName . byte ( ) flagBits = 8 if len ( encName ) == 0 { break } } switch flags >> 6 { case 0 : wchars = append ( wchars , uint16 ( encName . byte ( ) ) ) case 1 : wchars = append ( wchars , uint16 ( encName . byte ( ) ) | highByte ) case 2 : if len ( encName ) < 2 { break } wchars = append ( wchars , encName . uint16 ( ) ) case 3 : n := encName . byte ( ) b := name [ len ( wchars ) : ] if l := int ( n & 0x7f ) + 2 ; l < len ( b ) { b = b [ : l ] } if n & 0x80 > 0 { if len ( encName ) < 1 { break } ec := encName . byte ( ) for _ , c := range b { wchars = append ( wchars , uint16 ( c + ec ) | highByte ) } } else { for _ , c := range b { wchars = append ( wchars , uint16 ( c ) ) } } } flags <<= 2 flagBits -= 2 } return string ( utf16 . Decode ( wchars ) ) }
// decodeName decodes a non-unicode filename from a file header.
decodeName decodes a non - unicode filename from a file header .