Skip to content

Commit

Permalink
[preprocessor/wacz] use readline instead of readstring to reduce mem …
Browse files Browse the repository at this point in the history
…usage
  • Loading branch information
williamchong committed Jun 17, 2024
1 parent b09bec5 commit 054999e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions preprocessor/wacz/wacz.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,26 @@ func findUserAgent(packageData waczPackageData, fileMap map[string]*zip.File) (s

reader := bufio.NewReader(file)
for {
line, err := reader.ReadString('\n')
lineBytes, isPrefix, err := reader.ReadLine()
if err != nil {
if err == io.EOF {
break
}
if err != bufio.ErrBufferFull {
return "", err
return "", err
}
if isPrefix {
// discard the rest of the long line
for isPrefix {
_, isPrefix, err = reader.ReadLine()
if err != nil {
if err == io.EOF {
break
}
return "", err
}
}
}
line := string(lineBytes)
if strings.Contains(line, "user-agent: ") || strings.Contains(line, "User-Agent: ") {
return line[strings.Index(line, ":")+2:], nil
}
Expand Down

0 comments on commit 054999e

Please sign in to comment.