mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 02:04:01 +03:00
FILE / ScuroNeko/mtg
_utils/read_current_data.go
Исходный файл и его история в репозитории.
22 lines
480 B
Go
22 lines
480 B
Go
package utils
|
|
|
|
import "io"
|
|
|
|
const readCurrentDataBufferSize = 1024 + 1 // + 1 because telegram operates with blocks mod 4
|
|
|
|
// ReadCurrentData reads all data from io.Reader which is ready to be read.
|
|
func ReadCurrentData(src io.Reader) (rv []byte, err error) {
|
|
buf := make([]byte, readCurrentDataBufferSize)
|
|
n := readCurrentDataBufferSize
|
|
|
|
for n == len(buf) {
|
|
n, err = src.Read(buf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rv = append(rv, buf[:n]...)
|
|
}
|
|
|
|
return rv, nil
|
|
}
|