4static std::vector<std::byte> streamToVector(juce::InputStream &stream)
7 const auto sizeInBytes =
static_cast<size_t>(stream.getTotalLength());
8 std::vector<std::byte> result(sizeInBytes);
10 [[maybe_unused]]
const auto bytesRead = stream.read(result.data(), result.size());
11 jassert(bytesRead ==
static_cast<ssize_t
>(sizeInBytes));
17static std::vector<std::byte> getWebViewFileAsBytes(
const juce::String &filepath)
19 std::ignore = filepath;
21 juce::MemoryInputStream zipStream{webview_files::webview_files_zip, webview_files::webview_files_zipSize,
false};
22 juce::ZipFile zipFile{zipStream};
24 if (
auto *zipEntry = zipFile.getEntry(ZIPPED_FILES_PREFIX + filepath))
26 const std::unique_ptr<juce::InputStream> entryStream{zipFile.createStreamForEntry(*zipEntry)};
28 if (entryStream ==
nullptr)
34 return streamToVector(*entryStream);
41static const char *getMimeForExtension(
const juce::String &extension)
43 static const std::unordered_map<juce::String, const char *> mimeMap = {{{
"htm"},
"text/html"},
44 {{
"html"},
"text/html"},
45 {{
"txt"},
"text/plain"},
46 {{
"jpg"},
"image/jpeg"},
47 {{
"jpeg"},
"image/jpeg"},
48 {{
"svg"},
"image/svg+xml"},
49 {{
"ico"},
"image/vnd.microsoft.icon"},
50 {{
"json"},
"application/json"},
51 {{
"png"},
"image/png"},
52 {{
"css"},
"text/css"},
53 {{
"map"},
"application/json"},
54 {{
"js"},
"text/javascript"},
55 {{
"woff2"},
"font/woff2"}};
57 if (
const auto it = mimeMap.find(extension.toLowerCase()); it != mimeMap.end())