Fixed problem with TarHeader...

This commit is contained in:
niksedk 2014-10-04 18:14:57 +02:00
parent 9ce90aef2e
commit c9cba9d373

View File

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Text;
namespace Nikse.SubtitleEdit.Logic
@ -7,42 +8,33 @@ namespace Nikse.SubtitleEdit.Logic
{
public const int HeaderSize = 512;
public string FileName { get; set; }
public long FileSizeInBytes { get; set; }
public long FilePosition { get; set; }
private readonly Stream _stream;
private readonly long _fileSizeInBytes;
public TarHeader(Stream stream)
{
_stream = stream;
byte[] buffer = new byte[HeaderSize];
var buffer = new byte[HeaderSize];
stream.Read(buffer, 0, HeaderSize);
FilePosition = stream.Position;
FileName = Encoding.ASCII.GetString(buffer, 0, 100).Replace("\0", string.Empty);
if (!string.IsNullOrEmpty(FileName))
{
var sizeInBytes = Encoding.ASCII.GetString(buffer, 124, 11);
long.TryParse(sizeInBytes, out _fileSizeInBytes);
}
}
public string FileName { get; set; }
public long FilePosition { get; set; }
public long FileSizeInBytes
{
get
{
return _fileSizeInBytes;
}
string sizeInBytes = Encoding.ASCII.GetString(buffer, 124, 11);
if (!string.IsNullOrEmpty(FileName) && Utilities.IsInteger(sizeInBytes))
FileSizeInBytes = Convert.ToInt64(sizeInBytes, 8);
}
public void WriteData(string fileName)
{
var buffer = new byte[_fileSizeInBytes];
var buffer = new byte[FileSizeInBytes];
_stream.Position = FilePosition;
_stream.Read(buffer, 0, buffer.Length);
File.WriteAllBytes(fileName, buffer);
}
}
}