iox

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy 类似于 io.Copy, 但内部使用 bytebufferpool 来获取临时缓冲区, 以减少内存分配. 这在需要高性能、高并发拷贝大量数据的场景下非常有用.

func CopyBuffer

func CopyBuffer(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)

CopyBuffer 类似于 io.CopyBuffer, 但在需要时会使用 bytebufferpool 来分配缓冲区. 如果 buf 为 nil, 将从池中获取一个; 如果 buf 长度为0, 会导致 panic. 如果 src 实现了 io.WriterTo 或 dst 实现了 io.ReaderFrom, 将不会使用 buf.

func CopyN

func CopyN(dst io.Writer, src io.Reader, n int64) (written int64, err error)

CopyN 从 src 拷贝 n 字节数据到 dst (或在遇到错误时提前停止). 它返回拷贝的字节数和拷贝时遇到的第一个错误. 仅当 err == nil 时, written == n 才会成立.

此实现利用了池化的 copyb.Copy 和标准的 io.LimitReader, 以实现高性能.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll 从 Reader r 中读取所有数据直到 EOF, 并返回读取的数据. 它使用 bytebufferpool 来获取一个大的临时缓冲区, 避免了标准库 io.ReadAll 在读取过程中可能发生的多次内存分配和拷贝, 从而显著降低GC压力.

函数会返回一个全新的数据切片副本, 池化的缓冲区会被安全地回收.

Types

This section is empty.

Jump to

Keyboard shortcuts

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