Add GetObjectNInfo to object layer (#6449)

The new call combines GetObjectInfo and GetObject, and returns an
object with a ReadCloser interface.

Also adds a number of end-to-end encryption tests at the handler
level.
This commit is contained in:
Aditya Manthramurthy
2018-09-20 19:22:09 -07:00
committed by Harshavardhana
parent 7d0645fb3a
commit 36e51d0cee
30 changed files with 2335 additions and 439 deletions

View File

@@ -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}
}

View File

@@ -17,6 +17,8 @@
package ioutil
import (
"bytes"
"io"
goioutil "io/ioutil"
"os"
"testing"
@@ -73,3 +75,29 @@ func TestAppendFile(t *testing.T) {
t.Errorf("AppendFile() failed, expected: %s, got %s", expected, string(b))
}
}
func TestSkipReader(t *testing.T) {
testCases := []struct {
src io.Reader
skipLen int64
expected string
}{
{bytes.NewBuffer([]byte("")), 0, ""},
{bytes.NewBuffer([]byte("")), 1, ""},
{bytes.NewBuffer([]byte("abc")), 0, "abc"},
{bytes.NewBuffer([]byte("abc")), 1, "bc"},
{bytes.NewBuffer([]byte("abc")), 2, "c"},
{bytes.NewBuffer([]byte("abc")), 3, ""},
{bytes.NewBuffer([]byte("abc")), 4, ""},
}
for i, testCase := range testCases {
r := NewSkipReader(testCase.src, testCase.skipLen)
b, err := goioutil.ReadAll(r)
if err != nil {
t.Errorf("Case %d: Unexpected err %v", i, err)
}
if string(b) != testCase.expected {
t.Errorf("Case %d: Got wrong result: %v", i, string(b))
}
}
}