mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-06 05:17:38 +03:00
Fix discard func
This commit is contained in:
parent
8ed9641213
commit
3b6fbee16a
2 changed files with 6 additions and 6 deletions
|
@ -13,7 +13,7 @@ func Skip(reader io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func SkipN(reader io.Reader, size int) 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) {
|
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) {
|
func ReadBytes(reader io.Reader, size int) ([]byte, error) {
|
||||||
b := make([]byte, size)
|
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 nil, err
|
||||||
}
|
}
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
|
@ -24,15 +24,15 @@ func WriteZeroN(writer io.Writer, size int) error {
|
||||||
var index int
|
var index int
|
||||||
for index < size {
|
for index < size {
|
||||||
next := index + 1024
|
next := index + 1024
|
||||||
if next < size {
|
if next > size {
|
||||||
|
_, err := writer.Write(ZeroBytes[:size-index])
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
_, err := writer.Write(ZeroBytes)
|
_, err := writer.Write(ZeroBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
index = next
|
index = next
|
||||||
} else {
|
|
||||||
_, err := writer.Write(ZeroBytes[:size-index])
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue