Fix discard func

This commit is contained in:
世界 2022-05-22 09:06:30 +08:00
parent 8ed9641213
commit 3b6fbee16a
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 6 additions and 6 deletions

View file

@ -13,7 +13,7 @@ func Skip(reader io.Reader) error {
}
func SkipN(reader io.Reader, size int) error {
return common.Error(ReadBytes(reader, size))
return common.Error(io.CopyN(io.Discard, reader, int64(size)))
}
func ReadByte(reader io.Reader) (byte, error) {
@ -29,7 +29,7 @@ func ReadByte(reader io.Reader) (byte, error) {
func ReadBytes(reader io.Reader, size int) ([]byte, error) {
b := make([]byte, size)
if err := common.Error(io.ReadFull(reader, b[:])); err != nil {
if err := common.Error(io.ReadFull(reader, b)); err != nil {
return nil, err
}
return b, nil

View file

@ -24,15 +24,15 @@ func WriteZeroN(writer io.Writer, size int) error {
var index int
for index < size {
next := index + 1024
if next < size {
if next > size {
_, err := writer.Write(ZeroBytes[:size-index])
return err
} else {
_, err := writer.Write(ZeroBytes)
if err != nil {
return err
}
index = next
} else {
_, err := writer.Write(ZeroBytes[:size-index])
return err
}
}
return nil