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