INNER CODE UNIT · JavaScript
encodeMimeTypes
gildas-lormeau/zip.js · generate-mime-type-data.js:56
function encodeMimeTypes(table) {
const blocks = [];
for (const type of Object.keys(table).sort()) {
const entries = [];
let previousSubtype = "";
for (const subtype of Object.keys(table[type]).sort()) {
const markedSubtype = subtype.replaceAll(XML_SUFFIX, XML_MARKER);
let sharedLength = 0;
const maxSharedLength = Math.min(previousSubtype.length, markedSubtype.length, MAX_SHARED_PREFIX_LENGTH);
while (sharedLength < maxSharedLength && previousSubtype[sharedLength] == markedSubtype[sharedLength]) {
sharedLength++;
}
previousSubtype = markedSubtype;
const key = sharedLength.toString(36) + markedSubtype.slice(sharedLength);
const value = table[type][subtype];
const extensions = typeof value == "string" ? [value] : value;
if (extensions.length == 1 && extensions[0] == subtype.split("+")[0]) {
entries.push(key);