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