package yu_io

import (
	"io"
)

// ReadAll
//
//	@Description: 从流中读取所有数据
func ReadAll(r io.Reader) []byte {
	j_buf := make([]byte, 0, 8192)
	for {
		if len(j_buf) == cap(j_buf) {
			// Add more capacity (let append pick how much).
			j_buf = append(j_buf, 0)[:len(j_buf)]
		}
		n, err := r.Read(j_buf[len(j_buf):cap(j_buf)])
		j_buf = j_buf[:len(j_buf)+n]
		if err != nil {
			return j_buf
		}
	}
}

// ReadAllS
//
//	@Description: 从流中读取所有数据
func ReadAllS(r io.Reader) string {
	return string(ReadAll(r))
}

// ReadAllClose
//
//	@Description: 从流中读取所有数据并关闭流
func ReadAllClose(r io.ReadCloser) []byte {
	defer r.Close()
	return ReadAll(r)
}

// ReadAllSClose
//
//	@Description: 从流中读取所有数据并关闭流
func ReadAllSClose(r io.ReadCloser) string {
	return string(ReadAllClose(r))
}
