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

HasVSIHandler to test if a VSIHandler is registered for a given prefix #133

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions godal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3898,6 +3898,11 @@ func RegisterVSIHandler(prefix string, handler KeySizerReaderAt, opts ...VSIHand
return nil
}

// HasVSIHandler returns true if a VSIHandler is registered for this prefix
func HasVSIHandler(prefix string) bool {
return handlers != nil && handlers[prefix].KeySizerReaderAt != nil
}

// BuildVRT runs the GDALBuildVRT function and creates a VRT dataset from a list of datasets
func BuildVRT(dstVRTName string, sourceDatasets []string, switches []string, opts ...BuildVRTOption) (*Dataset, error) {
bvo := buildVRTOpts{}
Expand Down
16 changes: 16 additions & 0 deletions godal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3459,6 +3459,22 @@ func (mvp mvpHandler) ReadAtMulti(k string, buf [][]byte, off []int64) ([]int, e
}
return b.(KeyMultiReader).ReadAtMulti(k, buf, off)
}
func TestHasVSIHandler(t *testing.T) { // stripPrefix false
assert.False(t, HasVSIHandler("unregistered_prefix://"))

vpa := vpHandler{datas: make(map[string]KeySizerReaderAt)}
err := RegisterVSIHandler("registered_prefix://", vpa, VSIHandlerStripPrefix(false))
assert.NoError(t, err)
assert.True(t, HasVSIHandler("registered_prefix://"))

// nil handler
err = RegisterVSIHandler("nil_prefix://", nil)
assert.NoError(t, err)
assert.False(t, HasVSIHandler("nil_prefix://"))

// unregistered_prefix
assert.False(t, HasVSIHandler("unregistered_prefix://"))
}

func TestVSIPrefix(t *testing.T) {
tifdat, _ := ioutil.ReadFile("testdata/test.tif")
Expand Down
Loading