Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage.ReadAt doesn't read with empty arrays #77

Open
benjlai opened this issue Nov 3, 2019 · 1 comment
Open

storage.ReadAt doesn't read with empty arrays #77

benjlai opened this issue Nov 3, 2019 · 1 comment

Comments

@benjlai
Copy link

benjlai commented Nov 3, 2019

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.

@anz-rfc
Copy link

anz-rfc commented Nov 26, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants