Argus.IO.ReverseFileReader 2019.11.22.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Argus.IO.ReverseFileReader --version 2019.11.22.1
NuGet\Install-Package Argus.IO.ReverseFileReader -Version 2019.11.22.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Argus.IO.ReverseFileReader" Version="2019.11.22.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Argus.IO.ReverseFileReader --version 2019.11.22.1
#r "nuget: Argus.IO.ReverseFileReader, 2019.11.22.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Argus.IO.ReverseFileReader as a Cake Addin
#addin nuget:?package=Argus.IO.ReverseFileReader&version=2019.11.22.1

// Install Argus.IO.ReverseFileReader as a Cake Tool
#tool nuget:?package=Argus.IO.ReverseFileReader&version=2019.11.22.1

Reverse File/Stream Reader

NuGet version (ReverseFileReader) NuGet version (ReverseFileReader)

A file/stream reader that is designed to iterate over a file or a stream line by line in reverse order in a way that does not read all of the lines into memory at one time. This supports .NET Standard, the full framework as well as the Windows Universal Platform (UWP) apps.

Although this is geared towards files it will read any Stream line by line in reverse order.

.Net Framework Support

  • .NET Standard 2.1
  • .NET Standard 2.0
  • .NET Framework 4.7.2
  • .NET Framework 4.7.1
  • .NET Framework 4.7
  • .NET Framework 4.6.2
  • .NET Framework 4.6.1
  • .NET Framework 4.6
  • .NET Framework 4.5.2
  • .NET Framework 4.5.1
  • .NET Framework 4.5
  • .NET Framework 4

Read a file with CrLf line endings

C#
var sb = new StringBuilder();

using (var reader = new Argus.IO.ReverseFileReader(@"C:\Temp\log-file.txt"))
{
    while (!reader.StartOfFile)
    {
        sb.AppendLine(reader.ReadLine());
    }
}

Read a file with Lf line endings (Cr also supported with a change to the LineEnding property)

C#
var sb = new StringBuilder();

using (var reader = new Argus.IO.ReverseFileReader(@"C:\Temp\log-file.txt"))
{
    reader.LineEnding = Argus.IO.LineEnding.Lf;

    while (!reader.StartOfFile)
    {
        sb.AppendLine(reader.ReadLine());
    }
}

Windows Universal Platform Example (UWP)

The FileStream is available in UWP but for all intensive purposes is unusable due to the apps being sandboxed. If you instantiate the ReverseFileReader with a file path it will likely end with a permissions exception. Instead, you'll get a StorageFile and then pass its Stream off to the ReverseFileReader which will work.

One thing to note that could cause a related issue is that since Windows 10 build 14393 the TextBox and RichEditBox use only a carriage return (when those save they only save with a carriage return unless you intervene). Pay attention to that if it becomes an issue. In the near future I will provide an auto-detect method that will attempt to infer what line endings the file is using.

C#
/// <summary>
/// Opens a document and puts the contents into a TextBox named TextBoxMain.
/// </summary>
/// <returns></returns>
private async Task OpenDocument()
{
    var picker = new Windows.Storage.Pickers.FileOpenPicker
    {
        SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary
    };

    picker.FileTypeFilter.Add(".txt");
    var OpenStorageFile = await picker.PickSingleFileAsync();

    if (OpenStorageFile != null)
    {
        var sb = new StringBuilder();

        using (var stream = await OpenStorageFile.OpenStreamForReadAsync())
        {
            using (var reader = new Argus.IO.ReverseFileReader(stream))
            {
                reader.LineEnding = Argus.IO.LineEnding.CrLf;

                while (!reader.StartOfFile)
                {
                    sb.AppendLine(reader.ReadLine());
                }

            }
        }

        TextBoxMain.Text = sb.ToString();
        return;
    }
}

Tail

I have provided a console program that is a lightweight tail utility. It reads lines of the end of the provided file. If more lines are requested than the file has the entire file is returned.

Syntax: tail <filename>
        tail <filename> <number of lines to fetch>
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 is compatible.  net452 is compatible.  net46 is compatible.  net461 is compatible.  net462 is compatible.  net463 was computed.  net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.5.1

    • No dependencies.
  • .NETFramework 4.5.2

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.7.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2021.11.9.1 1,094 11/10/2021
2020.11.11.1 762 11/11/2020
2019.11.22.1 549 11/22/2019
2019.4.7.1 605 4/7/2019

- Updated targets to add .NET Standard 2.1