mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 21:07:41 +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 {
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue