You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

io.go 569B

1234567891011121314151617181920
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. import (
  6. "io"
  7. )
  8. // ReadAtMost reads at most len(buf) bytes from r into buf.
  9. // It returns the number of bytes copied. n is only less then len(buf) if r provides fewer bytes.
  10. // If EOF occurs while reading, err will be nil.
  11. func ReadAtMost(r io.Reader, buf []byte) (n int, err error) {
  12. n, err = io.ReadFull(r, buf)
  13. if err == io.EOF || err == io.ErrUnexpectedEOF {
  14. err = nil
  15. }
  16. return
  17. }