// hasNUL reports whether the NUL character exists within s. func hasNUL(s string) bool { … } // isASCII reports whether the input is an ASCII C-style string. func isASCII(s string) bool { … } // toASCII converts the input to an ASCII C-style string. // This is a best effort conversion, so invalid characters are dropped. func toASCII(s string) string { … } type parser … type formatter … // parseString parses bytes as a NUL-terminated C-style string. // If a NUL byte is not found then the whole slice is returned as a string. func (*parser) parseString(b []byte) string { … } // formatString copies s into b, NUL-terminating if possible. func (f *formatter) formatString(b []byte, s string) { … } // fitsInBase256 reports whether x can be encoded into n bytes using base-256 // encoding. Unlike octal encoding, base-256 encoding does not require that the // string ends with a NUL character. Thus, all n bytes are available for output. // // If operating in binary mode, this assumes strict GNU binary mode; which means // that the first byte can only be either 0x80 or 0xff. Thus, the first byte is // equivalent to the sign bit in two's complement form. func fitsInBase256(n int, x int64) bool { … } // parseNumeric parses the input as being encoded in either base-256 or octal. // This function may return negative numbers. // If parsing fails or an integer overflow occurs, err will be set. func (p *parser) parseNumeric(b []byte) int64 { … } // formatNumeric encodes x into b using base-8 (octal) encoding if possible. // Otherwise it will attempt to use base-256 (binary) encoding. func (f *formatter) formatNumeric(b []byte, x int64) { … } func (p *parser) parseOctal(b []byte) int64 { … } func (f *formatter) formatOctal(b []byte, x int64) { … } // fitsInOctal reports whether the integer x fits in a field n-bytes long // using octal encoding with the appropriate NUL terminator. func fitsInOctal(n int, x int64) bool { … } // parsePAXTime takes a string of the form %d.%d as described in the PAX // specification. Note that this implementation allows for negative timestamps, // which is allowed for by the PAX specification, but not always portable. func parsePAXTime(s string) (time.Time, error) { … } // formatPAXTime converts ts into a time of the form %d.%d as described in the // PAX specification. This function is capable of negative timestamps. func formatPAXTime(ts time.Time) (s string) { … } // 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. func parsePAXRecord(s string) (k, v, r string, err error) { … } // formatPAXRecord formats a single PAX record, prefixing it with the // appropriate length. func formatPAXRecord(k, v string) (string, error) { … } // validPAXRecord reports whether the key-value pair is valid where each // record is formatted as: // // "%d %s=%s\n" % (size, key, value) // // Keys and values should be UTF-8, but the number of bad writers out there // forces us to be a more liberal. // Thus, we only reject all keys with NUL, and only reject NULs in values // for the PAX version of the USTAR string fields. // The key must not contain an '=' character. func validPAXRecord(k, v string) bool { … }