bytes

package
v1.19.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bytes is a bytes extended libary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Replace

func Replace(b []byte, src, dest []byte, n int) []byte

Unlike bytes.Replace, this Replace does replace operations in place.

func ReplaceAt

func ReplaceAt(b []byte, off, nsrc int, dest []byte) []byte

ReplaceAt does a replace operation at position `off` in place.

func ReplaceOne

func ReplaceOne(b []byte, from int, src, dest []byte) ([]byte, int)

ReplaceOne does a replace operation from `from` position in place. It returns an offset for next replace operation. If the returned offset is -1, it means no replace operation occurred.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a random read/write memory file that supports ReadAt/WriteAt methods instead of Read/Write:

b := bytes.NewBuffer()
b.Truncate(100)
b.WriteAt([]byte("hello"), 100)
slice := make([]byte, 105)
n, err := b.ReadAt(slice, 0)
...

func (*Buffer) Buffer

func (p *Buffer) Buffer() []byte

func (*Buffer) Len

func (p *Buffer) Len() int

func (*Buffer) ReadAt

func (p *Buffer) ReadAt(buf []byte, off int64) (n int, err error)

func (*Buffer) Truncate

func (p *Buffer) Truncate(fsize int64) (err error)

func (*Buffer) WriteAt

func (p *Buffer) WriteAt(buf []byte, off int64) (n int, err error)

func (*Buffer) WriteStringAt

func (p *Buffer) WriteStringAt(buf string, off int64) (n int, err error)

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Unlike the standard library's bytes.Reader, this Reader supports Seek.

func NewReader

func NewReader(val []byte) *Reader

NewReader create a readonly stream for byte slice:

var slice []byte
...
r := bytes.NewReader(slice)
...
r.Seek(0, 0) // r.SeekToBegin()
...

Unlike the standard library's bytes.Reader, the returned Reader supports Seek.

func (*Reader) Bytes

func (r *Reader) Bytes() []byte

func (*Reader) Close

func (r *Reader) Close() (err error)

func (*Reader) Len

func (r *Reader) Len() int

func (*Reader) Read

func (r *Reader) Read(val []byte) (n int, err error)

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (ret int64, err error)

func (*Reader) SeekToBegin

func (r *Reader) SeekToBegin() (err error)

func (*Reader) Size added in v1.12.20

func (r *Reader) Size() int64

Size returns the original length of the underlying byte slice.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer implements a write stream with a limited capacity.

func NewWriter

func NewWriter(buff []byte) *Writer

NewWriter NewWriter creates a write stream with a limited capacity:

slice := make([]byte, 1024)
w := bytes.NewWriter(slice)
...
writtenData := w.Bytes()

If we write more than 1024 bytes of data to w, the excess data will be discarded.

func (*Writer) Bytes

func (p *Writer) Bytes() []byte

func (*Writer) Len

func (p *Writer) Len() int

func (*Writer) Reset

func (p *Writer) Reset()

Reset deletes all written data.

func (*Writer) Write

func (p *Writer) Write(val []byte) (n int, err error)

Directories

Path Synopsis
This package provide a method to read and replace http.Request's body.
This package provide a method to read and replace http.Request's body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL