------------------------------------------------------------------------------
| 302 | |
| 303 | //------------------------------------------------------------------------------ |
| 304 | vtkSmartPointer<vtkResourceStream> vtkURILoader::LoadData(const vtkURI& uri) |
| 305 | { |
| 306 | const auto& path = uri.GetPath().GetValue(); |
| 307 | const auto info = ExtractDataURI(path.data(), path.data() + path.size()); |
| 308 | |
| 309 | if (info.base64) |
| 310 | { |
| 311 | const auto size = static_cast<std::size_t>(std::distance(info.Begin, info.End)); |
| 312 | if (size % 4 != 0) |
| 313 | { |
| 314 | vtkErrorMacro("Truncated base64 data. " << size << " is not a multiple of 4."); |
| 315 | return nullptr; |
| 316 | } |
| 317 | |
| 318 | std::vector<unsigned char> data; |
| 319 | data.resize(size / 4 * 3); // 4 base64 value -> 3 bytes |
| 320 | const auto decoded = vtksysBase64_Decode( |
| 321 | reinterpret_cast<const unsigned char*>(info.Begin), data.size(), data.data(), size); |
| 322 | data.resize(decoded); |
| 323 | |
| 324 | auto stream = vtkSmartPointer<vtkMemoryResourceStream>::New(); |
| 325 | stream->SetBuffer(std::move(data)); |
| 326 | |
| 327 | return stream; |
| 328 | } |
| 329 | |
| 330 | // raw data: convert %xx in string if any |
| 331 | auto data = vtkURI::PercentDecode(info.Begin, std::distance(info.Begin, info.End)); |
| 332 | |
| 333 | auto stream = vtkSmartPointer<vtkMemoryResourceStream>::New(); |
| 334 | stream->SetBuffer(std::move(data)); |
| 335 | |
| 336 | return stream; |
| 337 | } |
| 338 | |
| 339 | //------------------------------------------------------------------------------ |
| 340 | void vtkURILoader::PrintSelf(ostream& os, vtkIndent indent) |