MCPcopy Create free account
hub / github.com/Kitware/VTK / LoadData

Method LoadData

IO/Core/vtkURILoader.cxx:304–337  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

302
303//------------------------------------------------------------------------------
304vtkSmartPointer<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//------------------------------------------------------------------------------
340void vtkURILoader::PrintSelf(ostream& os, vtkIndent indent)

Callers 1

DoLoadMethod · 0.95

Calls 10

ExtractDataURIFunction · 0.85
PercentDecodeFunction · 0.85
distanceFunction · 0.50
NewFunction · 0.50
GetValueMethod · 0.45
GetPathMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
SetBufferMethod · 0.45

Tested by

no test coverage detected