UNPKG

1.06 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isAssetCompressed = exports.compressAsset = void 0;
4/**
5 * Since audio or video can be base64-encoded, those can be really long strings.
6 * Since we track the `src` property for every frame, Node.JS can run out of memory easily. Instead of duplicating the src for every frame, we save memory by replacing the full base 64 encoded data with a string `same-as-[asset-id]-[frame]` referencing a previous asset with the same src.
7 */
8const compressAsset = (previousAssets, newAsset) => {
9 if (newAsset.src.length < 400) {
10 return newAsset;
11 }
12 const assetWithSameSrc = previousAssets.find((a) => a.src === newAsset.src);
13 if (!assetWithSameSrc) {
14 return newAsset;
15 }
16 return {
17 ...newAsset,
18 src: `same-as-${assetWithSameSrc.id}-${assetWithSameSrc.frame}`,
19 };
20};
21exports.compressAsset = compressAsset;
22const isAssetCompressed = (src) => {
23 return src.startsWith('same-as');
24};
25exports.isAssetCompressed = isAssetCompressed;