/
githubmirror
/
gitleaks
ΠΠ±Π·ΠΎΡ
ΠΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΡ
ΠΠΎΠΉΡΠΈ
/
githubmirror
/
gitleaks
ΠΠΎΠ΄
ΠΠ°Π΄Π°ΡΠΈ
ΠΠΈΠΊΠΈ
ΠΠ°ΠΊΠ΅ΡΡ
0
Π Π΅Π»ΠΈΠ·Ρ
0
ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°
ΠΠ΅Π·ΠΎΠΏΠ°ΡΠ½ΠΎΡΡΡ
v8.19.2
detect/reader.go
43 ΡΡΡΠΎΠΊΠΈ
885 B
Richard Gomez
fix(detect): handle EOF with bytes (#1472)
19 Π°Π²Π³ 2024, 22:00
ΠΠ΅ Π²Π΅ΡΠΈΡΠΈΡΠΈΡΠΎΠ²Π°Π½
19 Π°Π²Π³ 2024, 22:00
f361c5e
ΠΠΎΠ΄
ΠΠ²ΡΠΎΡΡΡΠ²ΠΎ
Π ΡΡΠΌ ΠΊΠΎΠ΄?
package detect import ( "bufio" "io" "github.com/zricethezav/gitleaks/v8/report" ) // DetectReader accepts an io.Reader and a buffer size for the reader in KB func (d *Detector) DetectReader(r io.Reader, bufSize int) ([]report.Finding, error) { reader := bufio.NewReader(r) buf := make([]byte, 0, 1000*bufSize) findings := []report.Finding{} for { n, err := reader.Read(buf[:cap(buf)]) // "Callers should always process the n > 0 bytes returned before considering the error err." // https://pkg.go.dev/io#Reader if n > 0 { buf = buf[:n] fragment := Fragment{ Raw: string(buf), } for _, finding := range d.Detect(fragment) { findings = append(findings, finding) if d.Verbose { printFinding(finding, d.NoColor) } } } if err != nil { if err != io.EOF { return findings, err } break } } return findings, nil }