JavaScript
// by Anton Purin, 2015 MIT https://github.com/anpur/client-line-navigator
function LineNavigator(e,t,n){function c(e,t){var n=e.exec(t);return!n?null:{offset:t.indexOf(n[0]),length:n[0].length,line:t}}var r=this;if(typeof e!="function")throw"readChunk argument must be function(offset, length, callback)";if(typeof t!="function")throw"decode argument must be function(buffer, callback)";n=n?n:{};var i=n.milestones?n.milestones:[];var s=n.chunkSize?n.chunkSize:1024*4;var o="\n".charCodeAt(0);var u=/\r?\n/;var a=function(e){for(var t=i.length-1;t>=0;t--){if(i[t].lastLine<e)return{firstLine:i[t].lastLine+1,offset:i[t].offset+i[t].length}}return{firstLine:0,offset:0}};var f=function(e,t,n,r){var u=i.length==0||i[i.length-1].offset<t;var a=r-1;var f=0;for(var l=0;l<n;l++){if(e[l]==o){a++;f=l+1}}if(a==r-1){f=n;a=r}else if(n<s&&n>f){a++;f=n}var c={firstLine:r,lastLine:a,offset:t,length:f};if(u)i.push(c);var h=Object.create(c);h.place={firstLine:a+1,offset:t+f};return h};var l=function(e,n,r){t(e.slice(0,n),function(e){var t=e.split(u);if(t.length>0&&t[t.length-1]=="")t=t.slice(0,t.length-1);r(t)})};r.getMilestones=function(){return i};r.readSomeLines=function(t,n){var r=a(t);e(r.offset,s,function i(o,u,a){if(o)return n(o,t);var c=a<s;var h=f(u,r.offset,a,r.firstLine);if(h.firstLine<=t&&t<=h.lastLine){l(u,h.length,function(e){if(t!=h.firstLine)e=e.splice(t-h.firstLine);n(undefined,t,e,c)})}else{if(c)return n("Line "+t+" is out of index, last available: "+h.lastLine,t);r=h.place;e(r.offset,s,i)}})};r.readLines=function(e,t,n){var i=[];r.readSomeLines(e,function s(o,u,a,f){if(o)return n(o,e);i=i.concat(a);if(i.length>=t||f)return n(undefined,e,i.splice(0,t),f);r.readSomeLines(u+a.length,s)})};r.find=function(e,t,n){r.readSomeLines(t,function i(t,s,o,u){if(t)return n(t);for(var a=0;a<o.length;a++){var f=c(e,o[a]);if(f)return n(undefined,s+a,f)}if(u)return n(undefined);r.readSomeLines(s+o.length+1,i)})};r.findAll=function(e,t,n,i){var s=[];r.readSomeLines(t,function...