func parsePAXRecord(s string) (k, v, r string, err error) {
	sp := strings.IndexByte(s, ' ')
	if sp == -1 {
		return "", "", s, ErrHeader
	}
	n, perr := strconv.ParseInt(s[:sp], 10, 0)  
	if perr != nil || n < 5 || int64(len(s)) < n {
		return "", "", s, ErrHeader
	}
	rec, nl, rem := s[sp+1:n-1], s[n-1:n], s[n:]
	if nl != "\n" {
		return "", "", s, ErrHeader
	}
	eq := strings.IndexByte(rec, '=')
	if eq == -1 {
		return "", "", s, ErrHeader
	}
	k, v = rec[:eq], rec[eq+1:]
	if !validPAXRecord(k, v) {
		return "", "", s, ErrHeader
	}
	return k, v, rem, nil
}
parsePAXRecord parses the input PAX record string into a key-value pair.
If parsing is successful, it will slice off the currently read record and
return the remainder as r.
package tar
import (
	"bytes"
	"fmt"
	"strconv"
	"strings"
	"time"
)
func hasNUL(s string) bool {
	return strings.IndexByte(s, 0) >= 0
}
func isASCII(s string) bool {
	for _, c := range s {
		if c >= 0x80 || c == 0x00 {
			return false
		}
	}
	return true
}
func toASCII(s string) string {
	if isASCII(s) {
		return s
	}
	b := make([]byte, 0, len(s))
	for _, c := range s {
		if c < 0x80 && c != 0x00 {
			b = append(b, byte(c))
		}
	}
	return string(b)
}
type parser struct {
	err error  
}
type formatter struct {
	err error  
}
func (*parser) parseString(b []byte) string {
	if i := bytes.IndexByte(b, 0); i >= 0 {
		return string(b[:i])
	}
	return string(b)
}
func (f *formatter) formatString(b []byte, s string) {
	if len(s) > len(b) {
		f.err = ErrFieldTooLong
	}
	copy(b, s)
	if len(s) < len(b) {
		b[len(s)] = 0
	}
	if len(s) > len(b) && b[len(b)-1] == '/' {
		n := len(strings.TrimRight(s[:len(b)], "/"))
		b[n] = 0  
	}
}
func fitsInBase256(n int, x int64) bool {
	binBits := uint(n-1) * 8
	return n >= 9 || (x >= -1<<binBits && x < 1<<binBits)
}
func (p *parser) parseNumeric(b []byte) int64 {
	if len(b) > 0 && b[0]&0x80 != 0 {
		var inv byte  
		if b[0]&0x40 != 0 {
			inv = 0xff
		}
		var x uint64
		for i, c := range b {
			c ^= inv  
			if i == 0 {
				c &= 0x7f  
			}
			if (x >> 56) > 0 {
				p.err = ErrHeader  
				return 0
			}
			x = x<<8 | uint64(c)
		}
		if (x >> 63) > 0 {
			p.err = ErrHeader  
			return 0
		}
		if inv == 0xff {
			return ^int64(x)
		}
		return int64(x)
	}
	return p.parseOctal(b)
}
func (f *formatter) formatNumeric(b []byte, x int64) {
	if fitsInOctal(len(b), x) {
		f.formatOctal(b, x)
		return
	}
	if fitsInBase256(len(b), x) {
		for i := len(b) - 1; i >= 0; i-- {
			b[i] = byte(x)
			x >>= 8
		}
		b[0] |= 0x80  
		return
	}
	f.formatOctal(b, 0)  
	f.err = ErrFieldTooLong
}
func (p *parser) parseOctal(b []byte) int64 {
	b = bytes.Trim(b, " \x00")
	if len(b) == 0 {
		return 0
	}
	x, perr := strconv.ParseUint(p.parseString(b), 8, 64)
	if perr != nil {
		p.err = ErrHeader
	}
	return int64(x)
}
func (f *formatter) formatOctal(b []byte, x int64) {
	if !fitsInOctal(len(b), x) {
		x = 0  
		f.err = ErrFieldTooLong
	}
	s := strconv.FormatInt(x, 8)
	if n := len(b) - len(s) - 1; n > 0 {
		s = strings.Repeat("0", n) + s
	}
	f.formatString(b, s)
}
func fitsInOctal(n int, x int64) bool {
	octBits := uint(n-1) * 3
	return x >= 0 && (n >= 22 || x < 1<<octBits)
}
func parsePAXTime(s string) (time.Time, error) {
	const maxNanoSecondDigits = 9
	ss, sn := s, ""
	if pos := strings.IndexByte(s, '.'); pos >= 0 {
		ss, sn = s[:pos], s[pos+1:]
	}
	secs, err := strconv.ParseInt(ss, 10, 64)
	if err != nil {
		return time.Time{}, ErrHeader
	}
	if len(sn) == 0 {
		return time.Unix(secs, 0), nil  
	}
	if strings.Trim(sn, "0123456789") != "" {
		return time.Time{}, ErrHeader
	}
	if len(sn) < maxNanoSecondDigits {
		sn += strings.Repeat("0", maxNanoSecondDigits-len(sn))  
	} else {
		sn = sn[:maxNanoSecondDigits]  
	}
	nsecs, _ := strconv.ParseInt(sn, 10, 64)  
	if len(ss) > 0 && ss[0] == '-' {
		return time.Unix(secs, -1*nsecs), nil  
	}
	return time.Unix(secs, nsecs), nil
}
func formatPAXTime(ts time.Time) (s string) {
	secs, nsecs := ts.Unix(), ts.Nanosecond()
	if nsecs == 0 {
		return strconv.FormatInt(secs, 10)
	}
	sign := ""
	if secs < 0 {
		sign = "-"              
		secs = -(secs + 1)      
		nsecs = -(nsecs - 1E9)  
	}
	return strings.TrimRight(fmt.Sprintf("%s%d.%09d", sign, secs, nsecs), "0")
}