MCPcopy Create free account
hub / github.com/Snapchat/Valdi / preprocess

Method preprocess

valdi/src/valdi/runtime/Resources/Remote/RemoteModuleManager.cpp:78–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76 : _diskCache(std::move(diskCache)), _logger(logger) {}
77
78Result<BytesView> ResourcesBundleResultTransformer::preprocess(const StringBox& localFilename,
79 const BytesView& remoteData) const {
80 if (_diskCache == nullptr) {
81 return Error("Cannot load resources without a disk cache");
82 }
83
84 _diskCache->remove(Path(localFilename));
85
86 Result<ValdiModuleArchive> decompressedBundleResult;
87 if (_decompressionDisabled) {
88 decompressedBundleResult = ValdiModuleArchive::deserialize(remoteData);
89 } else {
90 decompressedBundleResult = ValdiModuleArchive::decompress(remoteData.data(), remoteData.size());
91 }
92
93 if (!decompressedBundleResult) {
94 return decompressedBundleResult.moveError();
95 }
96
97 auto decompressedBundle = Valdi::makeShared<ValdiModuleArchive>(decompressedBundleResult.moveValue());
98
99 ValdiArchiveBuilder manifestBuilder;
100
101 Path cacheDirectoryPath(localFilename.toStringView());
102 cacheDirectoryPath.removeFileExtension();
103 cacheDirectoryPath.appendFileExtension("dir");
104
105 for (const auto& path : decompressedBundle->getAllEntryPaths()) {
106 auto entry = decompressedBundle->getEntry(path);
107 SC_ASSERT(entry.has_value(), "Unable to retrieve module entry");
108
109 auto bytesView = BytesView(decompressedBundle, entry->data, entry->size);
110
111 auto cachePath = cacheDirectoryPath.appending(path.toStringView());
112
113 auto storeSuccess = _diskCache->store(cachePath, bytesView);
114 if (!storeSuccess) {
115 return storeSuccess.error().rethrow(
116 STRING_FORMAT("Failed to store resource item '{}' in disk cache", path));
117 }
118
119 manifestBuilder.addEntry(ValdiArchiveEntry(path, cachePath.toStringBox()));
120 }
121
122 auto moduleBytes = manifestBuilder.build();
123 return moduleBytes->toBytesView();
124}
125
126std::string_view ResourcesBundleResultTransformer::getItemTypeDescription() const {
127 return "assets package";

Callers 1

Calls 15

getAllEntryPathsMethod · 0.80
rethrowMethod · 0.80
addEntryMethod · 0.80
ValdiArchiveEntryClass · 0.70
removeMethod · 0.65
storeMethod · 0.65
errorMethod · 0.65
ErrorInterface · 0.50
PathClass · 0.50
BytesViewClass · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected