go-billy icon indicating copy to clipboard operation
go-billy copied to clipboard

storage.ReadAt doesn't read with empty arrays

Open benjlai opened this issue 6 years ago • 1 comments

I think the line: l := int64(len(b)) should be l := int64(cap(b)) i.e. the length of data copied should be based on the capacity of the array and not how much it has already been filled by other data.

benjlai avatar Nov 03 '19 06:11 benjlai

here's the analogous operation in standard library docco:

https://golang.org/pkg/os/#File.ReadAt

ReadAt reads len(b) bytes from the File starting at byte offset off. It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n < len(b). At end of file, that error is io.EOF.

i assume that go-billy needs to implement the same behaviour for consistency with standard library filesystem.

if b is an array (not a slice) then len(b) and cap(b) wil be equal, and if b is an empty array it is not possible for ReadAt to read anything without allocating, which is the responsibility of the caller

anz-rfc avatar Nov 26 '19 22:11 anz-rfc