Skip to content

Commit

Permalink
file bucket can return bytes than requested
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Feb 25, 2024
1 parent e0f80f9 commit 08536b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 7 additions & 3 deletions pmtiles/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ func (m mockBucket) NewRangeReaderEtag(_ context.Context, key string, offset int
if len(etag) > 0 && resultEtag != etag {
return nil, "", 412, &RefreshRequiredError{}
}
if offset+length > int64(len(bs)) {
if offset > int64(len(bs)) {
return nil, "", 416, &RefreshRequiredError{416}
}

return io.NopCloser(bytes.NewReader(bs[offset:(offset + length)])), resultEtag, 206, nil
end := offset + length
if end > int64(len(bs)) {
end = int64(len(bs))
}
return io.NopCloser(bytes.NewReader(bs[offset:end])), resultEtag, 206, nil
}

// FileBucket is a bucket backed by a directory on disk
Expand Down Expand Up @@ -125,7 +129,7 @@ func (b FileBucket) NewRangeReaderEtag(_ context.Context, key string, offset, le
result := make([]byte, length)
read, err := file.ReadAt(result, offset)

if err == io.EOF && offset == 0 {
if err == io.EOF {
part := result[0:read]
return io.NopCloser(bytes.NewReader(part)), newEtag, 206, nil
}
Expand Down
3 changes: 0 additions & 3 deletions pmtiles/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ func fakeArchive(t *testing.T, header HeaderV3, metadata map[string]interface{},
archiveBytes = append(archiveBytes, metadataBytes...)
archiveBytes = append(archiveBytes, leavesBytes...)
archiveBytes = append(archiveBytes, tileDataBytes...)
if len(archiveBytes) < 16384 {
archiveBytes = append(archiveBytes, make([]byte, 16384-len(archiveBytes))...)
}
return archiveBytes
}

Expand Down

0 comments on commit 08536b9

Please sign in to comment.