blakepell / argus.io.reversefilereader Goto Github PK
View Code? Open in Web Editor NEWA file/stream reader that is designed to iterate over a file or a stream line by line in reverse order
License: MIT License
A file/stream reader that is designed to iterate over a file or a stream line by line in reverse order
License: MIT License
I am looking for some methods help me to read log files from tail to head.
your project is great!
but int this code https://github.com/blakepell/Argus.IO.ReverseFileReader/blob/master/src/Argus.IO.ReverseFileReader/IO/ReverseFileReader.cs
byte[] buf = new byte[1];
long position = _stream.Position;
while (_stream.Position > 0)
{
buf.Initialize();
_stream.Seek(-1, SeekOrigin.Current);
// Read one char
_stream.Read(buf, 0, 1);
// Move it back
_stream.Seek(-1, SeekOrigin.Current);
if (buf[0] == 10)
{
// Move it back again.
_stream.Seek(-1, SeekOrigin.Current);
_stream.Read(buf, 0, 1);
if (buf[0] == 13)
{
break;
}
}
}
int count = (int)(position - _stream.Position);
byte[] line = new byte[count];
_stream.Read(line, 0, count);
_stream.Seek(-count, SeekOrigin.Current);
return this.Encoding.GetString(line).Trim(new[] { '\r', '\n' });
Read same char twice, you can improve it.
By the way, _stream.Read(buf, 0, 1);
is slow.
_stream.Read(buf, 0, bufferSize); char ch = buf[wantedPosition - bufferStartPosition];
may be better
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.