MCPcopy Create free account
hub / github.com/Facets-cloud/flow / computeAvgKBFileBytes

Function computeAvgKBFileBytes

internal/stats/report.go:168–190  ·  view source on GitHub ↗

computeAvgKBFileBytes returns the average byte size of *.md files in kbDir. Returns 0 if the directory is missing or empty.

(kbDir string)

Source from the content-addressed store, hash-verified

166// computeAvgKBFileBytes returns the average byte size of *.md files in kbDir.
167// Returns 0 if the directory is missing or empty.
168func computeAvgKBFileBytes(kbDir string) int64 {
169 entries, err := os.ReadDir(kbDir)
170 if err != nil {
171 return 0
172 }
173 var total int64
174 var count int
175 for _, e := range entries {
176 if e.IsDir() || !strings.HasSuffix(e.Name(), ".md") {
177 continue
178 }
179 fi, err := e.Info()
180 if err != nil {
181 continue
182 }
183 total += fi.Size()
184 count++
185 }
186 if count == 0 {
187 return 0
188 }
189 return total / int64(count)
190}
191
192// fileSize returns the byte size of the file at path, or 0 if it does not exist.
193func fileSize(path string) int64 {

Callers 1

BuildStatsFunction · 0.85

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected