Skip to content

Commit

Permalink
HasVSIHandler to test if a VSIHandler is registered for a given prefix (
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvaroquauxads authored Sep 11, 2024
1 parent d610839 commit 203295b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit 203295b

Please sign in to comment.