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

Method readFile

deps/v8/tools/zone-stats/trace-file-reader.js:57–119  ·  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 // Decode data as strings of 64Kb chunks. Bigger chunks may cause
71 // parsing failures in Oboe.js.
72 const chunkedInflate = new pako.Inflate(
73 {to: 'string', chunkSize: 65536}
74 );
75 let processingState = undefined;
76 chunkedInflate.onData = (chunk) => {
77 if (processingState === undefined) {
78 processingState = this.startProcessing(file, chunk);
79 } else {
80 processingState.processChunk(chunk);
81 }
82 };
83 chunkedInflate.onEnd = () => {
84 if (processingState !== undefined) {
85 const result_data = processingState.endProcessing();
86 this.processLoadedData(file, result_data);
87 }
88 };
89 console.log("======");
90 const textResult = chunkedInflate.push(e.target.result);
91
92 this.section.className = 'success';
93 this.$('#fileReader').classList.add('done');
94 } catch (err) {
95 console.error(err);
96 this.section.className = 'failure';
97 }
98 };
99 // Delay the loading a bit to allow for CSS animations to happen.
100 setTimeout(() => reader.readAsArrayBuffer(file), 0);
101 } else {
102 reader.onload = (e) => {
103 try {
104 // Process the whole file in at once.
105 const processingState = this.startProcessing(file, e.target.result);
106 const dataModel = processingState.endProcessing();
107 this.processLoadedData(file, dataModel);
108
109 this.section.className = 'success';
110 this.$('#fileReader').classList.add('done');
111 } catch (err) {
112 console.error(err);
113 this.section.className = 'failure';
114 }

Callers 1

handleChangeMethod · 0.95

Calls 12

updateLabelMethod · 0.95
$Method · 0.95
startProcessingMethod · 0.95
processLoadedDataMethod · 0.95
includesMethod · 0.80
endProcessingMethod · 0.80
addMethod · 0.65
setTimeoutFunction · 0.50
processChunkMethod · 0.45
logMethod · 0.45
pushMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected