Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Src/AdvancedLogViewer.Common/Parser/LogParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Text.RegularExpressions;
using AdvancedLogViewer.Common.Parser.LogPartsFileNameStrategies;
using System.IO.Compression;

namespace AdvancedLogViewer.Common.Parser
{
Expand Down Expand Up @@ -95,15 +96,28 @@ public void LoadLogEntries()
this.LogFileExists = true;
using (FileStream fs = File.Open(this.LogFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (TextReader sr = new StreamReader(fs, true))
var isGzip = false;
if (LogFileName.Contains(".gz"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use EndsWith instead of Contains? I assume that we are interested only in files ending by .gz.
And I would also add StringComparer.OrdinalIgnoreCase option.

{
// Check for GZip file mark
var firstByte = fs.ReadByte();
var secondByte = fs.ReadByte();
isGzip = firstByte == 0x1f && secondByte == 0x8b;
// Rewind the stream
fs.Seek(0, SeekOrigin.Begin);
}

Stream stream = isGzip ? new GZipStream(fs, CompressionMode.Decompress) : fs; // Not necessary to employ using block on GZipStream, StreamReader closes it

using (TextReader sr = new StreamReader(stream, true))
{
LogEntry tmpLogEntry = new LogEntry();
LogEntry currentLogEntry = null;
LogEntry logEntryFromPrevLoad = null;

StringBuilder messageBuilder = new StringBuilder(524288); //0.5 MB

long fileSize = fs.Length;
long fileSize = fs.Length; // Can't use stream here as GZipStream does not support Length
int readFromLine = 1;
DateTime nextProgressReportTime = DateTime.Now.AddMilliseconds(50);
int nextProgressReportLine = 200;
Expand Down
16 changes: 15 additions & 1 deletion Src/AdvancedLogViewer/UI/ViewLogAsText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Compression;

namespace AdvancedLogViewer.UI
{
Expand All @@ -22,7 +23,20 @@ public void LoadFile(string fileName, int numberOfRowsToShow)
this.Text = fileName;
using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (TextReader sr = new StreamReader(fs))
var isGzip = false;
if (fileName.Contains(".gz"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same comment as above. Otherwise no comments, thanks for the PR! :)

{
// Check for GZip file mark
var firstByte = fs.ReadByte();
var secondByte = fs.ReadByte();
isGzip = firstByte == 0x1f && secondByte == 0x8b;
// Rewind the stream
fs.Seek(0, SeekOrigin.Begin);
}

Stream stream = isGzip ? new GZipStream(fs, CompressionMode.Decompress) : fs; // Not necessary to employ using block on GZipStream, StreamReader closes it

using (TextReader sr = new StreamReader(stream))
{
string line;
int lineNumber = 0;
Expand Down