Skip to content

Commit

Permalink
Seek to timestamp mostly working now - need to fix off-by-one error w…
Browse files Browse the repository at this point in the history
…hen selecting last timestamp in file.

Co-authored-by: Benjamin Ross <[email protected]>
  • Loading branch information
Blake Bender and BenjaminPerryRoss committed Jun 29, 2018
1 parent b153ce6 commit 11f7a5a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
26 changes: 20 additions & 6 deletions fileManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function indexFile(fileName) {

function getIndexForTimestamp(timestamp) {
for (var i = 0; i < linesIndex.timestamps.length; i++) {
if (linesIndex.timestamps[i] <= timestamp) {
return i;
if (linesIndex.timestamps[i] > timestamp) {
return (i > 0) ? i - 1 : i;
}
}
return -1;
Expand All @@ -81,15 +81,20 @@ function displayLines(timestamp) {
var totalLinesRead = 0;
var buffer = new Buffer(100000);
var offset = 0;
var fd = fs.openSync(linesIndex.fileNames[index], "r");

while(buffer.toString().split("\n").length < linesToDisplay())
while(buffer.toString().split("\n").length < linesToDisplay() && index < linesIndex.timestamps.length)
{
var fd = fs.openSync(linesIndex.fileNames[index], "r");
offset += fs.readSync(fd, buffer, offset, linesIndex.fileOffsets[index], linesIndex.lengths[index]);
console.log("Attempting to read " + linesIndex.lengths[index] + " bytes at offset " + linesIndex.fileOffsets[index]);
console.log("Line count is " + buffer.toString().split("\n").length);

offset += fs.readSync(fd, buffer, offset, linesIndex.lengths[index], linesIndex.fileOffsets[index]);

index++;
}

fs.closeSync(fd);

var withBreaks = buffer.toString().split("\n").join("<br />");

document.querySelector('#textGoesHere').innerHTML = withBreaks;
Expand Down Expand Up @@ -123,7 +128,16 @@ function populateTimeList()
}

timestampComboBox.innerHTML = options;
timestampComboBox.addEventListener('onchange', timeSelected);
console.log("onChange event handler set to " + timestampComboBox.onChange);
}

var timestampComboBox = document.getElementById('timestampCombo');
function timeSelected() {
var timestamp = timestampComboBox.options[timestampComboBox.selectedIndex].value;
displayLines(timestamp);
}

var timestampComboBox = document.querySelector('#timestampCombo');

document.querySelector('#fileOpenButton').addEventListener('click', openFile);
document.querySelector('#updateTime').addEventListener('click', timeSelected);
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ <h1>Hello World!</h1>
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<button id="fileOpenButton">Open</button>
<select id="timestampCombo">
<button id="updateTime">Open</button>
<select id="timestampCombo" onchange="timeSelected()">
</select>
<p id="textGoesHere"></p>
</body>
Expand Down

0 comments on commit 11f7a5a

Please sign in to comment.