MCPcopy
hub / github.com/gchq/CyberChef / formatFile

Method formatFile

src/core/Utils.mjs:1075–1119  ·  view source on GitHub ↗
(file, i)

Source from the content-addressed store, hash-verified

1073 };
1074
1075 const formatFile = async function(file, i) {
1076 const buff = await Utils.readFile(file);
1077 const blob = new Blob(
1078 [buff],
1079 {type: file.type || "octet/stream"}
1080 );
1081 const blobURL = URL.createObjectURL(blob);
1082
1083 const html = `<div class='card' style='white-space: normal;'>
1084 <div class='card-header' id='heading${i}'>
1085 <h6 class='mb-0'>
1086 <a class='collapsed'
1087 data-toggle='collapse'
1088 href='#collapse${i}'
1089 aria-expanded='false'
1090 aria-controls='collapse${i}'
1091 title="Show/hide contents of '${Utils.escapeHtml(file.name)}'">
1092 ${Utils.escapeHtml(file.name)}</a>
1093 <span class='float-right' style="margin-top: -3px">
1094 ${file.size.toLocaleString()} bytes
1095 <a title="Download ${Utils.escapeHtml(file.name)}"
1096 href="${blobURL}"
1097 download="${Utils.escapeHtml(file.name)}"
1098 data-toggle="tooltip">
1099 <i class="material-icons" style="vertical-align: bottom">save</i>
1100 </a>
1101 <a title="Move to input"
1102 href="#"
1103 blob-url="${blobURL}"
1104 file-name="${Utils.escapeHtml(file.name)}"
1105 class="extract-file"
1106 data-toggle="tooltip">
1107 <i class="material-icons" style="vertical-align: bottom">open_in_browser</i>
1108 </a>
1109 </span>
1110 </h6>
1111 </div>
1112 <div id='collapse${i}' class='collapse' aria-labelledby='heading${i}' data-parent="#files">
1113 <div class='card-body'>
1114 ${formatContent(buff, file.type)}
1115 </div>
1116 </div>
1117 </div>`;
1118 return html;
1119 };
1120
1121 let html = `<div style='padding: 5px; white-space: normal;'>
1122 ${files.length} file(s) found

Callers

nothing calls this directly

Calls 2

readFileMethod · 0.80
escapeHtmlMethod · 0.80

Tested by

no test coverage detected