Git Product home page Git Product logo

argus.io.reversefilereader's People

Contributors

blakepell avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

argus.io.reversefilereader's Issues

Read Twice

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.