First pass. Doesn't work yet.

This commit is contained in:
Adam Hathcock
2016-05-20 17:31:35 +01:00
parent b3fe26fc56
commit 40e559e608
9 changed files with 94 additions and 103 deletions

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ TestResults/
packages/*/
project.lock.json
test/TestArchives/Scratch
.vs

View File

@@ -1,6 +1,3 @@
{
"projects": ["src","test"],
"sdk": {
"version": "1.0.0-rc1-final"
}
"projects": ["src","test"]
}

View File

@@ -14,5 +14,6 @@
LongName = (byte) 'L',
SparseFile = (byte) 'S',
VolumeHeader = (byte) 'V',
GlobalExtendedHeader = (byte) 'g',
}
}

View File

@@ -5,7 +5,6 @@ using SharpCompress.Converter;
namespace SharpCompress.Common.Tar.Headers
{
GlobalExtendedHeader = (byte) 'g',
internal class TarHeader
{
internal static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
@@ -25,25 +24,25 @@ namespace SharpCompress.Common.Tar.Headers
{
byte[] buffer = new byte[512];
WriteOctalBytes(511, buffer, 100, 8); // file mode
WriteOctalBytes(0, buffer, 108, 8); // owner ID
WriteOctalBytes(0, buffer, 116, 8); // group ID
WriteOctalBytes(511, buffer, 100, 8); // file mode
WriteOctalBytes(0, buffer, 108, 8); // owner ID
WriteOctalBytes(0, buffer, 116, 8); // group ID
//Encoding.UTF8.GetBytes("magic").CopyTo(buffer, 257);
if (Name.Length > 100)
{
// Set mock filename and filetype to indicate the next block is the actual name of the file
WriteStringBytes("././@LongLink", buffer, 0, 100);
buffer[156] = (byte)EntryType.LongName;
buffer[156] = (byte) EntryType.LongName;
WriteOctalBytes(Name.Length + 1, buffer, 124, 12);
}
else
{
WriteStringBytes(Name, buffer, 0, 100);
WriteOctalBytes(Size, buffer, 124, 12);
var time = (long)(LastModifiedTime.ToUniversalTime() - Epoch).TotalSeconds;
var time = (long) (LastModifiedTime.ToUniversalTime() - Epoch).TotalSeconds;
WriteOctalBytes(time, buffer, 136, 12);
buffer[156] = (byte)EntryType;
buffer[156] = (byte) EntryType;
if (Size >= 0x1FFFFFFFF)
{
@@ -67,13 +66,14 @@ namespace SharpCompress.Common.Tar.Headers
Write(output);
}
}
private void WriteLongFilenameHeader(Stream output)
{
byte[] nameBytes = ArchiveEncoding.Default.GetBytes(Name);
output.Write(nameBytes, 0, nameBytes.Length);
// pad to multiple of 512 bytes, and make sure a terminating null is added
int numPaddingBytes = 512 - (nameBytes.Length % 512);
int numPaddingBytes = 512 - (nameBytes.Length%512);
if (numPaddingBytes == 0)
numPaddingBytes = 512;
output.Write(new byte[numPaddingBytes], 0, numPaddingBytes);
@@ -110,7 +110,8 @@ namespace SharpCompress.Common.Tar.Headers
Magic = ArchiveEncoding.Default.GetString(buffer, 257, 6).TrimNulls();
if (!string.IsNullOrEmpty(Magic) && "ustar".Equals(Magic))
if (!string.IsNullOrEmpty(Magic)
&& "ustar".Equals(Magic))
{
string namePrefix = ArchiveEncoding.Default.GetString(buffer, 345, 157);
namePrefix = namePrefix.TrimNulls();
@@ -119,7 +120,8 @@ namespace SharpCompress.Common.Tar.Headers
Name = namePrefix + "/" + Name;
}
}
if (EntryType != EntryType.LongName && Name.Length == 0)
if (EntryType != EntryType.LongName
&& Name.Length == 0)
{
return false;
}

View File

@@ -9,28 +9,28 @@ namespace SharpCompress.Compressor.LZMA
{
internal class AesDecoderStream : DecoderStream2
{
#region Variables
#region Variables
private Stream mStream;
private ICryptoTransform mDecoder;
private byte[] mBuffer;
private readonly Stream mStream;
private readonly ICryptoTransform mDecoder;
private readonly byte[] mBuffer;
private long mWritten;
private long mLimit;
private readonly long mLimit;
private int mOffset;
private int mEnding;
private int mUnderflow;
private bool isDisposed;
#endregion
#endregion
#region Stream Methods
#region Stream Methods
public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
{
mStream = input;
mLimit = limit;
if (((uint)input.Length & 15) != 0)
if (((uint) input.Length & 15) != 0)
throw new NotSupportedException("AES decoder does not support padding.");
int numCyclesPower;
@@ -73,17 +73,24 @@ namespace SharpCompress.Compressor.LZMA
public override long Position
{
get { return mWritten; }
get
{
return mWritten;
}
}
public override long Length
{
get { return mLimit; }
get
{
return mLimit;
}
}
public override int Read(byte[] buffer, int offset, int count)
{
if (count == 0 || mWritten == mLimit)
if (count == 0
|| mWritten == mLimit)
return 0;
if (mUnderflow > 0)
@@ -106,14 +113,15 @@ namespace SharpCompress.Compressor.LZMA
}
mEnding += read;
} while (mEnding - mOffset < 16);
}
while (mEnding - mOffset < 16);
}
// We shouldn't return more data than we are limited to.
// Currently this is handled by forcing an underflow if
// the stream length is not a multiple of the block size.
if (count > mLimit - mWritten)
count = (int)(mLimit - mWritten);
count = (int) (mLimit - mWritten);
// We cannot transform less than 16 bytes into the target buffer,
// but we also cannot return zero, so we need to handle this.
@@ -131,9 +139,9 @@ namespace SharpCompress.Compressor.LZMA
return processed;
}
#endregion
#endregion
#region Private Methods
#region Private Methods
private void Init(byte[] info, out int numCyclesPower, out byte[] salt, out byte[] iv)
{
@@ -186,7 +194,7 @@ namespace SharpCompress.Compressor.LZMA
}
else
{
#if DOTNET54 || DOTNET51
#if NETSTANDARD13
using (IncrementalHash sha = IncrementalHash.CreateHash(HashAlgorithmName.SHA256))
{
byte[] counter = new byte[8];
@@ -250,7 +258,8 @@ namespace SharpCompress.Compressor.LZMA
return count;
}
#endregion
#endregion
}
}
#endif

View File

@@ -4,17 +4,16 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>fd19ddd8-72b2-4024-8665-0d1f7a2aa998</ProjectGuid>
<RootNamespace>SharpCompress</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@@ -1,87 +1,65 @@
{
"version": "0.11.4",
"version": "0.12.0",
"title": "SharpCompress - Pure C# Decompression/Compression",
"authors": [ "Adam Hathcock" ],
"owners": [ "Adam Hathcock" ],
"tags": [ "rar", "unrar", "zip", "unzip", "bzip2", "gzip", "tar", "7zip" ],
"projectUrl": "https://github.com/adamhathcock/sharpcompress",
"licenseUrl": "https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt",
"description": "SharpCompress is a compression library for .NET/Mono/Silverlight/WP7/WindowsStore that can unrar, decompress 7zip, zip/unzip, tar/untar bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.",
"language": "en-US",
"requireLicenseAcceptance": false,
"packOptions": {
"owners": [ "Adam Hathcock" ],
"tags": [ "rar", "unrar", "zip", "unzip", "bzip2", "gzip", "tar", "7zip" ],
"projectUrl": "https://github.com/adamhathcock/sharpcompress",
"licenseUrl": "https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt",
"description": "SharpCompress is a compression library for .NET/Mono/Silverlight/WP7/WindowsStore that can unrar, decompress 7zip, zip/unzip, tar/untar bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.",
"requireLicenseAcceptance": false
},
"frameworks": {
"net35": {
"compilationOptions": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
}
},
"net40": {
"compilationOptions": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
}
},
"net45": {
"compilationOptions": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true
}
},
".NETPortable,Version=v4.5,Profile=Profile259": {
"compilationOptions": {
"netstandard1.0": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"define": [ "PROFILE259", "NO_FILE", "NO_CRYPTO" ]
},
"frameworkAssemblies": {
"Microsoft.CSharp": "",
"System.Collections": "",
"System.Diagnostics.Debug": "",
"System.Dynamic.Runtime": "",
"System.Globalization": "",
"System.IO": "",
"System.Linq": "",
"System.Reflection": "",
"System.Reflection.Extensions": "",
"System.Runtime": "",
"System.Runtime.Extensions": "",
"System.Core": "",
"System.Threading": "",
"System.Threading.Tasks": "",
"System.Text.Encoding": "4.0.0.0"
}
},
"dotnet5.1": {
"compilationOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"define": [ "DOTNET51", "NO_FILE" ]
"define": [ "NETSTANDARD10", "NO_FILE" ]
},
"dependencies": {
"System.Collections": "4.0.11-beta-23516",
"System.Diagnostics.Debug": "4.0.11-beta-23516",
"System.IO": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime.Extensions": "4.0.11-beta-23516",
"System.Security.Cryptography.Algorithms": "4.0.0-beta-23516",
"System.Text.Encoding.Extensions": "4.0.11-beta-23516"
"System.Collections": "4.0.11-rc2-24027",
"System.Diagnostics.Debug": "4.0.11-rc2-24027",
"System.IO": "4.1.0-rc2-24027",
"System.Linq": "4.1.0-rc2-24027",
"System.Runtime.Extensions": "4.1.0-rc2-24027",
"System.Text.Encoding.Extensions": "4.0.11-rc2-24027"
}
},
"dotnet5.4": {
"compilationOptions": {
"netstandard1.3": {
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"define": [ "DOTNET54" ]
"define": [ "NETSTANDARD13" ]
},
"dependencies": {
"System.Collections": "4.0.11-beta-23516",
"System.Diagnostics.Debug": "4.0.11-beta-23516",
"System.IO": "4.0.11-beta-23516",
"System.IO.FileSystem": "4.0.1-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Security.Cryptography.Algorithms": "4.0.0-beta-23516",
"System.Text.Encoding.Extensions": "4.0.11-beta-23516"
"System.Collections": "4.0.11-rc2-24027",
"System.Diagnostics.Debug": "4.0.11-rc2-24027",
"System.IO": "4.1.0-rc2-24027",
"System.IO.FileSystem": "4.0.1-rc2-24027",
"System.Linq": "4.1.0-rc2-24027",
"System.Runtime.Extensions": "4.1.0-rc2-24027",
"System.Security.Cryptography.Algorithms": "4.1.0-rc2-24027",
"System.Text.Encoding.Extensions": "4.0.11-rc2-24027"
}
}
}

View File

@@ -4,12 +4,13 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>3b80e585-a2f3-4666-8f69-c7ffda0dd7e5</ProjectGuid>
<RootNamespace>SharpCompress.Test</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
@@ -17,5 +18,5 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@@ -3,17 +3,20 @@
"test": "xunit.runner.dnx -parallel none"
},
"frameworks": {
"dnxcore50": {
"netcoreapp1.0": {
"imports": [
"dnxcore50"
]
}
},
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final",
"System.Console": "4.0.0-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"Microsoft.CSharp": "4.0.1-rc2-24027",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-final",
"System.Console": "4.0.0-rc2-24027",
"System.Collections": "4.0.11-rc2-24027",
"System.Linq": "4.1.0-rc2-24027",
"System.Runtime": "4.1.0-rc2-24027",
"System.Threading": "4.0.11-rc2-24027",
"SharpCompress": "0.11.4",
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204"