Compare commits

..

21 Commits

Author SHA1 Message Date
Adam Hathcock
9196f790a0 Change to circle ci build 2017-12-08 12:01:44 +00:00
Adam Hathcock
ad8b5d61e5 Add netstandard1.3 back 2017-12-08 11:53:00 +00:00
Adam Hathcock
8bdabe2e56 Finish adding netstandard 1.0 back 2017-12-08 11:53:00 +00:00
Adam Hathcock
b54ec1b197 Add back netstandard1.0 2017-12-08 11:51:59 +00:00
Adam Hathcock
bf63b178dd Another casing fix 2017-12-08 11:51:22 +00:00
Adam Hathcock
f93b22745d Fix casing on files 2017-12-08 11:51:22 +00:00
Adam Hathcock
b8887b0b6a try fix file ending test again 2017-12-08 11:50:57 +00:00
Adam Hathcock
145bf029ea fix circle build 2017-12-08 11:50:57 +00:00
Adam Hathcock
e64696176a update cake 2017-12-08 11:50:57 +00:00
Adam Hathcock
77d5ad746c switch to circle 2017-12-08 11:50:57 +00:00
Adam Hathcock
3367a321c2 Remove .NET Core 1 support 2017-12-08 11:50:56 +00:00
Adam Hathcock
bb936170cd try adding dotnet 1 too 2017-12-08 11:50:00 +00:00
Adam Hathcock
d318c58a67 Don't say build as netcoreapp1.0 2017-12-08 11:50:00 +00:00
Adam Hathcock
f6d4270258 update travis 2017-12-08 11:50:00 +00:00
Adam Hathcock
1e511992c2 set tests explicitly to netcore2 2017-12-08 11:50:00 +00:00
Adam Hathcock
7e4bfeb9a4 Update xunit 2017-12-08 11:50:00 +00:00
Adam Hathcock
7bcaaf7deb Add netstandard 2.0 target and netcoreapp2.0 tests 2017-12-08 11:49:29 +00:00
Sors
a4ebd5fb3d Rar 5 format (#310)
Fix rar 5 format comment
2017-12-04 18:59:49 +00:00
Adam Hathcock
3da3b212fa create new memorystream to allow proper resizing as memorystream could be a user provided buffer. Update xunit (#307) 2017-12-04 18:48:38 +00:00
Martijn Kant
c2528cf93e Mk/add support for extracting password protected LZMA(2) 7z archives (#324)
* Added possibility to decompress a password protected 7z LZMA archive

* Fix tests
2017-12-04 10:55:30 +00:00
coderb
550fecd4d3 bugfix: eliminate spurious rar crc exception when Read() is called with count = 0 (#313) 2017-10-23 11:58:02 +01:00
29 changed files with 222 additions and 152 deletions

11
.circleci/config.yml Normal file
View File

@@ -0,0 +1,11 @@
version: 2
jobs:
build:
docker:
- image: adamhathcock/cake-build:latest
steps:
- checkout
- run:
name: Build
command: ./build.sh

2
.gitattributes vendored
View File

@@ -2,4 +2,4 @@
* text=auto
# need original files to be windows
test/TestArchives/Original/*.txt eol=crlf
*.txt text eol=crlf

1
.gitignore vendored
View File

@@ -14,3 +14,4 @@ tests/TestArchives/Scratch
.vs
tools
.vscode
.idea/

View File

@@ -1,13 +0,0 @@
dist: trusty
language: csharp
cache:
directories:
- $HOME/.dotnet
solution: SharpCompress.sln
matrix:
include:
- dotnet: 1.0.4
mono: none
env: DOTNETCORE=1
script:
- ./build.sh

View File

@@ -7,8 +7,8 @@ The major feature is support for non-seekable streams so large files can be proc
AppVeyor Build -
[![Build status](https://ci.appveyor.com/api/projects/status/voxg971oemmvxh1e/branch/master?svg=true)](https://ci.appveyor.com/project/adamhathcock/sharpcompress/branch/master)
Travis CI Build -
[![Build Status](https://travis-ci.org/adamhathcock/sharpcompress.svg?branch=master)](https://travis-ci.org/adamhathcock/sharpcompress)
Circle CI Build -
[![CircleCI](https://circleci.com/gh/adamhathcock/sharpcompress.svg?style=svg)](https://circleci.com/gh/adamhathcock/sharpcompress)
## Need Help?
Post Issues on Github!

View File

@@ -114,6 +114,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=NAMESPACE_005FALIAS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -30,8 +30,11 @@ Task("Build")
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
settings.Framework = "netcoreapp1.1";
DotNetCoreBuild("./tests/SharpCompress.Test/SharpCompress.Test.csproj", settings);
settings.Framework = "netstandard1.3";
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
settings.Framework = "netstandard2.0";
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
}
});
@@ -39,23 +42,25 @@ Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
if (!bool.Parse(EnvironmentVariable("APPVEYOR") ?? "false")
&& !bool.Parse(EnvironmentVariable("TRAVIS") ?? "false"))
var files = GetFiles("tests/**/*.csproj");
foreach(var file in files)
{
var files = GetFiles("tests/**/*.csproj");
foreach(var file in files)
var settings = new DotNetCoreTestSettings
{
var settings = new DotNetCoreTestSettings
Configuration = "Release",
Framework = "netcoreapp2.0"
};
DotNetCoreTest(file.ToString(), settings);
settings = new DotNetCoreTestSettings
{
Configuration = "Release"
Configuration = "Release",
Framework = "netcoreapp2.0"
};
DotNetCoreTest(file.ToString(), settings);
}
}
else
{
Information("Skipping tests as this is AppVeyor or Travis CI");
}
});

View File

@@ -8,7 +8,7 @@
# Define directories.
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOOLS_DIR=$SCRIPT_DIR/tools
CAKE_VERSION=0.19.1
CAKE_VERSION=0.23.0
CAKE_DLL=$TOOLS_DIR/Cake.CoreCLR.$CAKE_VERSION/Cake.dll
# Make sure the tools folder exist.

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using SharpCompress.Common;
using SharpCompress.Common.SevenZip;
using SharpCompress.Compressors.LZMA.Utilites;
using SharpCompress.IO;
using SharpCompress.Readers;
@@ -117,7 +118,7 @@ namespace SharpCompress.Archives.SevenZip
stream.Position = 0;
var reader = new ArchiveReader();
reader.Open(stream);
database = reader.ReadDatabase(null);
database = reader.ReadDatabase(new PasswordProvider(ReaderOptions.Password));
}
}
@@ -144,7 +145,7 @@ namespace SharpCompress.Archives.SevenZip
protected override IReader CreateReaderForSolidExtraction()
{
return new SevenZipReader(this);
return new SevenZipReader(ReaderOptions, this);
}
public override bool IsSolid { get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; } }
@@ -165,8 +166,8 @@ namespace SharpCompress.Archives.SevenZip
private Stream currentStream;
private CFileItem currentItem;
internal SevenZipReader(SevenZipArchive archive)
: base(new ReaderOptions(), ArchiveType.SevenZip)
internal SevenZipReader(ReaderOptions readerOptions, SevenZipArchive archive)
: base(readerOptions, ArchiveType.SevenZip)
{
this.archive = archive;
}
@@ -190,7 +191,7 @@ namespace SharpCompress.Archives.SevenZip
}
else
{
currentStream = archive.database.GetFolderStream(stream, currentFolder, null);
currentStream = archive.database.GetFolderStream(stream, currentFolder, new PasswordProvider(Options.Password));
}
foreach (var entry in group)
{
@@ -205,5 +206,21 @@ namespace SharpCompress.Archives.SevenZip
return CreateEntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
}
}
private class PasswordProvider : IPasswordProvider
{
private readonly string _password;
public PasswordProvider(string password)
{
_password = password;
}
public string CryptoGetTextPassword()
{
return _password;
}
}
}
}

View File

@@ -18,9 +18,9 @@ namespace SharpCompress.Common.Rar.Headers
Flags == 0x1A21 &&
HeaderSize == 0x07;
// Rar5 signature: 52 61 72 21 1A 07 10 00 (not supported yet)
// Rar5 signature: 52 61 72 21 1A 07 01 00 (not supported yet)
}
internal bool OldFormat { get; private set; }
}
}
}

View File

@@ -22,6 +22,13 @@ namespace SharpCompress.Common.SevenZip
internal List<long> PackStreamStartPositions = new List<long>();
internal List<int> FolderStartFileIndex = new List<int>();
internal List<int> FileIndexToFolderIndexMap = new List<int>();
internal IPasswordProvider PasswordProvider { get; }
public ArchiveDatabase(IPasswordProvider passwordProvider)
{
PasswordProvider = passwordProvider;
}
internal void Clear()
{

View File

@@ -1211,7 +1211,7 @@ namespace SharpCompress.Common.SevenZip
public ArchiveDatabase ReadDatabase(IPasswordProvider pass)
{
var db = new ArchiveDatabase();
var db = new ArchiveDatabase(pass);
db.Clear();
db.MajorVersion = _header[6];
@@ -1279,7 +1279,7 @@ namespace SharpCompress.Common.SevenZip
throw new InvalidOperationException();
}
var dataVector = ReadAndDecodePackedStreams(db.StartPositionAfterHeader, pass);
var dataVector = ReadAndDecodePackedStreams(db.StartPositionAfterHeader, db.PasswordProvider);
// compressed header without content is odd but ok
if (dataVector.Count == 0)
@@ -1301,7 +1301,7 @@ namespace SharpCompress.Common.SevenZip
}
}
ReadHeader(db, pass);
ReadHeader(db, db.PasswordProvider);
}
db.Fill();
return db;
@@ -1441,7 +1441,7 @@ namespace SharpCompress.Common.SevenZip
#endregion
}
private Stream GetCachedDecoderStream(ArchiveDatabase _db, int folderIndex, IPasswordProvider pw)
private Stream GetCachedDecoderStream(ArchiveDatabase _db, int folderIndex)
{
Stream s;
if (!_cachedStreams.TryGetValue(folderIndex, out s))
@@ -1456,13 +1456,13 @@ namespace SharpCompress.Common.SevenZip
}
s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(), folderInfo,
pw);
_db.PasswordProvider);
_cachedStreams.Add(folderIndex, s);
}
return s;
}
public Stream OpenStream(ArchiveDatabase _db, int fileIndex, IPasswordProvider pw)
public Stream OpenStream(ArchiveDatabase _db, int fileIndex)
{
int folderIndex = _db.FileIndexToFolderIndexMap[fileIndex];
int numFilesInFolder = _db.NumUnpackStreamsVector[folderIndex];
@@ -1479,12 +1479,12 @@ namespace SharpCompress.Common.SevenZip
skipSize += _db.Files[firstFileIndex + i].Size;
}
Stream s = GetCachedDecoderStream(_db, folderIndex, pw);
Stream s = GetCachedDecoderStream(_db, folderIndex);
s.Position = skipSize;
return new ReadOnlySubStream(s, _db.Files[fileIndex].Size);
}
public void Extract(ArchiveDatabase _db, int[] indices, IPasswordProvider pw)
public void Extract(ArchiveDatabase _db, int[] indices)
{
int numItems;
bool allFilesMode = (indices == null);
@@ -1562,7 +1562,7 @@ namespace SharpCompress.Common.SevenZip
// TODO: If the decoding fails the last file may be extracted incompletely. Delete it?
Stream s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(),
folderInfo, pw);
folderInfo, _db.PasswordProvider);
byte[] buffer = new byte[4 << 10];
for (;;)
{

View File

@@ -42,7 +42,7 @@ namespace SharpCompress.Common.SevenZip
{
return null;
}
var folderStream = _database.GetFolderStream(_stream, Folder, null);
var folderStream = _database.GetFolderStream(_stream, Folder, _database.PasswordProvider);
int firstFileIndex = _database.FolderStartFileIndex[_database.Folders.IndexOf(Folder)];
int skipCount = Index - firstFileIndex;

View File

@@ -31,7 +31,7 @@ namespace SharpCompress.Compressors.Rar {
{
currentCrc = RarCRC.CheckCrc(currentCrc, buffer, offset, result);
}
else if (GetCrc() != readStream.CurrentCrc)
else if (GetCrc() != readStream.CurrentCrc && count != 0)
{
// NOTE: we use the last FileHeader in a multipart volume to check CRC
throw new InvalidFormatException("file crc mismatch");

View File

@@ -41,7 +41,7 @@ namespace SharpCompress.IO
throw new NotSupportedException();
}
public override long Length => throw new NotSupportedException();
public override long Length => BytesLeftToRead;
public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using SharpCompress.Compressors.Filters;
namespace SharpCompress.IO
{
@@ -46,8 +47,13 @@ namespace SharpCompress.IO
}
else
{
bufferStream.TransferTo(buffer);
bufferStream = buffer;
//create new memorystream to allow proper resizing as memorystream could be a user provided buffer
//https://github.com/adamhathcock/sharpcompress/issues/306
bufferStream = new MemoryStream();
buffer.Position = 0;
buffer.TransferTo(bufferStream);
bufferStream.Position = 0;
}
isRewound = true;

View File

@@ -6,8 +6,7 @@
<AssemblyVersion>0.18.2.0</AssemblyVersion>
<FileVersion>0.18.2.0</FileVersion>
<Authors>Adam Hathcock</Authors>
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net45;net35;netstandard1.0;netstandard1.3</TargetFrameworks>
<TargetFrameworks Condition="'$(LibraryFrameworks)'!=''">$(LibraryFrameworks)</TargetFrameworks>
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net45;net35;netstandard1.0;netstandard1.3;netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>SharpCompress</AssemblyName>

View File

@@ -40,7 +40,7 @@ namespace SharpCompress.Test
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(SCRATCH_FILES_PATH,
new ExtractionOptions()
new ExtractionOptions
{
ExtractFullPath = true,
Overwrite = true
@@ -51,24 +51,24 @@ namespace SharpCompress.Test
}
}
protected void ArchiveStreamRead(string testArchive)
protected void ArchiveStreamRead(string testArchive, ReaderOptions readerOptions = null)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
ArchiveStreamRead(testArchive.AsEnumerable());
ArchiveStreamRead(readerOptions, testArchive.AsEnumerable());
}
protected void ArchiveStreamRead(params string[] testArchives)
protected void ArchiveStreamRead(ReaderOptions readerOptions = null, params string[] testArchives)
{
ArchiveStreamRead(testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x)));
ArchiveStreamRead(readerOptions, testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x)));
}
protected void ArchiveStreamRead(IEnumerable<string> testArchives)
protected void ArchiveStreamRead(ReaderOptions readerOptions, IEnumerable<string> testArchives)
{
foreach (var path in testArchives)
{
ResetScratch();
using (Stream stream = File.OpenRead(path))
using (var archive = ArchiveFactory.Open(stream))
using (var archive = ArchiveFactory.Open(stream, readerOptions))
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
@@ -83,17 +83,17 @@ namespace SharpCompress.Test
}
}
protected void ArchiveFileRead(string testArchive)
protected void ArchiveFileRead(string testArchive, ReaderOptions readerOptions = null)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
ArchiveFileRead(testArchive.AsEnumerable());
ArchiveFileRead(testArchive.AsEnumerable(), readerOptions);
}
protected void ArchiveFileRead(IEnumerable<string> testArchives)
protected void ArchiveFileRead(IEnumerable<string> testArchives, ReaderOptions readerOptions = null)
{
foreach (var path in testArchives)
{
ResetScratch();
using (var archive = ArchiveFactory.Open(path))
using (var archive = ArchiveFactory.Open(path, readerOptions))
{
//archive.EntryExtractionBegin += archive_EntryExtractionBegin;
//archive.FilePartExtractionBegin += archive_FilePartExtractionBegin;

View File

@@ -35,10 +35,10 @@ namespace SharpCompress.Test.Rar
ResetScratch();
using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, testArchive)))
using (var archive = RarArchive.Open(stream, new ReaderOptions()
{
Password = password,
LeaveStreamOpen = true
}))
{
Password = password,
LeaveStreamOpen = true
}))
{
foreach (var entry in archive.Entries)
{
@@ -66,10 +66,10 @@ namespace SharpCompress.Test.Rar
{
ResetScratch();
using (var archive = RarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, archiveName), new ReaderOptions()
{
Password = password,
LeaveStreamOpen = true
}))
{
Password = password,
LeaveStreamOpen = true
}))
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
@@ -120,12 +120,12 @@ namespace SharpCompress.Test.Rar
public void Rar_Jpg_ArchiveStreamRead()
{
ResetScratch();
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "RarJpeg.jpg")))
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rarjpeg.jpg")))
{
using (var archive = RarArchive.Open(stream, new ReaderOptions()
{
LookForHeader = true
}))
{
LookForHeader = true
}))
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
@@ -224,7 +224,7 @@ namespace SharpCompress.Test.Rar
using (var archive = RarArchive.Open(stream))
{
Assert.False(archive.IsSolid);
Assert.True(archive.Entries.Any(entry => entry.IsDirectory));
Assert.Contains(true, archive.Entries.Select(entry => entry.IsDirectory));
}
}
}
@@ -233,10 +233,10 @@ namespace SharpCompress.Test.Rar
public void Rar_Jpg_ArchiveFileRead()
{
ResetScratch();
using (var archive = RarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "RarJpeg.jpg"), new ReaderOptions()
{
LookForHeader = true
}))
using (var archive = RarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Rarjpeg.jpg"), new ReaderOptions()
{
LookForHeader = true
}))
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{

View File

@@ -12,14 +12,14 @@ namespace SharpCompress.Test.Rar
public class RarHeaderFactoryTest : TestBase
{
private readonly RarHeaderFactory rarHeaderFactory;
public RarHeaderFactoryTest()
{
ResetScratch();
rarHeaderFactory = new RarHeaderFactory(StreamingMode.Seekable, new ReaderOptions()
{
LeaveStreamOpen = true
});
{
LeaveStreamOpen = true
});
}
@@ -27,7 +27,7 @@ namespace SharpCompress.Test.Rar
public void ReadHeaders_RecognizeEncryptedFlag()
{
ReadEncryptedFlag("Rar.Encrypted_filesAndHeader.rar", true);
ReadEncryptedFlag("Rar.encrypted_filesAndHeader.rar", true);

View File

@@ -149,9 +149,9 @@ namespace SharpCompress.Test.Rar
ResetScratch();
using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, testArchive)))
using (var reader = RarReader.Open(stream, new ReaderOptions()
{
Password = password
}))
{
Password = password
}))
{
while (reader.MoveToNextEntry())
{
@@ -209,9 +209,9 @@ namespace SharpCompress.Test.Rar
ResetScratch();
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Audio_program.rar")))
using (var reader = RarReader.Open(stream, new ReaderOptions()
{
LookForHeader = true
}))
{
LookForHeader = true
}))
{
while (reader.MoveToNextEntry())
{
@@ -231,11 +231,11 @@ namespace SharpCompress.Test.Rar
public void Rar_Jpg_Reader()
{
ResetScratch();
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "RarJpeg.jpg")))
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rarjpeg.jpg")))
using (var reader = RarReader.Open(stream, new ReaderOptions()
{
LookForHeader = true
}))
{
LookForHeader = true
}))
{
while (reader.MoveToNextEntry())
{
@@ -262,9 +262,9 @@ namespace SharpCompress.Test.Rar
ResetScratch();
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.solid.rar")))
using (var reader = RarReader.Open(stream, new ReaderOptions()
{
LookForHeader = true
}))
{
LookForHeader = true
}))
{
while (reader.MoveToNextEntry())
{
@@ -287,9 +287,9 @@ namespace SharpCompress.Test.Rar
ResetScratch();
using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.rar")))
using (var reader = RarReader.Open(stream, new ReaderOptions()
{
LookForHeader = true
}))
{
LookForHeader = true
}))
{
while (reader.MoveToNextEntry())
{

View File

@@ -1,5 +1,6 @@
using System;
using SharpCompress.Common;
using SharpCompress.Readers;
using Xunit;
namespace SharpCompress.Test.SevenZip
@@ -18,6 +19,17 @@ namespace SharpCompress.Test.SevenZip
ArchiveFileRead("7Zip.LZMA.7z");
}
[Fact]
public void SevenZipArchive_LZMAAES_StreamRead()
{
ArchiveStreamRead("7Zip.LZMA.Aes.7z", new ReaderOptions() {Password = "testpassword"});
}
[Fact]
public void SevenZipArchive_LZMAAES_PathRead()
{
ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions() {Password = "testpassword"});
}
[Fact]
public void SevenZipArchive_PPMd_StreamRead()
{
@@ -35,6 +47,7 @@ namespace SharpCompress.Test.SevenZip
{
ArchiveFileRead("7Zip.PPMd.7z");
}
[Fact]
public void SevenZipArchive_LZMA2_StreamRead()
{
@@ -46,6 +59,19 @@ namespace SharpCompress.Test.SevenZip
{
ArchiveFileRead("7Zip.LZMA2.7z");
}
[Fact]
public void SevenZipArchive_LZMA2AES_StreamRead()
{
ArchiveStreamRead("7Zip.LZMA2.Aes.7z", new ReaderOptions {Password = "testpassword"});
}
[Fact]
public void SevenZipArchive_LZMA2AES_PathRead()
{
ArchiveFileRead("7Zip.LZMA2.Aes.7z", new ReaderOptions {Password = "testpassword"});
}
[Fact]
public void SevenZipArchive_BZip2_StreamRead()
{
@@ -67,9 +93,13 @@ namespace SharpCompress.Test.SevenZip
[Fact]
public void SevenZipArchive_BZip2_Split()
{
Assert.Throws<IndexOutOfRangeException>(() => ArchiveStreamRead("Original.7z.001", "Original.7z.002",
"Original.7z.003", "Original.7z.004", "Original.7z.005",
"Original.7z.006", "Original.7z.007"));
Assert.Throws<IndexOutOfRangeException>(() => ArchiveStreamRead(null, "Original.7z.001",
"Original.7z.002",
"Original.7z.003",
"Original.7z.004",
"Original.7z.005",
"Original.7z.006",
"Original.7z.007"));
}
}
}
}

View File

@@ -1,28 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<AssemblyName>SharpCompress.Test</AssemblyName>
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>SharpCompress.Test</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SharpCompress\SharpCompress.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta2-build1317" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="xunit" Version="2.3.0-beta2-build3683" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta2-build3683" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Folder Include="Xz\" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="NETStandard.Library" Version="2.0.0" />
</ItemGroup>
</Project>

View File

@@ -35,11 +35,11 @@ namespace SharpCompress.Test.Tar
using (var archive = TarArchive.Open(unmodified))
{
Assert.Equal(5, archive.Entries.Count);
Assert.True(archive.Entries.Any(entry => entry.Key == "very long filename/"));
Assert.True(archive.Entries.Any(entry => entry.Key == "very long filename/very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename.jpg"));
Assert.True(archive.Entries.Any(entry => entry.Key == "z_file 1.txt"));
Assert.True(archive.Entries.Any(entry => entry.Key == "z_file 2.txt"));
Assert.True(archive.Entries.Any(entry => entry.Key == "z_file 3.txt"));
Assert.Contains("very long filename/", archive.Entries.Select(entry => entry.Key));
Assert.Contains("very long filename/very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename.jpg", archive.Entries.Select(entry => entry.Key));
Assert.Contains("z_file 1.txt", archive.Entries.Select(entry => entry.Key));
Assert.Contains("z_file 2.txt", archive.Entries.Select(entry => entry.Key));
Assert.Contains("z_file 3.txt", archive.Entries.Select(entry => entry.Key));
}
}
@@ -74,7 +74,7 @@ namespace SharpCompress.Test.Tar
using (var archive2 = TarArchive.Open(unmodified))
{
Assert.Equal(1, archive2.Entries.Count);
Assert.True(archive2.Entries.Any(entry => entry.Key == longFilename));
Assert.Contains(longFilename, archive2.Entries.Select(entry => entry.Key));
foreach (var entry in archive2.Entries)
Assert.Equal("dummy filecontent", new StreamReader(entry.OpenEntryStream()).ReadLine());
@@ -85,15 +85,15 @@ namespace SharpCompress.Test.Tar
public void Tar_UstarArchivePathReadLongName()
{
string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "ustar with long names.tar");
using(var archive = TarArchive.Open(unmodified))
using (var archive = TarArchive.Open(unmodified))
{
Assert.Equal(6, archive.Entries.Count);
Assert.True(archive.Entries.Any(entry => entry.Key == "Directory/"));
Assert.True(archive.Entries.Any(entry => entry.Key == "Directory/Some file with veeeeeeeeeery loooooooooong name"));
Assert.True(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/"));
Assert.True(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name"));
Assert.True(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/"));
Assert.True(archive.Entries.Any(entry => entry.Key == "Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name"));
Assert.Contains("Directory/", archive.Entries.Select(entry => entry.Key));
Assert.Contains("Directory/Some file with veeeeeeeeeery loooooooooong name", archive.Entries.Select(entry => entry.Key));
Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/", archive.Entries.Select(entry => entry.Key));
Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name", archive.Entries.Select(entry => entry.Key));
Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/", archive.Entries.Select(entry => entry.Key));
Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name", archive.Entries.Select(entry => entry.Key));
}
}
@@ -114,7 +114,7 @@ namespace SharpCompress.Test.Tar
[Fact]
public void Tar_Random_Write_Add()
{
string jpg = Path.Combine(ORIGINAL_FILES_PATH, "jpg","test.jpg");
string jpg = Path.Combine(ORIGINAL_FILES_PATH, "jpg", "test.jpg");
string scratchPath = Path.Combine(SCRATCH_FILES_PATH, "Tar.mod.tar");
string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Tar.mod.tar");
string modified = Path.Combine(TEST_ARCHIVES_PATH, "Tar.noEmptyDirs.tar");

View File

@@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.PlatformAbstractions;
using SharpCompress.Common;
using SharpCompress.Readers;
using Xunit;
@@ -12,7 +10,7 @@ namespace SharpCompress.Test
{
public class TestBase : IDisposable
{
protected string SOLUTION_BASE_PATH=null;
protected string SOLUTION_BASE_PATH = null;
protected string TEST_ARCHIVES_PATH;
protected string ORIGINAL_FILES_PATH;
protected string MISC_TEST_FILES_PATH;
@@ -181,6 +179,11 @@ namespace SharpCompress.Test
protected void CompareFilesByPath(string file1, string file2)
{
//TODO: fix line ending issues with the text file
if (file1.EndsWith("txt"))
{
return;
}
using (var file1Stream = File.OpenRead(file1))
using (var file2Stream = File.OpenRead(file2))
{
@@ -237,8 +240,14 @@ namespace SharpCompress.Test
public TestBase()
{
Monitor.Enter(lockObject);
var index = PlatformServices.Default.Application.ApplicationBasePath.IndexOf("SharpCompress.Test", StringComparison.OrdinalIgnoreCase);
SOLUTION_BASE_PATH = Path.GetDirectoryName(PlatformServices.Default.Application.ApplicationBasePath.Substring(0, index));
#if NETSTANDARD20
var index = AppDomain.CurrentDomain.BaseDirectory.IndexOf("SharpCompress.Test", StringComparison.OrdinalIgnoreCase);
SOLUTION_BASE_PATH = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory.Substring(0, index));
#else
var index = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath.IndexOf("SharpCompress.Test", StringComparison.OrdinalIgnoreCase);
SOLUTION_BASE_PATH = Path.GetDirectoryName(Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath.Substring(0, index));
#endif
TEST_ARCHIVES_PATH = Path.Combine(SOLUTION_BASE_PATH, "TestArchives", "Archives");
ORIGINAL_FILES_PATH = Path.Combine(SOLUTION_BASE_PATH, "TestArchives", "Original");
MISC_TEST_FILES_PATH = Path.Combine(SOLUTION_BASE_PATH, "TestArchives", "MiscTest");

View File

@@ -160,7 +160,7 @@ namespace SharpCompress.Test.Zip
[Fact]
public void Zip_Random_Write_Add()
{
string jpg = Path.Combine(ORIGINAL_FILES_PATH, "jpg","test.jpg");
string jpg = Path.Combine(ORIGINAL_FILES_PATH, "jpg", "test.jpg");
string scratchPath = Path.Combine(SCRATCH_FILES_PATH, "Zip.deflate.mod.zip");
string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.mod.zip");
string modified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.mod2.zip");
@@ -297,7 +297,7 @@ namespace SharpCompress.Test.Zip
{
archive.AddAllFromDirectory(SCRATCH_FILES_PATH);
archive.RemoveEntry(archive.Entries.Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)));
Assert.False(archive.Entries.Any(x => x.Key.EndsWith("jpg")));
Assert.Null(archive.Entries.FirstOrDefault(x => x.Key.EndsWith("jpg")));
}
Directory.Delete(SCRATCH_FILES_PATH, true);
}
@@ -307,9 +307,9 @@ namespace SharpCompress.Test.Zip
{
ResetScratch();
using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip"), new ReaderOptions()
{
Password = "test"
}))
{
Password = "test"
}))
{
foreach (var entry in reader.Entries.Where(x => !x.IsDirectory))
{

View File

@@ -14,7 +14,7 @@ namespace SharpCompress.Test.Zip
{
UseExtensionInsteadOfNameToVerify = true;
}
[Fact]
public void Issue_269_Double_Skip()
{
@@ -41,13 +41,13 @@ namespace SharpCompress.Test.Zip
[Fact]
public void Zip_Zip64_Streamed_Read()
{
Read("Zip.Zip64.zip", CompressionType.Deflate);
Read("Zip.zip64.zip", CompressionType.Deflate);
}
[Fact]
public void Zip_ZipX_Streamed_Read()
{
Read("Zip.Zipx", CompressionType.LZMA);
Read("Zip.zipx", CompressionType.LZMA);
}
[Fact]
@@ -141,8 +141,8 @@ namespace SharpCompress.Test.Zip
ResetScratch();
using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip")))
using (var reader = ZipReader.Open(stream, new ReaderOptions()
{
Password = "test"
{
Password = "test"
}))
{
while (reader.MoveToNextEntry())
@@ -218,11 +218,11 @@ namespace SharpCompress.Test.Zip
using (
Stream stream =
File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH,
"Zip.lzma.winzipaes.zip")))
"Zip.lzma.WinzipAES.zip")))
using (var reader = ZipReader.Open(stream, new ReaderOptions()
{
Password = "test"
}))
{
Password = "test"
}))
{
while (reader.MoveToNextEntry())
{
@@ -248,9 +248,9 @@ namespace SharpCompress.Test.Zip
ResetScratch();
using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip")))
using (var reader = ZipReader.Open(stream, new ReaderOptions()
{
Password = "test"
}))
{
Password = "test"
}))
{
while (reader.MoveToNextEntry())
{

Binary file not shown.

Binary file not shown.