-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlisting-4.3.js
More file actions
28 lines (19 loc) · 684 Bytes
/
listing-4.3.js
File metadata and controls
28 lines (19 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict";
const fs = require('fs');
const buffer = fs.readFileSync("./data/earthquakes.bin");
const numRecords = buffer.readInt32LE(0);
let bufferOffset = 4;
const records = [];
for (let recordIndex = 0; recordIndex < numRecords; ++recordIndex) {
const time = buffer.readDoubleLE(bufferOffset);
const record = {
Time: new Date(time),
Latitude: buffer.readDoubleLE(bufferOffset + 8),
Longitude: buffer.readDoubleLE(bufferOffset + 16),
Depth_Km: buffer.readDoubleLE(bufferOffset + 24),
Magnitude: buffer.readDoubleLE(bufferOffset + 32),
};
bufferOffset += 8 * 5;
records.push(record);
}
console.log(records);