package bytes

Import Path
	bytes (on golang.org and go.dev)

Dependency Relation
	imports 5 packages, and imported by 54 packages

Involved Source Files buffer.go Package bytes implements functions for the manipulation of byte slices. It is analogous to the facilities of the strings package. reader.go
Package-Level Type Names (total 2)
/* sort by: | */
A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use. Bytes returns a slice of length b.Len() holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification (that is, only until the next call to a method like Read, Write, Reset, or Truncate). The slice aliases the buffer content at least until the next buffer modification, so immediate changes to the slice will affect the result of future reads. Cap returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data. Grow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with ErrTooLarge. Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()). Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method. Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil. ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF. ReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim. ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge. ReadRune reads and returns the next UTF-8-encoded Unicode code point from the buffer. If no bytes are available, the error returned is io.EOF. If the bytes are an erroneous UTF-8 encoding, it consumes one byte and returns U+FFFD, 1. ReadString reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadString returns err != nil if and only if the returned data does not end in delim. Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as Truncate(0). String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>". To build strings more efficiently, see the strings.Builder type. Truncate discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It panics if n is negative or greater than the length of the buffer. UnreadByte unreads the last byte returned by the most recent successful read operation that read at least one byte. If a write has happened since the last read, if the last read returned an error, or if the read read zero bytes, UnreadByte returns an error. UnreadRune unreads the last rune returned by ReadRune. If the most recent read or write operation on the buffer was not a successful ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.) Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge. WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge. WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge. WriteString appends the contents of s to the buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge. WriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned. *T : compress/flate.Reader *T : expvar.Var *T : fmt.Stringer *T : image/jpeg.Reader *T : io.ByteReader *T : io.ByteScanner *T : io.ByteWriter *T : io.Reader *T : io.ReaderFrom *T : io.ReadWriter *T : io.RuneReader *T : io.RuneScanner *T : io.StringWriter *T : io.Writer *T : io.WriterTo func NewBuffer(buf []byte) *Buffer func NewBufferString(s string) *Buffer func encoding/json.Compact(dst *Buffer, src []byte) error func encoding/json.HTMLEscape(dst *Buffer, src []byte) func encoding/json.Indent(dst *Buffer, src []byte, prefix, indent string) error func go/types.WriteExpr(buf *Buffer, x ast.Expr) func go/types.WriteSignature(buf *Buffer, sig *types.Signature, qf types.Qualifier) func go/types.WriteType(buf *Buffer, typ types.Type, qf types.Qualifier)
A Reader implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker, io.ByteScanner, and io.RuneScanner interfaces by reading from a byte slice. Unlike a Buffer, a Reader is read-only and supports seeking. The zero value for Reader operates like a Reader of an empty slice. Len returns the number of bytes of the unread portion of the slice. Read implements the io.Reader interface. ReadAt implements the io.ReaderAt interface. ReadByte implements the io.ByteReader interface. ReadRune implements the io.RuneReader interface. Reset resets the Reader to be reading from b. Seek implements the io.Seeker interface. Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by calls to any other method. UnreadByte complements ReadByte in implementing the io.ByteScanner interface. UnreadRune complements ReadRune in implementing the io.RuneScanner interface. WriteTo implements the io.WriterTo interface. *T : compress/flate.Reader *T : image/jpeg.Reader *T : io.ByteReader *T : io.ByteScanner *T : io.Reader *T : io.ReaderAt *T : io.ReadSeeker *T : io.RuneReader *T : io.RuneScanner *T : io.Seeker *T : io.WriterTo func NewReader(b []byte) *Reader
Package-Level Functions (total 50)
Compare returns an integer comparing two byte slices lexicographically. The result will be 0 if a==b, -1 if a < b, and +1 if a > b. A nil argument is equivalent to an empty slice.
Contains reports whether subslice is within b.
ContainsAny reports whether any of the UTF-8-encoded code points in chars are within b.
ContainsRune reports whether the rune is contained in the UTF-8-encoded byte slice b.
Count counts the number of non-overlapping instances of sep in s. If sep is an empty slice, Count returns 1 + the number of UTF-8-encoded code points in s.
Equal reports whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.
EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.
Fields interprets s as a sequence of UTF-8-encoded code points. It splits the slice s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of subslices of s or an empty slice if s contains only white space.
FieldsFunc interprets s as a sequence of UTF-8-encoded code points. It splits the slice s at each run of code points c satisfying f(c) and returns a slice of subslices of s. If all code points in s satisfy f(c), or len(s) == 0, an empty slice is returned. FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.
HasPrefix tests whether the byte slice s begins with prefix.
HasSuffix tests whether the byte slice s ends with suffix.
Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
IndexAny interprets s as a sequence of UTF-8-encoded Unicode code points. It returns the byte index of the first occurrence in s of any of the Unicode code points in chars. It returns -1 if chars is empty or if there is no code point in common.
IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b.
IndexFunc interprets s as a sequence of UTF-8-encoded code points. It returns the byte index in s of the first Unicode code point satisfying f(c), or -1 if none do.
IndexRune interprets s as a sequence of UTF-8-encoded code points. It returns the byte index of the first occurrence in s of the given rune. It returns -1 if rune is not present in s. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.
Join concatenates the elements of s to create a new byte slice. The separator sep is placed between elements in the resulting slice.
LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.
LastIndexAny interprets s as a sequence of UTF-8-encoded Unicode code points. It returns the byte index of the last occurrence in s of any of the Unicode code points in chars. It returns -1 if chars is empty or if there is no code point in common.
LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
LastIndexFunc interprets s as a sequence of UTF-8-encoded code points. It returns the byte index in s of the last Unicode code point satisfying f(c), or -1 if none do.
Map returns a copy of the byte slice s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the byte slice with no replacement. The characters in s and the output are interpreted as UTF-8-encoded code points.
NewBuffer creates and initializes a new Buffer using buf as its initial contents. The new Buffer takes ownership of buf, and the caller should not use buf after this call. NewBuffer is intended to prepare a Buffer to read existing data. It can also be used to set the initial size of the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero. In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
NewBufferString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string. In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
NewReader returns a new Reader reading from b.
Repeat returns a new byte slice consisting of count copies of b. It panics if count is negative or if the result of (len(b) * count) overflows.
Replace returns a copy of the slice s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the slice and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune slice. If n < 0, there is no limit on the number of replacements.
ReplaceAll returns a copy of the slice s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the slice and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune slice.
Runes interprets s as a sequence of UTF-8-encoded code points. It returns a slice of runes (Unicode code points) equivalent to s.
Split slices s into all subslices separated by sep and returns a slice of the subslices between those separators. If sep is empty, Split splits after each UTF-8 sequence. It is equivalent to SplitN with a count of -1.
SplitAfter slices s into all subslices after each instance of sep and returns a slice of those subslices. If sep is empty, SplitAfter splits after each UTF-8 sequence. It is equivalent to SplitAfterN with a count of -1.
SplitAfterN slices s into subslices after each instance of sep and returns a slice of those subslices. If sep is empty, SplitAfterN splits after each UTF-8 sequence. The count determines the number of subslices to return: n > 0: at most n subslices; the last subslice will be the unsplit remainder. n == 0: the result is nil (zero subslices) n < 0: all subslices
SplitN slices s into subslices separated by sep and returns a slice of the subslices between those separators. If sep is empty, SplitN splits after each UTF-8 sequence. The count determines the number of subslices to return: n > 0: at most n subslices; the last subslice will be the unsplit remainder. n == 0: the result is nil (zero subslices) n < 0: all subslices
Title treats s as UTF-8-encoded bytes and returns a copy with all Unicode letters that begin words mapped to their title case. BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly.
ToLower returns a copy of the byte slice s with all Unicode letters mapped to their lower case.
ToLowerSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their lower case, giving priority to the special casing rules.
ToTitle treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their title case.
ToTitleSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their title case, giving priority to the special casing rules.
ToUpper returns a copy of the byte slice s with all Unicode letters mapped to their upper case.
ToUpperSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their upper case, giving priority to the special casing rules.
ToValidUTF8 treats s as UTF-8-encoded bytes and returns a copy with each run of bytes representing invalid UTF-8 replaced with the bytes in replacement, which may be empty.
Trim returns a subslice of s by slicing off all leading and trailing UTF-8-encoded code points contained in cutset.
TrimFunc returns a subslice of s by slicing off all leading and trailing UTF-8-encoded code points c that satisfy f(c).
TrimLeft returns a subslice of s by slicing off all leading UTF-8-encoded code points contained in cutset.
TrimLeftFunc treats s as UTF-8-encoded bytes and returns a subslice of s by slicing off all leading UTF-8-encoded code points c that satisfy f(c).
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
TrimRight returns a subslice of s by slicing off all trailing UTF-8-encoded code points that are contained in cutset.
TrimRightFunc returns a subslice of s by slicing off all trailing UTF-8-encoded code points c that satisfy f(c).
TrimSpace returns a subslice of s by slicing off all leading and trailing white space, as defined by Unicode.
TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.
Package-Level Variables (only one)
ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.
Package-Level Constants (only one)
MinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, ReadFrom will not grow the underlying buffer.