MCPcopy Index your code
hub / github.com/nodejs/node / readFile

Method readFile

deps/v8/tools/heap-stats/trace-file-reader.js:57–116  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

55 }
56
57 readFile(file) {
58 if (!file) {
59 this.updateLabel('Failed to load file.');
60 return;
61 }
62 this.$('#fileReader').blur();
63
64 this.section.className = 'loading';
65 const reader = new FileReader();
66
67 if (['application/gzip', 'application/x-gzip'].includes(file.type)) {
68 reader.onload = (e) => {
69 try {
70 const textResult = pako.inflate(e.target.result, {to: 'string'});
71 this.processRawText(file, textResult);
72 this.section.className = 'success';
73 this.$('#fileReader').classList.add('done');
74 } catch (err) {
75 console.error(err);
76 this.section.className = 'failure';
77 }
78 };
79 // Delay the loading a bit to allow for CSS animations to happen.
80 setTimeout(() => reader.readAsArrayBuffer(file), 0);
81 } else if (file.type == 'text/html') {
82 // try extracting the data from a results.html file
83 reader.onload = (e) => {
84 try {
85 let html = document.createElement('html');
86 html.innerHTML = e.target.result;
87 for (let dataScript of html.querySelectorAll('#viewer-data')) {
88 const base64 = dataScript.innerText.slice(1,-1);
89 const binary = globalThis.atob(base64);
90 const textResult = pako.inflate(binary, {to: 'string'});
91 this.processRawText(file, textResult);
92 }
93 this.section.className = 'success';
94 this.$('#fileReader').classList.add('done');
95 } catch (err) {
96 console.error(err);
97 this.section.className = 'failure';
98 }
99 };
100 // Delay the loading a bit to allow for CSS animations to happen.
101 setTimeout(() => reader.readAsText(file), 0);
102 } else {
103 reader.onload = (e) => {
104 try {
105 this.processRawText(file, e.target.result);
106 this.section.className = 'success';
107 this.$('#fileReader').classList.add('done');
108 } catch (err) {
109 console.error(err);
110 this.section.className = 'failure';
111 }
112 };
113 // Delay the loading a bit to allow for CSS animations to happen.
114 setTimeout(() => reader.readAsText(file), 0);

Callers 1

handleChangeMethod · 0.95

Calls 11

updateLabelMethod · 0.95
$Method · 0.95
processRawTextMethod · 0.95
includesMethod · 0.80
createElementMethod · 0.80
atobMethod · 0.80
addMethod · 0.65
sliceMethod · 0.65
setTimeoutFunction · 0.50
errorMethod · 0.45
querySelectorAllMethod · 0.45

Tested by

no test coverage detected