Fix profile render when the README.md size is larger than 1024 bytes (#25270)

Backport #25131
This commit is contained in:
yp05327 2023-06-15 10:39:34 +09:00 committed by GitHub
parent 037366f93f
commit d686aa0d31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 114 additions and 10 deletions

View file

@ -20,17 +20,18 @@ func (b *Blob) Name() string {
return b.name
}
// GetBlobContent Gets the content of the blob as raw text
func (b *Blob) GetBlobContent() (string, error) {
// GetBlobContent Gets the limited content of the blob as raw text
func (b *Blob) GetBlobContent(limit int64) (string, error) {
if limit <= 0 {
return "", nil
}
dataRc, err := b.DataAsync()
if err != nil {
return "", err
}
defer dataRc.Close()
buf := make([]byte, 1024)
n, _ := util.ReadAtMost(dataRc, buf)
buf = buf[:n]
return string(buf), nil
buf, err := util.ReadWithLimit(dataRc, int(limit))
return string(buf), err
}
// GetBlobLineCount gets line count of the blob