MCPcopy
hub / github.com/g3n/engine / loadDataURL

Function loadDataURL

loader/gltf/loader.go:1154–1185  ·  view source on GitHub ↗

loadDataURL decodes the specified data URI string (base64).

(url string)

Source from the content-addressed store, hash-verified

1152
1153// loadDataURL decodes the specified data URI string (base64).
1154func loadDataURL(url string) ([]byte, error) {
1155
1156 var du dataURL
1157 err := parseDataURL(url, &du)
1158 if err != nil {
1159 return nil, err
1160 }
1161
1162 // Checks for valid media type
1163 found := false
1164 for i := 0; i < len(validMediaTypes); i++ {
1165 if validMediaTypes[i] == du.MediaType {
1166 found = true
1167 break
1168 }
1169 }
1170 if !found {
1171 return nil, fmt.Errorf("data URI media type:%s not supported", du.MediaType)
1172 }
1173
1174 // Checks encoding
1175 if du.Encoding != "base64" {
1176 return nil, fmt.Errorf("data URI encoding:%s not supported", du.Encoding)
1177 }
1178
1179 // Decodes data from BASE64
1180 data, err := base64.StdEncoding.DecodeString(du.Data)
1181 if err != nil {
1182 return nil, err
1183 }
1184 return data, nil
1185}
1186
1187// parseDataURL tries to parse the specified string as a data URL with the format:
1188// data:[<mediatype>][;base64],<data>

Callers 2

LoadImageMethod · 0.85
loadBufferMethod · 0.85

Calls 1

parseDataURLFunction · 0.85

Tested by

no test coverage detected