mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
Implement GetObjectNInfo object layer call (#6290)
This combines calling GetObjectInfo and GetObject while returning a io.ReadCloser for the object's body. This allows the two operations to be under a single lock, fixing a race between getting object info and reading the object body.
This commit is contained in:
committed by
Nitish Tiwari
parent
cea4f82586
commit
e6d740ce09
@@ -126,3 +126,34 @@ func (nopCloser) Close() error { return nil }
|
||||
func NopCloser(w io.Writer) io.WriteCloser {
|
||||
return nopCloser{w}
|
||||
}
|
||||
|
||||
// SkipReader skips a given number of bytes and then returns all
|
||||
// remaining data.
|
||||
type SkipReader struct {
|
||||
io.Reader
|
||||
|
||||
skipCount int64
|
||||
}
|
||||
|
||||
func (s *SkipReader) Read(p []byte) (int, error) {
|
||||
l := int64(len(p))
|
||||
if l == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
for s.skipCount > 0 {
|
||||
if l > s.skipCount {
|
||||
l = s.skipCount
|
||||
}
|
||||
n, err := s.Reader.Read(p[:l])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
s.skipCount -= int64(n)
|
||||
}
|
||||
return s.Reader.Read(p)
|
||||
}
|
||||
|
||||
// NewSkipReader - creates a SkipReader
|
||||
func NewSkipReader(r io.Reader, n int64) io.Reader {
|
||||
return &SkipReader{r, n}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user