frostfs-s3-gw/api/layer/detector.go
Evgeniy Kulikov 31d3e55489 Add content detector
Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
2020-11-27 15:33:31 +03:00

26 lines
345 B
Go

package layer
import (
"io"
"net/http"
"sync"
)
type detector struct {
io.Reader
sync.Once
contentType string
}
func newDetector(r io.Reader) *detector {
return &detector{Reader: r}
}
func (d *detector) Read(data []byte) (int, error) {
d.Do(func() {
d.contentType = http.DetectContentType(data)
})
return d.Reader.Read(data)
}