/
githubmirror
/
trivy
Обзор
Документация
Войти
/
githubmirror
/
trivy
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
pkg/x/io/counting_reader.go
32 строки
793 B
DmitriyLewen
feat(image): save layers metadata into report (#8394)
23 апр 2025, 19:31
Не верифицирован
23 апр 2025, 19:31
a95cab0
Код
Авторство
О чём код?
package io import ( "io" ) // CountingReader wraps an io.Reader and counts the number of bytes read. // Note: This implementation is NOT thread-safe. It should not be used // concurrently from multiple goroutines. type CountingReader struct { r io.Reader bytesRead int64 } // NewCountingReader creates a new CountingReader that wraps the provided io.Reader. func NewCountingReader(r io.Reader) *CountingReader { return &CountingReader{r: r} } // Read reads data from the underlying reader and counts the number of bytes read. func (c *CountingReader) Read(p []byte) (int, error) { n, err := c.r.Read(p) if n > 0 { c.bytesRead += int64(n) } return n, err } // BytesRead returns the number of bytes read. func (c *CountingReader) BytesRead() int64 { return c.bytesRead }