XL: Implement new ReadAll API for files which are read in single call. (#1974)

Add a unit test as well.
This commit is contained in:
Harshavardhana
2016-06-25 14:51:06 -07:00
committed by Anand Babu (AB) Periasamy
parent ed2fdd90b0
commit 42286cba70
11 changed files with 211 additions and 48 deletions

View File

@@ -168,6 +168,20 @@ func (n networkStorage) StatFile(volume, path string) (fileInfo FileInfo, err er
return fileInfo, nil
}
// ReadAll - reads entire contents of the file at path until EOF, retuns the
// contents in a byte slice. Returns buf == nil if err != nil.
// This API is meant to be used on files which have small memory footprint, do
// not use this on large files as it would cause server to crash.
func (n networkStorage) ReadAll(volume, path string) (buf []byte, err error) {
if err = n.rpcClient.Call("Storage.ReadAllHandler", ReadAllArgs{
Vol: volume,
Path: path,
}, &buf); err != nil {
return nil, toStorageErr(err)
}
return buf, nil
}
// ReadFile - reads a file.
func (n networkStorage) ReadFile(volume string, path string, offset int64, buffer []byte) (m int64, err error) {
if err = n.rpcClient.Call("Storage.ReadFileHandler", ReadFileArgs{