diff --git a/.gitignore b/.gitignore index 1b119084..71becff1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ TestResults/ *.nupkg packages/*/ project.lock.json -test/TestArchives/Scratch +tests/TestArchives/Scratch .vs tools .vscode diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..44d18bef --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +dist: trusty +language: csharp +solution: SharpCompress.sln +matrix: + include: + - dotnet: 1.0.4 + mono: none + env: DOTNETCORE=1 +script: + - ./build.sh \ No newline at end of file diff --git a/README.md b/README.md index a8ad5858..9ff8f13e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ # SharpCompress -SharpCompress is a compression library for .NET/Mono/Silverlight/WP7 that can unrar, un7zip, unzip, untar unbzip2 and ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip are implemented. +SharpCompress is a compression library in pure C# for .NET 3.5, 4.5, .NET Standard 1.0, 1.3 that can unrar, un7zip, unzip, untar unbzip2 and ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip are implemented. The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream). +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) + ## Need Help? Post Issues on Github! @@ -27,10 +31,23 @@ I'm always looking for help or ideas. Please submit code or email with ideas. Un * 7Zip writing * Zip64 (Need writing and extend Reading) * Multi-volume Zip support. -* RAR5 support ## Version Log +### Version 0.16.1 + +* Fix [Preserve compression method when getting a compressed stream](https://github.com/adamhathcock/sharpcompress/pull/235) +* Fix [RAR entry key normalization fix](https://github.com/adamhathcock/sharpcompress/issues/201) + +### Version 0.16.0 + +* Breaking - [Progress Event Tracking rethink](https://github.com/adamhathcock/sharpcompress/pull/226) +* Update to VS2017 - [VS2017](https://github.com/adamhathcock/sharpcompress/pull/231) - Framework targets have been changed. +* New - [Add Zip64 writing](https://github.com/adamhathcock/sharpcompress/pull/211) +* [Fix invalid/mismatching Zip version flags.](https://github.com/adamhathcock/sharpcompress/issues/164) - This allows nuget/System.IO.Packaging to read zip files generated by SharpCompress +* [Fix 7Zip directory hiding](https://github.com/adamhathcock/sharpcompress/pull/215/files) +* [Verify RAR CRC headers](https://github.com/adamhathcock/sharpcompress/pull/220) + ### Version 0.15.2 * [Fix invalid headers](https://github.com/adamhathcock/sharpcompress/pull/210) - fixes an issue creating large-ish zip archives that was introduced with zip64 reading. diff --git a/SharpCompress.sln b/SharpCompress.sln index e82ccc1a..d6f16c37 100644 --- a/SharpCompress.sln +++ b/SharpCompress.sln @@ -1,23 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F18F1765-4A02-42FD-9BEF-F0E2FCBD9D17}" - ProjectSection(SolutionItems) = preProject - global.json = global.json - EndProjectSection -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SharpCompress", "src\SharpCompress\SharpCompress.xproj", "{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C5BE746-03E5-4895-9988-0B57F162F86C}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{0F0901FF-E8D9-426A-B5A2-17C7F47C1529}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0F0901FF-E8D9-426A-B5A2-17C7F47C1529}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SharpCompress.Test", "test\SharpCompress.Test\SharpCompress.Test.xproj", "{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}" - ProjectSection(ProjectDependencies) = postProject - {FD19DDD8-72B2-4024-8665-0D1F7A2AA998} = {FD19DDD8-72B2-4024-8665-0D1F7A2AA998} - EndProjectSection +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpCompress", "src\SharpCompress\SharpCompress.csproj", "{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpCompress.Test", "tests\SharpCompress.Test\SharpCompress.Test.csproj", "{F2B1A1EB-0FA6-40D0-8908-E13247C7226F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,16 +23,16 @@ Global {FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Release|Any CPU.Build.0 = Release|Any CPU - {3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Release|Any CPU.Build.0 = Release|Any CPU + {F2B1A1EB-0FA6-40D0-8908-E13247C7226F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F2B1A1EB-0FA6-40D0-8908-E13247C7226F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F2B1A1EB-0FA6-40D0-8908-E13247C7226F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F2B1A1EB-0FA6-40D0-8908-E13247C7226F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {FD19DDD8-72B2-4024-8665-0D1F7A2AA998} = {3C5BE746-03E5-4895-9988-0B57F162F86C} - {3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5} = {0F0901FF-E8D9-426A-B5A2-17C7F47C1529} + {F2B1A1EB-0FA6-40D0-8908-E13247C7226F} = {0F0901FF-E8D9-426A-B5A2-17C7F47C1529} EndGlobalSection EndGlobal diff --git a/appveyor.yml b/appveyor.yml index 058121f1..ff3204f7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,17 +1,20 @@ -version: '0.15.{build}' +version: '{build}' +image: Visual Studio 2017 -init: -- git config --global core.autocrlf true +pull_requests: + do_not_increment_build_number: true + +branches: + only: + - master + +nuget: + disable_publish_on_pr: true build_script: - ps: .\build.ps1 test: off -cache: -- tools -> build.cake -- tools -> build.ps1 - artifacts: -- path: nupkgs\*.nupkg - name: NuPkgs \ No newline at end of file +- path: src\SharpCompress\bin\Release\*.nupkg \ No newline at end of file diff --git a/build.cake b/build.cake index 0977c35a..c1d19980 100644 --- a/build.cake +++ b/build.cake @@ -1,229 +1,93 @@ -#addin "Cake.Json" - -#addin "nuget:?package=NuGet.Core" - -using NuGet; - - -////////////////////////////////////////////////////////////////////// -// ARGUMENTS -////////////////////////////////////////////////////////////////////// - var target = Argument("target", "Default"); -var apiKey = Argument("apiKey", ""); -var repo = Argument("repo", ""); - -////////////////////////////////////////////////////////////////////// -// PREPARATION -////////////////////////////////////////////////////////////////////// - -var sources = new [] { "https://api.nuget.org/v3/index.json" }; -var publishTarget = ""; - -Warning("============="); -var globalPath = MakeFullPath("global.json"); -var nupkgs = MakeFullPath("nupkgs"); -Warning("Operating on global.json: " + globalPath); -Warning("============="); - -////////////////////////////////////////////////////////////////////// -// FUNCTIONS -////////////////////////////////////////////////////////////////////// - -string MakeFullPath(string relativePath) -{ - if (string.IsNullOrEmpty(repo)) - { - return MakeAbsolute(new DirectoryPath(relativePath)).ToString(); - } - if (!System.IO.Path.IsPathRooted(repo)) - { - return MakeAbsolute(new DirectoryPath(System.IO.Path.Combine(repo,relativePath))).ToString(); - } - return System.IO.Path.Combine(repo, relativePath); -} - -IEnumerable GetAllProjects() -{ - var global = DeserializeJsonFromFile(globalPath); - var projs = global["projects"].Select(x => x.ToString()); - foreach(var y in projs) - { - yield return MakeFullPath(y); - } -} - -IEnumerable GetSourceProjects() -{ - return GetAllProjects().Where(x => x.EndsWith("src")); -} - -IEnumerable GetTestProjects() -{ - return GetAllProjects().Where(x => x.EndsWith("test")); -} - -IEnumerable GetFrameworks(string path) -{ - var projectJObject = DeserializeJsonFromFile(path); - foreach(var prop in ((JObject)projectJObject["frameworks"]).Properties()) - { - yield return prop.Name; - } -} - -string GetVersion(string path) -{ - var projectJObject = DeserializeJsonFromFile(path); - return ((JToken)projectJObject["version"]).ToString(); -} - -IEnumerable GetProjectJsons(IEnumerable projects) -{ - foreach(var proj in projects) - { - foreach(var projectJson in GetFiles(proj + "/**/project.json")) - { - yield return MakeFullPath(projectJson.ToString()); - } - } -} - -bool IsNuGetPublished (FilePath file, string nugetSource) -{ - var pkg = new ZipPackage(file.ToString()); - - var repo = PackageRepositoryFactory.Default.CreateRepository(nugetSource); - - var packages = repo.FindPackagesById(pkg.Id); - - var version = SemanticVersion.Parse(pkg.Version.ToString()); - - //Filter the list of packages that are not Release (Stable) versions - var exists = packages.Any (p => p.Version == version); - - return exists; -} - -////////////////////////////////////////////////////////////////////// -// TASKS -////////////////////////////////////////////////////////////////////// +var tag = Argument("tag", "cake"); Task("Restore") - .Does(() => + .Does(() => { - var settings = new DotNetCoreRestoreSettings - { - Sources = sources, - NoCache = true - }; - - foreach(var project in GetProjectJsons(GetSourceProjects().Concat(GetTestProjects()))) - { - DotNetCoreRestore(project, settings); - } + DotNetCoreRestore("."); }); Task("Build") - .Does(() => + .IsDependentOn("Restore") + .Does(() => { - var settings = new DotNetCoreBuildSettings + if (IsRunningOnWindows()) { - Configuration = "Release" - }; - - foreach(var project in GetProjectJsons(GetSourceProjects().Concat(GetTestProjects()))) + MSBuild("./sharpcompress.sln", c => + { + c.SetConfiguration("Release") + .SetVerbosity(Verbosity.Minimal) + .UseToolVersion(MSBuildToolVersion.VS2017); + }); + } + else { - foreach(var framework in GetFrameworks(project)) + var settings = new DotNetCoreBuildSettings { - Information("Building: {0} on Framework: {1}", project, framework); - Information("========"); - settings.Framework = framework; - DotNetCoreBuild(project, settings); - } - } + Framework = "netstandard1.0", + Configuration = "Release" + }; + + DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings); + + settings.Framework = "netcoreapp1.1"; + DotNetCoreBuild("./tests/SharpCompress.Test/SharpCompress.Test.csproj", settings); + } }); Task("Test") - .Does(() => -{ - var settings = new DotNetCoreTestSettings + .IsDependentOn("Build") + .Does(() => +{ + if (!bool.Parse(EnvironmentVariable("APPVEYOR") ?? "false") + && !bool.Parse(EnvironmentVariable("TRAVIS") ?? "false")) { - Configuration = "Release", - Verbose = true - }; - - foreach(var project in GetProjectJsons(GetTestProjects())) - { - settings.Framework = GetFrameworks(project).First(); - DotNetCoreTest(project.ToString(), settings); + var files = GetFiles("tests/**/*.csproj"); + foreach(var file in files) + { + var settings = new DotNetCoreTestSettings + { + Configuration = "Release" + }; + + DotNetCoreTest(file.ToString(), settings); + } + } + else + { + Information("Skipping tests as this is AppVeyor or Travis CI"); } - -}).ReportError(exception => -{ - Error(exception.ToString()); }); Task("Pack") - .Does(() => -{ - if (DirectoryExists(nupkgs)) - { - DeleteDirectory(nupkgs, true); - } - CreateDirectory(nupkgs); - - var settings = new DotNetCorePackSettings - { - Configuration = "Release", - OutputDirectory = nupkgs - }; - - foreach(var project in GetProjectJsons(GetSourceProjects())) - { - DotNetCorePack(project, settings); - } -}); - -Task("Publish") - .IsDependentOn("Restore") .IsDependentOn("Build") - .IsDependentOn("Test") - .IsDependentOn("Pack") - .Does(() => + .Does(() => { - var packages = GetFiles(nupkgs + "/*.nupkg"); - foreach(var package in packages) + if (IsRunningOnWindows()) { - if (package.ToString().Contains("symbols")) - { - Warning("Skipping Symbols package " + package); - continue; - } - if (IsNuGetPublished(package, sources[1])) - { - throw new InvalidOperationException(package + " is already published."); - } - NuGetPush(package, new NuGetPushSettings{ - ApiKey = apiKey, - Verbosity = NuGetVerbosity.Detailed, - Source = publishTarget - }); - } + MSBuild("src/SharpCompress/SharpCompress.csproj", c => c + .SetConfiguration("Release") + .SetVerbosity(Verbosity.Minimal) + .UseToolVersion(MSBuildToolVersion.VS2017) + .WithProperty("NoBuild", "true") + .WithTarget("Pack")); + } + else + { + Information("Skipping Pack as this is not Windows"); + } }); -////////////////////////////////////////////////////////////////////// -// TASK TARGETS -////////////////////////////////////////////////////////////////////// - Task("Default") .IsDependentOn("Restore") .IsDependentOn("Build") .IsDependentOn("Test") .IsDependentOn("Pack"); -////////////////////////////////////////////////////////////////////// -// EXECUTION -////////////////////////////////////////////////////////////////////// + Task("RunTests") + .IsDependentOn("Restore") + .IsDependentOn("Build") + .IsDependentOn("Test"); + RunTarget(target); \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 878a2dc4..6d04c8cf 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,22 +1,41 @@ +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + <# + .SYNOPSIS This is a Powershell script to bootstrap a Cake build. + .DESCRIPTION This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. .PARAMETER Target The build script target to run. .PARAMETER Configuration The build configuration to use. .PARAMETER Verbosity Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. .PARAMETER WhatIf Performs a dry run of the build script. No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. .PARAMETER ScriptArgs Remaining arguments are added here. + .LINK http://cakebuild.net + #> [CmdletBinding()] @@ -27,104 +46,183 @@ Param( [string]$Configuration = "Release", [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$ScriptArgs ) -$CakeVersion = "0.16.1" -$DotNetChannel = "preview"; -$DotNetVersion = "1.0.0-preview2-003131"; -$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1"; -$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null +function MD5HashFile([string] $filePath) +{ + if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) + { + return $null + } + + [System.IO.Stream] $file = $null; + [System.Security.Cryptography.MD5] $md5 = $null; + try + { + $md5 = [System.Security.Cryptography.MD5]::Create() + $file = [System.IO.File]::OpenRead($filePath) + return [System.BitConverter]::ToString($md5.ComputeHash($file)) + } + finally + { + if ($file -ne $null) + { + $file.Dispose() + } + } +} + +Write-Host "Preparing to run build script..." + +if(!$PSScriptRoot){ + $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +} + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$ADDINS_DIR = Join-Path $TOOLS_DIR "addins" +$MODULES_DIR = Join-Path $TOOLS_DIR "modules" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" +$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" +$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" +$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} # Make sure tools folder exists -$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -$ToolPath = Join-Path $PSScriptRoot "tools" -if (!(Test-Path $ToolPath)) { - Write-Verbose "Creating tools directory..." - New-Item -Path $ToolPath -Type directory | out-null +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null } -########################################################################### -# INSTALL .NET CORE CLI -########################################################################### - -Function Remove-PathVariable([string]$VariableToRemove) -{ - $path = [Environment]::GetEnvironmentVariable("PATH", "User") - if ($path -ne $null) - { - $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove } - [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") - } - - $path = [Environment]::GetEnvironmentVariable("PATH", "Process") - if ($path -ne $null) - { - $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove } - [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + Throw "Could not download packages.config." } } -# Get .NET Core CLI path if installed. -$FoundDotNetCliVersion = $null; -if (Get-Command dotnet -ErrorAction SilentlyContinue) { - $FoundDotNetCliVersion = dotnet --version; -} - -if($FoundDotNetCliVersion -ne $DotNetVersion) { - $InstallPath = Join-Path $PSScriptRoot ".dotnet" - if (!(Test-Path $InstallPath)) { - mkdir -Force $InstallPath | Out-Null; +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName } - (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1"); - & $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath; - - Remove-PathVariable "$InstallPath" - $env:PATH = "$InstallPath;$env:PATH" - $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - $env:DOTNET_CLI_TELEMETRY_OPTOUT=1 } -########################################################################### -# INSTALL NUGET -########################################################################### - -# Make sure nuget.exe exists. -$NugetPath = Join-Path $ToolPath "nuget.exe" -if (!(Test-Path $NugetPath)) { - Write-Host "Downloading NuGet.exe..." - (New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath); +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } } -########################################################################### -# INSTALL CAKE -########################################################################### +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR + + # Check for changes in packages.config and remove installed tools if true. + [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + Write-Verbose -Message "Missing or changed package.config hash..." + Remove-Item * -Recurse -Exclude packages.config,nuget.exe + } + + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" -# Make sure Cake has been installed. -$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe" -if (!(Test-Path $CakePath)) { - Write-Host "Installing Cake..." - Invoke-Expression "&`"$NugetPath`" install Cake -Version $CakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null; if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring Cake from NuGet." + Throw "An error occured while restoring NuGet tools." } + else + { + $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" + } + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location } -########################################################################### -# RUN BUILD SCRIPT -########################################################################### +# Restore addins from NuGet +if (Test-Path $ADDINS_PACKAGES_CONFIG) { + Push-Location + Set-Location $ADDINS_DIR -# Build the argument list. -$Arguments = @{ - target=$Target; - configuration=$Configuration; - verbosity=$Verbosity; - dryrun=$WhatIf; -}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value }; + Write-Verbose -Message "Restoring addins from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet addins." + } + + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location +} + +# Restore modules from NuGet +if (Test-Path $MODULES_PACKAGES_CONFIG) { + Push-Location + Set-Location $MODULES_DIR + + Write-Verbose -Message "Restoring modules from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet modules." + } + + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} # Start Cake Write-Host "Running build script..." -Invoke-Expression "& `"$CakePath`" `"$Script`" $Arguments $ScriptArgs" +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" exit $LASTEXITCODE \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..9ed17711 --- /dev/null +++ b/build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +########################################################################## +# This is the Cake bootstrapper script for Linux and OS X. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +CAKE_VERSION=0.19.1 +CAKE_DLL=$TOOLS_DIR/Cake.CoreCLR.$CAKE_VERSION/Cake.dll + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" +fi + +########################################################################### +# INSTALL CAKE +########################################################################### + +if [ ! -f "$CAKE_DLL" ]; then + curl -Lsfo Cake.CoreCLR.zip "https://www.nuget.org/api/v2/package/Cake.CoreCLR/$CAKE_VERSION" && unzip -q Cake.CoreCLR.zip -d "$TOOLS_DIR/Cake.CoreCLR.$CAKE_VERSION" && rm -f Cake.CoreCLR.zip + if [ $? -ne 0 ]; then + echo "An error occured while installing Cake." + exit 1 + fi +fi + +# Make sure that Cake has been installed. +if [ ! -f "$CAKE_DLL" ]; then + echo "Could not find Cake.exe at '$CAKE_DLL'." + exit 1 +fi + +########################################################################### +# RUN BUILD SCRIPT +########################################################################### + +# Start Cake +exec dotnet "$CAKE_DLL" "$@" \ No newline at end of file diff --git a/global.json b/global.json deleted file mode 100644 index d0f936b5..00000000 --- a/global.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "projects": ["src","test"] -} diff --git a/src/SharpCompress/Archives/AbstractArchive.cs b/src/SharpCompress/Archives/AbstractArchive.cs index cc51b1c4..2981f734 100644 --- a/src/SharpCompress/Archives/AbstractArchive.cs +++ b/src/SharpCompress/Archives/AbstractArchive.cs @@ -61,18 +61,12 @@ namespace SharpCompress.Archives void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry) { - if (EntryExtractionBegin != null) - { - EntryExtractionBegin(this, new ArchiveExtractionEventArgs(entry)); - } + EntryExtractionBegin?.Invoke(this, new ArchiveExtractionEventArgs(entry)); } void IArchiveExtractionListener.FireEntryExtractionEnd(IArchiveEntry entry) { - if (EntryExtractionEnd != null) - { - EntryExtractionEnd(this, new ArchiveExtractionEventArgs(entry)); - } + EntryExtractionEnd?.Invoke(this, new ArchiveExtractionEventArgs(entry)); } private static Stream CheckStreams(Stream stream) @@ -129,27 +123,21 @@ namespace SharpCompress.Archives void IExtractionListener.FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes) { - if (CompressedBytesRead != null) + CompressedBytesRead?.Invoke(this, new CompressedBytesReadEventArgs { - CompressedBytesRead(this, new CompressedBytesReadEventArgs - { - CurrentFilePartCompressedBytesRead = currentPartCompressedBytes, - CompressedBytesRead = compressedReadBytes - }); - } + CurrentFilePartCompressedBytesRead = currentPartCompressedBytes, + CompressedBytesRead = compressedReadBytes + }); } void IExtractionListener.FireFilePartExtractionBegin(string name, long size, long compressedSize) { - if (FilePartExtractionBegin != null) + FilePartExtractionBegin?.Invoke(this, new FilePartExtractionBeginEventArgs { - FilePartExtractionBegin(this, new FilePartExtractionBeginEventArgs - { - CompressedSize = compressedSize, - Size = size, - Name = name - }); - } + CompressedSize = compressedSize, + Size = size, + Name = name + }); } /// diff --git a/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs b/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs index cdbbc89d..7f417171 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs @@ -27,7 +27,7 @@ namespace SharpCompress.Archives.GZip public IArchive Archive { get; } - public bool IsComplete { get { return true; } } + public bool IsComplete => true; #endregion } diff --git a/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs b/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs index 4aec0f62..852b15da 100644 --- a/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs +++ b/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs @@ -22,31 +22,31 @@ namespace SharpCompress.Archives.GZip this.closeStream = closeStream; } - public override long Crc { get { return 0; } } + public override long Crc => 0; public override string Key { get; } - public override long CompressedSize { get { return 0; } } + public override long CompressedSize => 0; public override long Size { get; } public override DateTime? LastModifiedTime { get; } - public override DateTime? CreatedTime { get { return null; } } + public override DateTime? CreatedTime => null; - public override DateTime? LastAccessedTime { get { return null; } } + public override DateTime? LastAccessedTime => null; - public override DateTime? ArchivedTime { get { return null; } } + public override DateTime? ArchivedTime => null; - public override bool IsEncrypted { get { return false; } } + public override bool IsEncrypted => false; - public override bool IsDirectory { get { return false; } } + public override bool IsDirectory => false; - public override bool IsSplit { get { return false; } } + public override bool IsSplit => false; - internal override IEnumerable Parts { get { throw new NotImplementedException(); } } + internal override IEnumerable Parts => throw new NotImplementedException(); - Stream IWritableArchiveEntry.Stream { get { return stream; } } + Stream IWritableArchiveEntry.Stream => stream; public override Stream OpenEntryStream() { diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index b3f48a26..eecd27b6 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -60,7 +60,7 @@ namespace SharpCompress.Archives.Rar return RarReader.Open(stream, ReaderOptions); } - public override bool IsSolid { get { return Volumes.First().IsSolidArchive; } } + public override bool IsSolid => Volumes.First().IsSolidArchive; #region Creation diff --git a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs index 285ab5cf..fe3d5106 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs @@ -20,13 +20,13 @@ namespace SharpCompress.Archives.Rar this.archive = archive; } - public override CompressionType CompressionType { get { return CompressionType.Rar; } } + public override CompressionType CompressionType => CompressionType.Rar; - public IArchive Archive { get { return archive; } } + public IArchive Archive => archive; - internal override IEnumerable Parts { get { return parts.Cast(); } } + internal override IEnumerable Parts => parts.Cast(); - internal override FileHeader FileHeader { get { return parts.First().FileHeader; } } + internal override FileHeader FileHeader => parts.First().FileHeader; public override long Crc { diff --git a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs index eac4ec9d..1e583f07 100644 --- a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs +++ b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs @@ -28,6 +28,6 @@ namespace SharpCompress.Archives.Rar return stream; } - internal override string FilePartName { get { return "Unknown Stream - File Entry: " + FileHeader.FileName; } } + internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; } } \ No newline at end of file diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index e8aac7b7..06cac787 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -106,10 +106,7 @@ namespace SharpCompress.Archives.SevenZip for (int i = 0; i < database.Files.Count; i++) { var file = database.Files[i]; - if (!file.IsDir) - { - yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file)); - } + yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file)); } } @@ -174,7 +171,7 @@ namespace SharpCompress.Archives.SevenZip this.archive = archive; } - public override SevenZipVolume Volume { get { return archive.Volumes.Single(); } } + public override SevenZipVolume Volume => archive.Volumes.Single(); internal override IEnumerable GetEntries(Stream stream) { @@ -209,4 +206,4 @@ namespace SharpCompress.Archives.SevenZip } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs index 7614c94a..ea80b5cb 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs @@ -18,11 +18,11 @@ namespace SharpCompress.Archives.SevenZip public IArchive Archive { get; } - public bool IsComplete { get { return true; } } + public bool IsComplete => true; /// /// This is a 7Zip Anti item /// - public bool IsAnti { get { return FilePart.Header.IsAnti; } } + public bool IsAnti => FilePart.Header.IsAnti; } } \ No newline at end of file diff --git a/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs index 968ab4f2..51a0a49b 100644 --- a/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs @@ -22,7 +22,7 @@ namespace SharpCompress.Archives.Tar public IArchive Archive { get; } - public bool IsComplete { get { return true; } } + public bool IsComplete => true; #endregion } diff --git a/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs b/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs index 784823ec..33c2e766 100644 --- a/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs +++ b/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs @@ -22,30 +22,30 @@ namespace SharpCompress.Archives.Tar this.closeStream = closeStream; } - public override long Crc { get { return 0; } } + public override long Crc => 0; public override string Key { get; } - public override long CompressedSize { get { return 0; } } + public override long CompressedSize => 0; public override long Size { get; } public override DateTime? LastModifiedTime { get; } - public override DateTime? CreatedTime { get { return null; } } + public override DateTime? CreatedTime => null; - public override DateTime? LastAccessedTime { get { return null; } } + public override DateTime? LastAccessedTime => null; - public override DateTime? ArchivedTime { get { return null; } } + public override DateTime? ArchivedTime => null; - public override bool IsEncrypted { get { return false; } } + public override bool IsEncrypted => false; - public override bool IsDirectory { get { return false; } } + public override bool IsDirectory => false; - public override bool IsSplit { get { return false; } } + public override bool IsSplit => false; - internal override IEnumerable Parts { get { throw new NotImplementedException(); } } - Stream IWritableArchiveEntry.Stream { get { return stream; } } + internal override IEnumerable Parts => throw new NotImplementedException(); + Stream IWritableArchiveEntry.Stream => stream; public override Stream OpenEntryStream() { diff --git a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs index 3e4f71f1..2f1f80f2 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs @@ -21,10 +21,10 @@ namespace SharpCompress.Archives.Zip public IArchive Archive { get; } - public bool IsComplete { get { return true; } } + public bool IsComplete => true; #endregion - public string Comment { get { return (Parts.Single() as SeekableZipFilePart).Comment; } } + public string Comment => (Parts.Single() as SeekableZipFilePart).Comment; } } \ No newline at end of file diff --git a/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs b/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs index c40394ea..4b4bbf36 100644 --- a/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs +++ b/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs @@ -23,31 +23,31 @@ namespace SharpCompress.Archives.Zip this.closeStream = closeStream; } - public override long Crc { get { return 0; } } + public override long Crc => 0; public override string Key { get; } - public override long CompressedSize { get { return 0; } } + public override long CompressedSize => 0; public override long Size { get; } public override DateTime? LastModifiedTime { get; } - public override DateTime? CreatedTime { get { return null; } } + public override DateTime? CreatedTime => null; - public override DateTime? LastAccessedTime { get { return null; } } + public override DateTime? LastAccessedTime => null; - public override DateTime? ArchivedTime { get { return null; } } + public override DateTime? ArchivedTime => null; - public override bool IsEncrypted { get { return false; } } + public override bool IsEncrypted => false; - public override bool IsDirectory { get { return false; } } + public override bool IsDirectory => false; - public override bool IsSplit { get { return false; } } + public override bool IsSplit => false; - internal override IEnumerable Parts { get { throw new NotImplementedException(); } } + internal override IEnumerable Parts => throw new NotImplementedException(); - Stream IWritableArchiveEntry.Stream { get { return stream; } } + Stream IWritableArchiveEntry.Stream => stream; public override Stream OpenEntryStream() { diff --git a/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs b/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs index 7295fdf4..b1c9fc75 100644 --- a/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs +++ b/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs @@ -9,6 +9,6 @@ namespace SharpCompress.Common Item = entry; } - public T Item { get; private set; } + public T Item { get; } } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Entry.cs b/src/SharpCompress/Common/Entry.cs index d546aad5..5f07af2f 100644 --- a/src/SharpCompress/Common/Entry.cs +++ b/src/SharpCompress/Common/Entry.cs @@ -75,6 +75,6 @@ namespace SharpCompress.Common /// /// Entry file attribute. /// - public virtual int? Attrib { get { throw new NotImplementedException(); } } + public virtual int? Attrib => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/SharpCompress/Common/EntryStream.cs b/src/SharpCompress/Common/EntryStream.cs index 1df65dbd..0120b782 100644 --- a/src/SharpCompress/Common/EntryStream.cs +++ b/src/SharpCompress/Common/EntryStream.cs @@ -44,20 +44,20 @@ namespace SharpCompress.Common stream.Dispose(); } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Common/GZip/GZipEntry.cs b/src/SharpCompress/Common/GZip/GZipEntry.cs index c347e32a..dd80e73e 100644 --- a/src/SharpCompress/Common/GZip/GZipEntry.cs +++ b/src/SharpCompress/Common/GZip/GZipEntry.cs @@ -13,31 +13,31 @@ namespace SharpCompress.Common.GZip this.filePart = filePart; } - public override CompressionType CompressionType { get { return CompressionType.GZip; } } + public override CompressionType CompressionType => CompressionType.GZip; - public override long Crc { get { return 0; } } + public override long Crc => 0; - public override string Key { get { return filePart.FilePartName; } } + public override string Key => filePart.FilePartName; - public override long CompressedSize { get { return 0; } } + public override long CompressedSize => 0; - public override long Size { get { return 0; } } + public override long Size => 0; - public override DateTime? LastModifiedTime { get { return filePart.DateModified; } } + public override DateTime? LastModifiedTime => filePart.DateModified; - public override DateTime? CreatedTime { get { return null; } } + public override DateTime? CreatedTime => null; - public override DateTime? LastAccessedTime { get { return null; } } + public override DateTime? LastAccessedTime => null; - public override DateTime? ArchivedTime { get { return null; } } + public override DateTime? ArchivedTime => null; - public override bool IsEncrypted { get { return false; } } + public override bool IsEncrypted => false; - public override bool IsDirectory { get { return false; } } + public override bool IsDirectory => false; - public override bool IsSplit { get { return false; } } + public override bool IsSplit => false; - internal override IEnumerable Parts { get { return filePart.AsEnumerable(); } } + internal override IEnumerable Parts => filePart.AsEnumerable(); internal static IEnumerable GetEntries(Stream stream) { diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.cs b/src/SharpCompress/Common/GZip/GZipFilePart.cs index f793195a..7690a014 100644 --- a/src/SharpCompress/Common/GZip/GZipFilePart.cs +++ b/src/SharpCompress/Common/GZip/GZipFilePart.cs @@ -24,7 +24,7 @@ namespace SharpCompress.Common.GZip internal DateTime? DateModified { get; private set; } - internal override string FilePartName { get { return name; } } + internal override string FilePartName => name; internal override Stream GetCompressedStream() { diff --git a/src/SharpCompress/Common/GZip/GZipVolume.cs b/src/SharpCompress/Common/GZip/GZipVolume.cs index c3a8bd68..7da73560 100644 --- a/src/SharpCompress/Common/GZip/GZipVolume.cs +++ b/src/SharpCompress/Common/GZip/GZipVolume.cs @@ -18,8 +18,8 @@ namespace SharpCompress.Common.GZip } #endif - public override bool IsFirstVolume { get { return true; } } + public override bool IsFirstVolume => true; - public override bool IsMultiVolume { get { return true; } } + public override bool IsMultiVolume => true; } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs index 2f982946..214a25c0 100644 --- a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs @@ -17,7 +17,7 @@ namespace SharpCompress.Common.Rar.Headers } } - internal ArchiveFlags ArchiveHeaderFlags { get { return (ArchiveFlags)Flags; } } + internal ArchiveFlags ArchiveHeaderFlags => (ArchiveFlags)Flags; internal short HighPosAv { get; private set; } @@ -25,6 +25,6 @@ namespace SharpCompress.Common.Rar.Headers internal byte EncryptionVersion { get; private set; } - public bool HasPassword { get { return ArchiveHeaderFlags.HasFlag(ArchiveFlags.PASSWORD); } } + public bool HasPassword => ArchiveHeaderFlags.HasFlag(ArchiveFlags.PASSWORD); } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs b/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs index 30e5acea..b2f62039 100644 --- a/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs @@ -16,7 +16,7 @@ namespace SharpCompress.Common.Rar.Headers } } - internal EndArchiveFlags EndArchiveFlags { get { return (EndArchiveFlags)Flags; } } + internal EndArchiveFlags EndArchiveFlags => (EndArchiveFlags)Flags; internal int? ArchiveCRC { get; private set; } diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs index 8cdd7135..f0359a24 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs @@ -165,25 +165,13 @@ namespace SharpCompress.Common.Rar.Headers #if NO_FILE return path.Replace('\\', '/'); #else - switch (os) + if (Path.DirectorySeparatorChar == '/') { - case HostOS.MacOS: - case HostOS.Unix: - { - if (Path.DirectorySeparatorChar == '\\') - { - return path.Replace('/', '\\'); - } - } - break; - default: - { - if (Path.DirectorySeparatorChar == '/') - { - return path.Replace('\\', '/'); - } - } - break; + return path.Replace('\\', '/'); + } + else if (Path.DirectorySeparatorChar == '\\') + { + return path.Replace('/', '\\'); } return path; #endif @@ -208,7 +196,7 @@ namespace SharpCompress.Common.Rar.Headers internal int FileAttributes { get; private set; } - internal FileFlags FileFlags { get { return (FileFlags)Flags; } } + internal FileFlags FileFlags => (FileFlags)Flags; internal long CompressedSize { get; private set; } internal long UncompressedSize { get; private set; } diff --git a/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs b/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs index b72391d4..e2f78c32 100644 --- a/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs @@ -13,7 +13,7 @@ namespace SharpCompress.Common.Rar.Headers Mark = reader.ReadBytes(8); } - internal uint DataSize { get { return AdditionalSize; } } + internal uint DataSize => AdditionalSize; internal byte Version { get; private set; } internal ushort RecSectors { get; private set; } internal uint TotalBlocks { get; private set; } diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeader.cs b/src/SharpCompress/Common/Rar/Headers/RarHeader.cs index ecfaad65..02658389 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeader.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using SharpCompress.IO; namespace SharpCompress.Common.Rar.Headers @@ -18,14 +19,14 @@ namespace SharpCompress.Common.Rar.Headers ReadBytes = baseHeader.ReadBytes; } - internal static RarHeader Create(MarkingBinaryReader reader) + internal static RarHeader Create(RarCrcBinaryReader reader) { try { RarHeader header = new RarHeader(); reader.Mark(); - header.ReadFromReader(reader); + header.ReadStartFromReader(reader); header.ReadBytes += reader.CurrentReadByteCount; return header; @@ -36,9 +37,10 @@ namespace SharpCompress.Common.Rar.Headers } } - protected virtual void ReadFromReader(MarkingBinaryReader reader) + private void ReadStartFromReader(RarCrcBinaryReader reader) { - HeadCRC = reader.ReadInt16(); + HeadCRC = reader.ReadUInt16(); + reader.ResetCrc(); HeaderType = (HeaderType)(reader.ReadByte() & 0xff); Flags = reader.ReadInt16(); HeaderSize = reader.ReadInt16(); @@ -48,7 +50,11 @@ namespace SharpCompress.Common.Rar.Headers } } - internal T PromoteHeader(MarkingBinaryReader reader) + protected virtual void ReadFromReader(MarkingBinaryReader reader) { + throw new NotImplementedException(); + } + + internal T PromoteHeader(RarCrcBinaryReader reader) where T : RarHeader, new() { T header = new T(); @@ -65,9 +71,21 @@ namespace SharpCompress.Common.Rar.Headers reader.ReadBytes(headerSizeDiff); } + VerifyHeaderCrc(reader.GetCrc()); + return header; } + private void VerifyHeaderCrc(ushort crc) { + if (HeaderType != HeaderType.MarkHeader) + { + if (crc != HeadCRC) + { + throw new InvalidFormatException("rar header crc mismatch"); + } + } + } + protected virtual void PostReadingBytes(MarkingBinaryReader reader) { } @@ -77,7 +95,7 @@ namespace SharpCompress.Common.Rar.Headers /// protected long ReadBytes { get; private set; } - protected short HeadCRC { get; private set; } + protected ushort HeadCRC { get; private set; } internal HeaderType HeaderType { get; private set; } diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs index 8d9f2412..13e02722 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs @@ -129,7 +129,7 @@ namespace SharpCompress.Common.Rar.Headers reader.InitializeAes(salt); } #else - var reader = new MarkingBinaryReader(stream); + var reader = new RarCrcBinaryReader(stream); #endif @@ -247,4 +247,4 @@ namespace SharpCompress.Common.Rar.Headers } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs new file mode 100644 index 00000000..6df617b5 --- /dev/null +++ b/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs @@ -0,0 +1,40 @@ +using System.IO; +using SharpCompress.Compressors.Rar; +using SharpCompress.IO; + +namespace SharpCompress.Common.Rar { + internal class RarCrcBinaryReader : MarkingBinaryReader { + private uint currentCrc; + + public RarCrcBinaryReader(Stream stream) : base(stream) + { + } + + public ushort GetCrc() + { + return (ushort)~currentCrc; + } + + public void ResetCrc() + { + currentCrc = 0xffffffff; + } + + protected void UpdateCrc(byte b) + { + currentCrc = RarCRC.CheckCrc(currentCrc, b); + } + + protected byte[] ReadBytesNoCrc(int count) + { + return base.ReadBytes(count); + } + + public override byte[] ReadBytes(int count) + { + var result = base.ReadBytes(count); + currentCrc = RarCRC.CheckCrc(currentCrc, result, 0, result.Length); + return result; + } + } +} \ No newline at end of file diff --git a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs index 40f64d19..9635375b 100644 --- a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs +++ b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs @@ -6,12 +6,13 @@ using SharpCompress.IO; namespace SharpCompress.Common.Rar { - internal class RarCryptoBinaryReader : MarkingBinaryReader + internal class RarCryptoBinaryReader : RarCrcBinaryReader { private RarRijndael rijndael; private byte[] salt; private readonly string password; private readonly Queue data = new Queue(); + private long readCount; public RarCryptoBinaryReader(Stream stream, string password ) : base(stream) @@ -19,6 +20,22 @@ namespace SharpCompress.Common.Rar this.password = password; } + // track read count ourselves rather than using the underlying stream since we buffer + public override long CurrentReadByteCount { + get + { + return this.readCount; + } + protected set + { + // ignore + } + } + + public override void Mark() { + this.readCount = 0; + } + protected bool UseEncryption { get { return salt != null; } @@ -36,6 +53,7 @@ namespace SharpCompress.Common.Rar { return ReadAndDecryptBytes(count); } + this.readCount += count; return base.ReadBytes(count); } @@ -50,7 +68,7 @@ namespace SharpCompress.Common.Rar for (int i = 0; i < alignedSize / 16; i++) { //long ax = System.currentTimeMillis(); - byte[] cipherText = base.ReadBytes(16); + byte[] cipherText = base.ReadBytesNoCrc(16); var readBytes = rijndael.ProcessBlock(cipherText); foreach (var readByte in readBytes) data.Enqueue(readByte); @@ -63,8 +81,11 @@ namespace SharpCompress.Common.Rar for (int i = 0; i < count; i++) { - decryptedBytes[i] = data.Dequeue(); + var b = data.Dequeue(); + decryptedBytes[i] = b; + UpdateCrc(b); } + this.readCount += count; return decryptedBytes; } diff --git a/src/SharpCompress/Common/Rar/RarEntry.cs b/src/SharpCompress/Common/Rar/RarEntry.cs index c69a514e..cddfca3e 100644 --- a/src/SharpCompress/Common/Rar/RarEntry.cs +++ b/src/SharpCompress/Common/Rar/RarEntry.cs @@ -10,44 +10,44 @@ namespace SharpCompress.Common.Rar /// /// The File's 32 bit CRC Hash /// - public override long Crc { get { return FileHeader.FileCRC; } } + public override long Crc => FileHeader.FileCRC; /// /// The path of the file internal to the Rar Archive. /// - public override string Key { get { return FileHeader.FileName; } } + public override string Key => FileHeader.FileName; /// /// The entry last modified time in the archive, if recorded /// - public override DateTime? LastModifiedTime { get { return FileHeader.FileLastModifiedTime; } } + public override DateTime? LastModifiedTime => FileHeader.FileLastModifiedTime; /// /// The entry create time in the archive, if recorded /// - public override DateTime? CreatedTime { get { return FileHeader.FileCreatedTime; } } + public override DateTime? CreatedTime => FileHeader.FileCreatedTime; /// /// The entry last accessed time in the archive, if recorded /// - public override DateTime? LastAccessedTime { get { return FileHeader.FileLastAccessedTime; } } + public override DateTime? LastAccessedTime => FileHeader.FileLastAccessedTime; /// /// The entry time whend archived, if recorded /// - public override DateTime? ArchivedTime { get { return FileHeader.FileArchivedTime; } } + public override DateTime? ArchivedTime => FileHeader.FileArchivedTime; /// /// Entry is password protected and encrypted and cannot be extracted. /// - public override bool IsEncrypted { get { return FileHeader.FileFlags.HasFlag(FileFlags.PASSWORD); } } + public override bool IsEncrypted => FileHeader.FileFlags.HasFlag(FileFlags.PASSWORD); /// /// Entry is password protected and encrypted and cannot be extracted. /// - public override bool IsDirectory { get { return FileHeader.FileFlags.HasFlag(FileFlags.DIRECTORY); } } + public override bool IsDirectory => FileHeader.FileFlags.HasFlag(FileFlags.DIRECTORY); - public override bool IsSplit { get { return FileHeader.FileFlags.HasFlag(FileFlags.SPLIT_AFTER); } } + public override bool IsSplit => FileHeader.FileFlags.HasFlag(FileFlags.SPLIT_AFTER); public override string ToString() { diff --git a/src/SharpCompress/Common/Rar/RarFilePart.cs b/src/SharpCompress/Common/Rar/RarFilePart.cs index c9d00dc0..d52fedea 100644 --- a/src/SharpCompress/Common/Rar/RarFilePart.cs +++ b/src/SharpCompress/Common/Rar/RarFilePart.cs @@ -14,9 +14,9 @@ namespace SharpCompress.Common.Rar FileHeader = fh; } - internal MarkHeader MarkHeader { get; private set; } + internal MarkHeader MarkHeader { get; } - internal FileHeader FileHeader { get; private set; } + internal FileHeader FileHeader { get; } internal override Stream GetRawStream() { diff --git a/src/SharpCompress/Common/Rar/RarVolume.cs b/src/SharpCompress/Common/Rar/RarVolume.cs index c7e9729f..89fee688 100644 --- a/src/SharpCompress/Common/Rar/RarVolume.cs +++ b/src/SharpCompress/Common/Rar/RarVolume.cs @@ -21,7 +21,7 @@ namespace SharpCompress.Common.Rar headerFactory = new RarHeaderFactory(mode, options); } - internal StreamingMode Mode { get { return headerFactory.StreamingMode; } } + internal StreamingMode Mode => headerFactory.StreamingMode; internal abstract IEnumerable ReadFileParts(); diff --git a/src/SharpCompress/Common/ReaderExtractionEventArgs.cs b/src/SharpCompress/Common/ReaderExtractionEventArgs.cs index b33b8635..aadc563c 100644 --- a/src/SharpCompress/Common/ReaderExtractionEventArgs.cs +++ b/src/SharpCompress/Common/ReaderExtractionEventArgs.cs @@ -1,14 +1,17 @@ using System; +using SharpCompress.Readers; namespace SharpCompress.Common { public class ReaderExtractionEventArgs : EventArgs { - internal ReaderExtractionEventArgs(T entry) + internal ReaderExtractionEventArgs(T entry, ReaderProgress readerProgress = null) { Item = entry; + ReaderProgress = readerProgress; } - public T Item { get; private set; } + public T Item { get; } + public ReaderProgress ReaderProgress { get; } } } \ No newline at end of file diff --git a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs index ad6992cc..64a18b8b 100644 --- a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs +++ b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs @@ -1339,20 +1339,20 @@ namespace SharpCompress.Common.SevenZip #region Stream - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Common/SevenZip/CFileItem.cs b/src/SharpCompress/Common/SevenZip/CFileItem.cs index 9d4960e3..450cbdfc 100644 --- a/src/SharpCompress/Common/SevenZip/CFileItem.cs +++ b/src/SharpCompress/Common/SevenZip/CFileItem.cs @@ -12,9 +12,9 @@ namespace SharpCompress.Common.SevenZip public bool HasStream { get; internal set; } public bool IsDir { get; internal set; } - public bool CrcDefined { get { return Crc != null; } } + public bool CrcDefined => Crc != null; - public bool AttribDefined { get { return Attrib != null; } } + public bool AttribDefined => Attrib != null; public void SetAttrib(uint attrib) { diff --git a/src/SharpCompress/Common/SevenZip/CFolder.cs b/src/SharpCompress/Common/SevenZip/CFolder.cs index 008c041c..4606d9dc 100644 --- a/src/SharpCompress/Common/SevenZip/CFolder.cs +++ b/src/SharpCompress/Common/SevenZip/CFolder.cs @@ -13,7 +13,7 @@ namespace SharpCompress.Common.SevenZip internal List UnpackSizes = new List(); internal uint? UnpackCRC; - internal bool UnpackCRCDefined { get { return UnpackCRC != null; } } + internal bool UnpackCRCDefined => UnpackCRC != null; public long GetUnpackSize() { diff --git a/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs b/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs index e6665f01..dd23d629 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs @@ -12,32 +12,32 @@ namespace SharpCompress.Common.SevenZip internal SevenZipFilePart FilePart { get; } - public override CompressionType CompressionType { get { return FilePart.CompressionType; } } + public override CompressionType CompressionType => FilePart.CompressionType; - public override long Crc { get { return FilePart.Header.Crc ?? 0; } } + public override long Crc => FilePart.Header.Crc ?? 0; - public override string Key { get { return FilePart.Header.Name; } } + public override string Key => FilePart.Header.Name; - public override long CompressedSize { get { return 0; } } + public override long CompressedSize => 0; - public override long Size { get { return FilePart.Header.Size; } } + public override long Size => FilePart.Header.Size; - public override DateTime? LastModifiedTime { get { return FilePart.Header.MTime; } } + public override DateTime? LastModifiedTime => FilePart.Header.MTime; - public override DateTime? CreatedTime { get { return null; } } + public override DateTime? CreatedTime => null; - public override DateTime? LastAccessedTime { get { return null; } } + public override DateTime? LastAccessedTime => null; - public override DateTime? ArchivedTime { get { return null; } } + public override DateTime? ArchivedTime => null; - public override bool IsEncrypted { get { return false; } } + public override bool IsEncrypted => false; - public override bool IsDirectory { get { return FilePart.Header.IsDir; } } + public override bool IsDirectory => FilePart.Header.IsDir; - public override bool IsSplit { get { return false; } } + public override bool IsSplit => false; - public override int? Attrib { get { return (int)FilePart.Header.Attrib; } } + public override int? Attrib => (int)FilePart.Header.Attrib; - internal override IEnumerable Parts { get { return FilePart.AsEnumerable(); } } + internal override IEnumerable Parts => FilePart.AsEnumerable(); } } \ No newline at end of file diff --git a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs index 7f77aadf..13ac91b6 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs @@ -28,7 +28,7 @@ namespace SharpCompress.Common.SevenZip internal CFolder Folder { get; } internal int Index { get; } - internal override string FilePartName { get { return Header.Name; } } + internal override string FilePartName => Header.Name; internal override Stream GetRawStream() { diff --git a/src/SharpCompress/Common/Tar/TarEntry.cs b/src/SharpCompress/Common/Tar/TarEntry.cs index 6fe0ba9e..101271a9 100644 --- a/src/SharpCompress/Common/Tar/TarEntry.cs +++ b/src/SharpCompress/Common/Tar/TarEntry.cs @@ -18,29 +18,29 @@ namespace SharpCompress.Common.Tar public override CompressionType CompressionType { get; } - public override long Crc { get { return 0; } } + public override long Crc => 0; - public override string Key { get { return filePart.Header.Name; } } + public override string Key => filePart.Header.Name; - public override long CompressedSize { get { return filePart.Header.Size; } } + public override long CompressedSize => filePart.Header.Size; - public override long Size { get { return filePart.Header.Size; } } + public override long Size => filePart.Header.Size; - public override DateTime? LastModifiedTime { get { return filePart.Header.LastModifiedTime; } } + public override DateTime? LastModifiedTime => filePart.Header.LastModifiedTime; - public override DateTime? CreatedTime { get { return null; } } + public override DateTime? CreatedTime => null; - public override DateTime? LastAccessedTime { get { return null; } } + public override DateTime? LastAccessedTime => null; - public override DateTime? ArchivedTime { get { return null; } } + public override DateTime? ArchivedTime => null; - public override bool IsEncrypted { get { return false; } } + public override bool IsEncrypted => false; - public override bool IsDirectory { get { return filePart.Header.EntryType == EntryType.Directory; } } + public override bool IsDirectory => filePart.Header.EntryType == EntryType.Directory; - public override bool IsSplit { get { return false; } } + public override bool IsSplit => false; - internal override IEnumerable Parts { get { return filePart.AsEnumerable(); } } + internal override IEnumerable Parts => filePart.AsEnumerable(); internal static IEnumerable GetEntries(StreamingMode mode, Stream stream, CompressionType compressionType) diff --git a/src/SharpCompress/Common/Tar/TarFilePart.cs b/src/SharpCompress/Common/Tar/TarFilePart.cs index 3b0a5729..d3569df1 100644 --- a/src/SharpCompress/Common/Tar/TarFilePart.cs +++ b/src/SharpCompress/Common/Tar/TarFilePart.cs @@ -16,7 +16,7 @@ namespace SharpCompress.Common.Tar internal TarHeader Header { get; } - internal override string FilePartName { get { return Header.Name; } } + internal override string FilePartName => Header.Name; internal override Stream GetCompressedStream() { diff --git a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs index 420bdafe..337dad74 100644 --- a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs +++ b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs @@ -42,20 +42,20 @@ namespace SharpCompress.Common.Tar public Stream Stream { get; } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Common/Volume.cs b/src/SharpCompress/Common/Volume.cs index d5921ab7..87b0d856 100644 --- a/src/SharpCompress/Common/Volume.cs +++ b/src/SharpCompress/Common/Volume.cs @@ -14,7 +14,7 @@ namespace SharpCompress.Common ReaderOptions = readerOptions; } - internal Stream Stream { get { return new NonDisposingStream(actualStream); } } + internal Stream Stream => new NonDisposingStream(actualStream); protected ReaderOptions ReaderOptions { get; } @@ -22,12 +22,12 @@ namespace SharpCompress.Common /// RarArchive is the first volume of a multi-part archive. /// Only Rar 3.0 format and higher /// - public virtual bool IsFirstVolume { get { return true; } } + public virtual bool IsFirstVolume => true; /// /// RarArchive is part of a multi-part archive. /// - public virtual bool IsMultiVolume { get { return true; } } + public virtual bool IsMultiVolume => true; private bool disposed; diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs index f4de3057..dddf3c22 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs @@ -37,14 +37,8 @@ namespace SharpCompress.Common.Zip.Headers public ushort TotalNumberOfEntries { get; private set; } - public bool IsZip64 - { - get - { - return TotalNumberOfEntriesInDisk == ushort.MaxValue - || DirectorySize == uint.MaxValue - || DirectoryStartOffsetRelativeToDisk == uint.MaxValue; - } - } + public bool IsZip64 => TotalNumberOfEntriesInDisk == ushort.MaxValue + || DirectorySize == uint.MaxValue + || DirectoryStartOffsetRelativeToDisk == uint.MaxValue; } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs index 14033ab6..23ae243a 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs @@ -25,7 +25,7 @@ namespace SharpCompress.Common.Zip.Headers internal class ExtraUnicodePathExtraField : ExtraData { - internal byte Version { get { return DataBytes[0]; } } + internal byte Version => DataBytes[0]; internal byte[] NameCRC32 { diff --git a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs index 924ade93..6ffc2781 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs @@ -113,6 +113,6 @@ namespace SharpCompress.Common.Zip.Headers internal ZipFilePart Part { get; set; } - internal bool IsZip64 { get { return CompressedSize == uint.MaxValue; } } + internal bool IsZip64 => CompressedSize == uint.MaxValue; } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs b/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs index 9a564fc9..d62513da 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs @@ -10,7 +10,7 @@ namespace SharpCompress.Common.Zip.Headers HasData = true; } - internal ZipHeaderType ZipHeaderType { get; private set; } + internal ZipHeaderType ZipHeaderType { get; } internal abstract void Read(BinaryReader reader); diff --git a/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs b/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs index 86d0d2d9..c43c4d00 100644 --- a/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs +++ b/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs @@ -23,15 +23,15 @@ namespace SharpCompress.Common.Zip this.mode = mode; } - public override bool CanRead { get { return (mode == CryptoMode.Decrypt); } } + public override bool CanRead => (mode == CryptoMode.Decrypt); - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return (mode == CryptoMode.Encrypt); } } + public override bool CanWrite => (mode == CryptoMode.Encrypt); - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs index 5042f23f..73600aa1 100644 --- a/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs @@ -24,7 +24,7 @@ namespace SharpCompress.Common.Zip return base.GetCompressedStream(); } - internal string Comment { get { return (Header as DirectoryEntryHeader).Comment; } } + internal string Comment => (Header as DirectoryEntryHeader).Comment; private void LoadLocalHeader() { diff --git a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs index 576b23d1..84c87700 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs @@ -25,7 +25,7 @@ namespace SharpCompress.Common.Zip { return Stream.Null; } - decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream())); + decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod); if (LeaveStreamOpen) { return new NonDisposingStream(decompressionStream); diff --git a/src/SharpCompress/Common/Zip/ZipEntry.cs b/src/SharpCompress/Common/Zip/ZipEntry.cs index 45363306..8b8c7337 100644 --- a/src/SharpCompress/Common/Zip/ZipEntry.cs +++ b/src/SharpCompress/Common/Zip/ZipEntry.cs @@ -52,28 +52,28 @@ namespace SharpCompress.Common.Zip } } - public override long Crc { get { return filePart.Header.Crc; } } + public override long Crc => filePart.Header.Crc; - public override string Key { get { return filePart.Header.Name; } } + public override string Key => filePart.Header.Name; - public override long CompressedSize { get { return filePart.Header.CompressedSize; } } + public override long CompressedSize => filePart.Header.CompressedSize; - public override long Size { get { return filePart.Header.UncompressedSize; } } + public override long Size => filePart.Header.UncompressedSize; public override DateTime? LastModifiedTime { get; } - public override DateTime? CreatedTime { get { return null; } } + public override DateTime? CreatedTime => null; - public override DateTime? LastAccessedTime { get { return null; } } + public override DateTime? LastAccessedTime => null; - public override DateTime? ArchivedTime { get { return null; } } + public override DateTime? ArchivedTime => null; - public override bool IsEncrypted { get { return FlagUtility.HasFlag(filePart.Header.Flags, HeaderFlags.Encrypted); } } + public override bool IsEncrypted => FlagUtility.HasFlag(filePart.Header.Flags, HeaderFlags.Encrypted); - public override bool IsDirectory { get { return filePart.Header.IsDirectory; } } + public override bool IsDirectory => filePart.Header.IsDirectory; - public override bool IsSplit { get { return false; } } + public override bool IsSplit => false; - internal override IEnumerable Parts { get { return filePart.AsEnumerable(); } } + internal override IEnumerable Parts => filePart.AsEnumerable(); } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index 5c9a68b1..8e09461e 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -21,10 +21,10 @@ namespace SharpCompress.Common.Zip BaseStream = stream; } - internal Stream BaseStream { get; private set; } + internal Stream BaseStream { get; } internal ZipFileEntry Header { get; set; } - internal override string FilePartName { get { return Header.Name; } } + internal override string FilePartName => Header.Name; internal override Stream GetCompressedStream() { @@ -32,7 +32,7 @@ namespace SharpCompress.Common.Zip { return Stream.Null; } - Stream decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream())); + Stream decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod); if (LeaveStreamOpen) { return new NonDisposingStream(decompressionStream); @@ -51,11 +51,11 @@ namespace SharpCompress.Common.Zip protected abstract Stream CreateBaseStream(); - protected bool LeaveStreamOpen { get { return FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor) || Header.IsZip64; } } + protected bool LeaveStreamOpen => FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor) || Header.IsZip64; - protected Stream CreateDecompressionStream(Stream stream) + protected Stream CreateDecompressionStream(Stream stream, ZipCompressionMethod method) { - switch (Header.CompressionMethod) + switch (method) { case ZipCompressionMethod.None: { @@ -102,9 +102,9 @@ namespace SharpCompress.Common.Zip { throw new InvalidFormatException("Winzip data length is not 7."); } - ushort method = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0); + ushort compressedMethod = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0); - if (method != 0x01 && method != 0x02) + if (compressedMethod != 0x01 && compressedMethod != 0x02) { throw new InvalidFormatException("Unexpected vendor version number for WinZip AES metadata"); } @@ -114,8 +114,7 @@ namespace SharpCompress.Common.Zip { throw new InvalidFormatException("Unexpected vendor ID for WinZip AES metadata"); } - Header.CompressionMethod = (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5); - return CreateDecompressionStream(stream); + return CreateDecompressionStream(stream, (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5)); } default: { diff --git a/src/SharpCompress/Compressors/ADC/ADCStream.cs b/src/SharpCompress/Compressors/ADC/ADCStream.cs index c1d0bacc..2a909568 100644 --- a/src/SharpCompress/Compressors/ADC/ADCStream.cs +++ b/src/SharpCompress/Compressors/ADC/ADCStream.cs @@ -73,15 +73,15 @@ namespace SharpCompress.Compressors.ADC this.stream = stream; } - public override bool CanRead { get { return stream.CanRead; } } + public override bool CanRead => stream.CanRead; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { return position; } set { throw new NotSupportedException(); } } + public override long Position { get => position; set => throw new NotSupportedException(); } public override void Flush() { diff --git a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs index e2685e27..590313d3 100644 --- a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs +++ b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs @@ -48,20 +48,20 @@ namespace SharpCompress.Compressors.BZip2 public CompressionMode Mode { get; } - public override bool CanRead { get { return stream.CanRead; } } + public override bool CanRead => stream.CanRead; - public override bool CanSeek { get { return stream.CanSeek; } } + public override bool CanSeek => stream.CanSeek; - public override bool CanWrite { get { return stream.CanWrite; } } + public override bool CanWrite => stream.CanWrite; public override void Flush() { stream.Flush(); } - public override long Length { get { return stream.Length; } } + public override long Length => stream.Length; - public override long Position { get { return stream.Position; } set { stream.Position = value; } } + public override long Position { get => stream.Position; set => stream.Position = value; } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs index 0c9bca55..0656801e 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs @@ -1092,13 +1092,13 @@ namespace SharpCompress.Compressors.BZip2 { } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; - public override long Length { get { return 0; } } + public override long Length => 0; public override long Position { get { return 0; } set { } } } diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs index 56dcf4f9..9f4817cc 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs @@ -1956,13 +1956,13 @@ namespace SharpCompress.Compressors.BZip2 } } - public override bool CanRead { get { return false; } } + public override bool CanRead => false; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return true; } } + public override bool CanWrite => true; - public override long Length { get { return 0; } } + public override long Length => 0; public override long Position { get { return 0; } set { } } } diff --git a/src/SharpCompress/Compressors/Deflate/CRC32.cs b/src/SharpCompress/Compressors/Deflate/CRC32.cs index c1263574..9be80960 100644 --- a/src/SharpCompress/Compressors/Deflate/CRC32.cs +++ b/src/SharpCompress/Compressors/Deflate/CRC32.cs @@ -92,14 +92,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Indicates the current CRC for all blocks slurped in. /// - public Int32 Crc32Result - { - get - { - // return one's complement of the running result - return unchecked((Int32)(~runningCrc32Result)); - } - } + public Int32 Crc32Result => unchecked((Int32)(~runningCrc32Result)); /// /// Returns the CRC32 for the specified stream. diff --git a/src/SharpCompress/Compressors/Deflate/DeflateStream.cs b/src/SharpCompress/Compressors/Deflate/DeflateStream.cs index 23399464..8ccaca1e 100644 --- a/src/SharpCompress/Compressors/Deflate/DeflateStream.cs +++ b/src/SharpCompress/Compressors/Deflate/DeflateStream.cs @@ -50,7 +50,7 @@ namespace SharpCompress.Compressors.Deflate /// public virtual FlushType FlushMode { - get { return (_baseStream._flushMode); } + get => (_baseStream._flushMode); set { if (_disposed) @@ -80,7 +80,7 @@ namespace SharpCompress.Compressors.Deflate /// public int BufferSize { - get { return _baseStream._bufferSize; } + get => _baseStream._bufferSize; set { if (_disposed) @@ -111,7 +111,7 @@ namespace SharpCompress.Compressors.Deflate /// public CompressionStrategy Strategy { - get { return _baseStream.Strategy; } + get => _baseStream.Strategy; set { if (_disposed) @@ -123,10 +123,10 @@ namespace SharpCompress.Compressors.Deflate } /// Returns the total number of bytes input so far. - public virtual long TotalIn { get { return _baseStream._z.TotalBytesIn; } } + public virtual long TotalIn => _baseStream._z.TotalBytesIn; /// Returns the total number of bytes output so far. - public virtual long TotalOut { get { return _baseStream._z.TotalBytesOut; } } + public virtual long TotalOut => _baseStream._z.TotalBytesOut; #endregion @@ -156,7 +156,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Always returns false. /// - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; /// /// Indicates whether the stream can be written. @@ -179,7 +179,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Reading this property always throws a . /// - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); /// /// The position of the stream pointer. @@ -206,7 +206,7 @@ namespace SharpCompress.Compressors.Deflate } return 0; } - set { throw new NotSupportedException(); } + set => throw new NotSupportedException(); } /// @@ -342,13 +342,7 @@ namespace SharpCompress.Compressors.Deflate #endregion - public MemoryStream InputBuffer - { - get - { - return new MemoryStream(_baseStream._z.InputBuffer, _baseStream._z.NextIn, - _baseStream._z.AvailableBytesIn); - } - } + public MemoryStream InputBuffer => new MemoryStream(_baseStream._z.InputBuffer, _baseStream._z.NextIn, + _baseStream._z.AvailableBytesIn); } } \ No newline at end of file diff --git a/src/SharpCompress/Compressors/Deflate/GZipStream.cs b/src/SharpCompress/Compressors/Deflate/GZipStream.cs index a7a7f74d..8e775c99 100644 --- a/src/SharpCompress/Compressors/Deflate/GZipStream.cs +++ b/src/SharpCompress/Compressors/Deflate/GZipStream.cs @@ -71,7 +71,7 @@ namespace SharpCompress.Compressors.Deflate public virtual FlushType FlushMode { - get { return (BaseStream._flushMode); } + get => (BaseStream._flushMode); set { if (disposed) @@ -84,7 +84,7 @@ namespace SharpCompress.Compressors.Deflate public int BufferSize { - get { return BaseStream._bufferSize; } + get => BaseStream._bufferSize; set { if (disposed) @@ -105,9 +105,9 @@ namespace SharpCompress.Compressors.Deflate } } - internal virtual long TotalIn { get { return BaseStream._z.TotalBytesIn; } } + internal virtual long TotalIn => BaseStream._z.TotalBytesIn; - internal virtual long TotalOut { get { return BaseStream._z.TotalBytesOut; } } + internal virtual long TotalOut => BaseStream._z.TotalBytesOut; #endregion @@ -137,7 +137,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Always returns false. /// - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; /// /// Indicates whether the stream can be written. @@ -160,7 +160,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Reading this property always throws a . /// - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); /// /// The position of the stream pointer. @@ -188,7 +188,7 @@ namespace SharpCompress.Compressors.Deflate return 0; } - set { throw new NotSupportedException(); } + set => throw new NotSupportedException(); } /// @@ -350,7 +350,7 @@ namespace SharpCompress.Compressors.Deflate public String Comment { - get { return comment; } + get => comment; set { if (disposed) @@ -363,7 +363,7 @@ namespace SharpCompress.Compressors.Deflate public string FileName { - get { return fileName; } + get => fileName; set { if (disposed) diff --git a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs index c6d8d1dc..7051b1f2 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs @@ -98,7 +98,7 @@ namespace SharpCompress.Compressors.Deflate } } - protected internal bool _wantCompress { get { return (_compressionMode == CompressionMode.Compress); } } + protected internal bool _wantCompress => (_compressionMode == CompressionMode.Compress); private ZlibCodec z { @@ -630,15 +630,15 @@ namespace SharpCompress.Compressors.Deflate return rc; } - public override Boolean CanRead { get { return _stream.CanRead; } } + public override Boolean CanRead => _stream.CanRead; - public override Boolean CanSeek { get { return _stream.CanSeek; } } + public override Boolean CanSeek => _stream.CanSeek; - public override Boolean CanWrite { get { return _stream.CanWrite; } } + public override Boolean CanWrite => _stream.CanWrite; - public override Int64 Length { get { return _stream.Length; } } + public override Int64 Length => _stream.Length; - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } internal enum StreamMode { diff --git a/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs b/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs index 5343057f..f2e9339b 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs @@ -171,7 +171,7 @@ namespace SharpCompress.Compressors.Deflate /// /// The Adler32 checksum on the data transferred through the codec so far. You probably don't need to look at this. /// - public int Adler32 { get { return (int)_Adler32; } } + public int Adler32 => (int)_Adler32; /// /// Create a ZlibCodec. diff --git a/src/SharpCompress/Compressors/Deflate/ZlibStream.cs b/src/SharpCompress/Compressors/Deflate/ZlibStream.cs index 9e20bc50..6777c20d 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibStream.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibStream.cs @@ -63,7 +63,7 @@ namespace SharpCompress.Compressors.Deflate /// public virtual FlushType FlushMode { - get { return (_baseStream._flushMode); } + get => (_baseStream._flushMode); set { if (_disposed) @@ -93,7 +93,7 @@ namespace SharpCompress.Compressors.Deflate /// public int BufferSize { - get { return _baseStream._bufferSize; } + get => _baseStream._bufferSize; set { if (_disposed) @@ -115,10 +115,10 @@ namespace SharpCompress.Compressors.Deflate } /// Returns the total number of bytes input so far. - public virtual long TotalIn { get { return _baseStream._z.TotalBytesIn; } } + public virtual long TotalIn => _baseStream._z.TotalBytesIn; /// Returns the total number of bytes output so far. - public virtual long TotalOut { get { return _baseStream._z.TotalBytesOut; } } + public virtual long TotalOut => _baseStream._z.TotalBytesOut; #endregion @@ -148,7 +148,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Always returns false. /// - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; /// /// Indicates whether the stream can be written. @@ -171,7 +171,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Reading this property always throws a . /// - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); /// /// The position of the stream pointer. @@ -199,7 +199,7 @@ namespace SharpCompress.Compressors.Deflate return 0; } - set { throw new NotSupportedException(); } + set => throw new NotSupportedException(); } /// diff --git a/src/SharpCompress/Compressors/Filters/BCJ2Filter.cs b/src/SharpCompress/Compressors/Filters/BCJ2Filter.cs index 86ed1b97..65af71ee 100644 --- a/src/SharpCompress/Compressors/Filters/BCJ2Filter.cs +++ b/src/SharpCompress/Compressors/Filters/BCJ2Filter.cs @@ -78,20 +78,20 @@ namespace SharpCompress.Compressors.Filters baseStream.Dispose(); } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { return baseStream.Length + data1.Length + data2.Length; } } + public override long Length => baseStream.Length + data1.Length + data2.Length; - public override long Position { get { return position; } set { throw new NotSupportedException(); } } + public override long Position { get => position; set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/Filters/Filter.cs b/src/SharpCompress/Compressors/Filters/Filter.cs index d19235ca..c0b23eb1 100644 --- a/src/SharpCompress/Compressors/Filters/Filter.cs +++ b/src/SharpCompress/Compressors/Filters/Filter.cs @@ -34,20 +34,20 @@ namespace SharpCompress.Compressors.Filters baseStream.Dispose(); } - public override bool CanRead { get { return !isEncoder; } } + public override bool CanRead => !isEncoder; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return isEncoder; } } + public override bool CanWrite => isEncoder; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { return baseStream.Length; } } + public override long Length => baseStream.Length; - public override long Position { get { return baseStream.Position; } set { throw new NotSupportedException(); } } + public override long Position { get => baseStream.Position; set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs index b4adab90..c9c6fd21 100644 --- a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs @@ -8,20 +8,20 @@ namespace SharpCompress.Compressors.LZMA { internal abstract class DecoderStream2 : Stream { - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override long Seek(long offset, SeekOrigin origin) { diff --git a/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs b/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs index fa41ed9f..ad8c9170 100644 --- a/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs +++ b/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs @@ -178,6 +178,6 @@ namespace SharpCompress.Compressors.LZMA.LZ _streamPos -= (UInt32)subValue; } - public bool IsDataStarved { get { return _streamPos - _pos < _keepSizeAfter; } } + public bool IsDataStarved => _streamPos - _pos < _keepSizeAfter; } } \ No newline at end of file diff --git a/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs b/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs index d9dbc3d0..1b230873 100644 --- a/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs +++ b/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs @@ -166,9 +166,9 @@ namespace SharpCompress.Compressors.LZMA.LZ Limit = Total + size; } - public bool HasSpace { get { return _pos < _windowSize && Total < Limit; } } + public bool HasSpace => _pos < _windowSize && Total < Limit; - public bool HasPending { get { return _pendingLen > 0; } } + public bool HasPending => _pendingLen > 0; public int Read(byte[] buffer, int offset, int count) { @@ -200,6 +200,6 @@ namespace SharpCompress.Compressors.LZMA.LZ } } - public int AvailableBytes { get { return _pos - _streamPos; } } + public int AvailableBytes => _pos - _streamPos; } } \ No newline at end of file diff --git a/src/SharpCompress/Compressors/LZMA/LZipStream.cs b/src/SharpCompress/Compressors/LZMA/LZipStream.cs index 19b89764..a061d1df 100644 --- a/src/SharpCompress/Compressors/LZMA/LZipStream.cs +++ b/src/SharpCompress/Compressors/LZMA/LZipStream.cs @@ -69,9 +69,9 @@ namespace SharpCompress.Compressors.LZMA // TODO: Both Length and Position are sometimes feasible, but would require // reading the output length when we initialize. - public override long Length { get { throw new NotImplementedException(); } } + public override long Length => throw new NotImplementedException(); - public override long Position { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } + public override long Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public override int Read(byte[] buffer, int offset, int count) => stream.Read(buffer, offset, count); diff --git a/src/SharpCompress/Compressors/LZMA/LzmaStream.cs b/src/SharpCompress/Compressors/LZMA/LzmaStream.cs index 3614b4c8..b2591cde 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaStream.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaStream.cs @@ -118,11 +118,11 @@ namespace SharpCompress.Compressors.LZMA } } - public override bool CanRead { get { return encoder == null; } } + public override bool CanRead => encoder == null; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return encoder != null; } } + public override bool CanWrite => encoder != null; public override void Flush() { @@ -149,9 +149,9 @@ namespace SharpCompress.Compressors.LZMA base.Dispose(disposing); } - public override long Length { get { return position + availableBytes; } } + public override long Length => position + availableBytes; - public override long Position { get { return position; } set { throw new NotSupportedException(); } } + public override long Position { get => position; set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs index 1c3d5ecc..6b6ab41e 100644 --- a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs +++ b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs @@ -245,7 +245,7 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder return symbol; } - public bool IsFinished { get { return Code == 0; } } + public bool IsFinished => Code == 0; // ulong GetProcessedSize() {return Stream.GetProcessedSize(); } } diff --git a/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs b/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs index b93a0181..1da7a723 100644 --- a/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs @@ -40,19 +40,19 @@ namespace SharpCompress.Compressors.LZMA.Utilites return mCRC; } - public override bool CanRead { get { return false; } } + public override bool CanRead => false; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return true; } } + public override bool CanWrite => true; public override void Flush() { } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { @@ -122,20 +122,20 @@ namespace SharpCompress.Compressors.LZMA.Utilites return mCRC; } - public override bool CanRead { get { return mSource.CanRead; } } + public override bool CanRead => mSource.CanRead; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs b/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs index 6f1ca915..f64887e4 100644 --- a/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs +++ b/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs @@ -62,19 +62,19 @@ namespace SharpCompress.Compressors.LZMA.Utilites } } - public override bool CanRead { get { return false; } } + public override bool CanRead => false; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return true; } } + public override bool CanWrite => true; public override void Flush() { } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/PPMd/H/FreqData.cs b/src/SharpCompress/Compressors/PPMd/H/FreqData.cs index e32ec69d..731ed972 100644 --- a/src/SharpCompress/Compressors/PPMd/H/FreqData.cs +++ b/src/SharpCompress/Compressors/PPMd/H/FreqData.cs @@ -19,7 +19,7 @@ namespace SharpCompress.Compressors.PPMd.H { } - internal int SummFreq { get { return DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff; } set { DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value); } } + internal int SummFreq { get => DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff; set => DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value); } internal FreqData Initialize(byte[] mem) { diff --git a/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs b/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs index 0329ab9c..8a754333 100644 --- a/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs +++ b/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs @@ -22,33 +22,33 @@ namespace SharpCompress.Compressors.PPMd.H public SubAllocator SubAlloc { get; } = new SubAllocator(); - public virtual SEE2Context DummySEE2Cont { get { return dummySEE2Cont; } } + public virtual SEE2Context DummySEE2Cont => dummySEE2Cont; - public virtual int InitRL { get { return initRL; } } + public virtual int InitRL => initRL; - public virtual int EscCount { get { return escCount; } set { escCount = value & 0xff; } } + public virtual int EscCount { get => escCount; set => escCount = value & 0xff; } - public virtual int[] CharMask { get { return charMask; } } + public virtual int[] CharMask => charMask; - public virtual int NumMasked { get { return numMasked; } set { numMasked = value; } } + public virtual int NumMasked { get => numMasked; set => numMasked = value; } - public virtual int PrevSuccess { get { return prevSuccess; } set { prevSuccess = value & 0xff; } } + public virtual int PrevSuccess { get => prevSuccess; set => prevSuccess = value & 0xff; } - public virtual int InitEsc { get { return initEsc; } set { initEsc = value; } } + public virtual int InitEsc { get => initEsc; set => initEsc = value; } - public virtual int RunLength { get { return runLength; } set { runLength = value; } } + public virtual int RunLength { get => runLength; set => runLength = value; } - public virtual int HiBitsFlag { get { return hiBitsFlag; } set { hiBitsFlag = value & 0xff; } } + public virtual int HiBitsFlag { get => hiBitsFlag; set => hiBitsFlag = value & 0xff; } - public virtual int[][] BinSumm { get { return binSumm; } } + public virtual int[][] BinSumm => binSumm; internal RangeCoder Coder { get; private set; } internal State FoundState { get; private set; } - public virtual byte[] Heap { get { return SubAlloc.Heap; } } + public virtual byte[] Heap => SubAlloc.Heap; - public virtual int OrderFall { get { return orderFall; } } + public virtual int OrderFall => orderFall; public const int MAX_O = 64; /* maximum allowed model order */ diff --git a/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs b/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs index f3a153aa..e39fa69c 100644 --- a/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs +++ b/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs @@ -8,8 +8,7 @@ namespace SharpCompress.Compressors.PPMd.H { internal FreqData FreqData { - get { return freqData; } - + get => freqData; set { freqData.SummFreq = value.SummFreq; @@ -131,7 +130,7 @@ namespace SharpCompress.Compressors.PPMd.H internal override int Address { - get { return base.Address; } + get => base.Address; set { base.Address = value; diff --git a/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs b/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs index a408e426..4c04828a 100644 --- a/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs +++ b/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs @@ -131,11 +131,11 @@ namespace SharpCompress.Compressors.PPMd.H Scale = Scale + dScale; } - internal long HighCount { get { return highCount; } set { highCount = value & RangeCoder.UintMask; } } + internal long HighCount { get => highCount; set => highCount = value & RangeCoder.UintMask; } - internal long LowCount { get { return lowCount & RangeCoder.UintMask; } set { lowCount = value & RangeCoder.UintMask; } } + internal long LowCount { get => lowCount & RangeCoder.UintMask; set => lowCount = value & RangeCoder.UintMask; } - internal long Scale { get { return scale; } set { scale = value & RangeCoder.UintMask; } } + internal long Scale { get => scale; set => scale = value & RangeCoder.UintMask; } // Debug public override String ToString() diff --git a/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs b/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs index 5cb2aca8..66344c00 100644 --- a/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs +++ b/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs @@ -15,11 +15,11 @@ namespace SharpCompress.Compressors.PPMd.H } } - public virtual int Count { get { return count; } set { count = value & 0xff; } } + public virtual int Count { get => count; set => count = value & 0xff; } - public virtual int Shift { get { return shift; } set { shift = value & 0xff; } } + public virtual int Shift { get => shift; set => shift = value & 0xff; } - public virtual int Summ { get { return summ; } set { summ = value & 0xffff; } } + public virtual int Summ { get => summ; set => summ = value & 0xffff; } public const int size = 4; diff --git a/src/SharpCompress/Compressors/PPMd/H/State.cs b/src/SharpCompress/Compressors/PPMd/H/State.cs index b248f5d8..2771e5b3 100644 --- a/src/SharpCompress/Compressors/PPMd/H/State.cs +++ b/src/SharpCompress/Compressors/PPMd/H/State.cs @@ -13,9 +13,9 @@ namespace SharpCompress.Compressors.PPMd.H { } - internal int Symbol { get { return Memory[Address] & 0xff; } set { Memory[Address] = (byte)value; } } + internal int Symbol { get => Memory[Address] & 0xff; set => Memory[Address] = (byte)value; } - internal int Freq { get { return Memory[Address + 1] & 0xff; } set { Memory[Address + 1] = (byte)value; } } + internal int Freq { get => Memory[Address + 1] & 0xff; set => Memory[Address + 1] = (byte)value; } internal State Initialize(byte[] mem) { diff --git a/src/SharpCompress/Compressors/PPMd/H/StateRef.cs b/src/SharpCompress/Compressors/PPMd/H/StateRef.cs index 83764370..3499bdd8 100644 --- a/src/SharpCompress/Compressors/PPMd/H/StateRef.cs +++ b/src/SharpCompress/Compressors/PPMd/H/StateRef.cs @@ -11,9 +11,9 @@ namespace SharpCompress.Compressors.PPMd.H private int successor; // pointer ppmcontext - internal int Symbol { get { return symbol; } set { symbol = value & 0xff; } } + internal int Symbol { get => symbol; set => symbol = value & 0xff; } - internal int Freq { get { return freq; } set { freq = value & 0xff; } } + internal int Freq { get => freq; set => freq = value & 0xff; } internal State Values { diff --git a/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs b/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs index da74fd96..0918e9a9 100644 --- a/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs +++ b/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs @@ -5,15 +5,15 @@ namespace SharpCompress.Compressors.PPMd.H { internal class SubAllocator { - public virtual int FakeUnitsStart { get { return fakeUnitsStart; } set { fakeUnitsStart = value; } } + public virtual int FakeUnitsStart { get => fakeUnitsStart; set => fakeUnitsStart = value; } - public virtual int HeapEnd { get { return heapEnd; } } + public virtual int HeapEnd => heapEnd; - public virtual int PText { get { return pText; } set { pText = value; } } + public virtual int PText { get => pText; set => pText = value; } - public virtual int UnitsStart { get { return unitsStart; } set { unitsStart = value; } } + public virtual int UnitsStart { get => unitsStart; set => unitsStart = value; } - public virtual byte[] Heap { get { return heap; } } + public virtual byte[] Heap => heap; //UPGRADE_NOTE: Final was removed from the declaration of 'N4 '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" public const int N1 = 4; diff --git a/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs b/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs index c9e9483b..23a08643 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs @@ -48,11 +48,8 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public uint Stamp { - get - { - return Memory[Address] | ((uint)Memory[Address + 1]) << 8 | ((uint)Memory[Address + 2]) << 16 | - ((uint)Memory[Address + 3]) << 24; - } + get => Memory[Address] | ((uint)Memory[Address + 1]) << 8 | ((uint)Memory[Address + 2]) << 16 | + ((uint)Memory[Address + 3]) << 24; set { Memory[Address] = (byte)value; @@ -67,13 +64,9 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public MemoryNode Next { - get - { - return - new MemoryNode( - Memory[Address + 4] | ((uint)Memory[Address + 5]) << 8 | - ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); - } + get => new MemoryNode( + Memory[Address + 4] | ((uint)Memory[Address + 5]) << 8 | + ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); set { Memory[Address + 4] = (byte)value.Address; @@ -88,11 +81,8 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public uint UnitCount { - get - { - return Memory[Address + 8] | ((uint)Memory[Address + 9]) << 8 | - ((uint)Memory[Address + 10]) << 16 | ((uint)Memory[Address + 11]) << 24; - } + get => Memory[Address + 8] | ((uint)Memory[Address + 9]) << 8 | + ((uint)Memory[Address + 10]) << 16 | ((uint)Memory[Address + 11]) << 24; set { Memory[Address + 8] = (byte)value; @@ -105,7 +95,7 @@ namespace SharpCompress.Compressors.PPMd.I1 /// /// Gets whether there is a next memory node available. /// - public bool Available { get { return Next.Address != 0; } } + public bool Available => Next.Address != 0; /// /// Link in the provided memory node. diff --git a/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs b/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs index 8b05e637..371385fe 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs @@ -34,19 +34,19 @@ namespace SharpCompress.Compressors.PPMd.I1 /// /// Gets or sets the number statistics. /// - public byte NumberStatistics { get { return Memory[Address]; } set { Memory[Address] = value; } } + public byte NumberStatistics { get => Memory[Address]; set => Memory[Address] = value; } /// /// Gets or sets the flags. /// - public byte Flags { get { return Memory[Address + 1]; } set { Memory[Address + 1] = value; } } + public byte Flags { get => Memory[Address + 1]; set => Memory[Address + 1] = value; } /// /// Gets or sets the summary frequency. /// public ushort SummaryFrequency { - get { return (ushort)(Memory[Address + 2] | Memory[Address + 3] << 8); } + get => (ushort)(Memory[Address + 2] | Memory[Address + 3] << 8); set { Memory[Address + 2] = (byte)value; @@ -59,13 +59,9 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public PpmState Statistics { - get - { - return - new PpmState( - Memory[Address + 4] | ((uint)Memory[Address + 5]) << 8 | - ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); - } + get => new PpmState( + Memory[Address + 4] | ((uint)Memory[Address + 5]) << 8 | + ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); set { Memory[Address + 4] = (byte)value.Address; @@ -80,13 +76,9 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public PpmContext Suffix { - get - { - return - new PpmContext( - Memory[Address + 8] | ((uint)Memory[Address + 9]) << 8 | - ((uint)Memory[Address + 10]) << 16 | ((uint)Memory[Address + 11]) << 24, Memory); - } + get => new PpmContext( + Memory[Address + 8] | ((uint)Memory[Address + 9]) << 8 | + ((uint)Memory[Address + 10]) << 16 | ((uint)Memory[Address + 11]) << 24, Memory); set { Memory[Address + 8] = (byte)value.Address; @@ -121,21 +113,21 @@ namespace SharpCompress.Compressors.PPMd.I1 /// /// /// - public PpmState FirstState { get { return new PpmState(Address + 2, Memory); } } + public PpmState FirstState => new PpmState(Address + 2, Memory); /// /// Gets or sets the symbol of the first PPM state. This is provided for convenience. The same /// information can be obtained using the Symbol property on the PPM state provided by the /// property. /// - public byte FirstStateSymbol { get { return Memory[Address + 2]; } set { Memory[Address + 2] = value; } } + public byte FirstStateSymbol { get => Memory[Address + 2]; set => Memory[Address + 2] = value; } /// /// Gets or sets the frequency of the first PPM state. This is provided for convenience. The same /// information can be obtained using the Frequency property on the PPM state provided by the ///context.FirstState property. /// - public byte FirstStateFrequency { get { return Memory[Address + 3]; } set { Memory[Address + 3] = value; } } + public byte FirstStateFrequency { get => Memory[Address + 3]; set => Memory[Address + 3] = value; } /// /// Gets or sets the successor of the first PPM state. This is provided for convenience. The same @@ -143,13 +135,9 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public PpmContext FirstStateSuccessor { - get - { - return - new PpmContext( - Memory[Address + 4] | ((uint)Memory[Address + 5]) << 8 | - ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); - } + get => new PpmContext( + Memory[Address + 4] | ((uint)Memory[Address + 5]) << 8 | + ((uint)Memory[Address + 6]) << 16 | ((uint)Memory[Address + 7]) << 24, Memory); set { Memory[Address + 4] = (byte)value.Address; diff --git a/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs b/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs index 584eb389..d6c2d39f 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs @@ -38,25 +38,21 @@ namespace SharpCompress.Compressors.PPMd.I1 /// /// Gets or sets the symbol. /// - public byte Symbol { get { return Memory[Address]; } set { Memory[Address] = value; } } + public byte Symbol { get => Memory[Address]; set => Memory[Address] = value; } /// /// Gets or sets the frequency. /// - public byte Frequency { get { return Memory[Address + 1]; } set { Memory[Address + 1] = value; } } + public byte Frequency { get => Memory[Address + 1]; set => Memory[Address + 1] = value; } /// /// Gets or sets the successor. /// public Model.PpmContext Successor { - get - { - return - new Model.PpmContext( - Memory[Address + 2] | ((uint)Memory[Address + 3]) << 8 | - ((uint)Memory[Address + 4]) << 16 | ((uint)Memory[Address + 5]) << 24, Memory); - } + get => new Model.PpmContext( + Memory[Address + 2] | ((uint)Memory[Address + 3]) << 8 | + ((uint)Memory[Address + 4]) << 16 | ((uint)Memory[Address + 5]) << 24, Memory); set { Memory[Address + 2] = (byte)value.Address; @@ -72,7 +68,7 @@ namespace SharpCompress.Compressors.PPMd.I1 /// /// /// - public PpmState this[int offset] { get { return new PpmState((uint)(Address + offset * Size), Memory); } } + public PpmState this[int offset] => new PpmState((uint)(Address + offset * Size), Memory); /// /// Allow a pointer to be implicitly converted to a PPM state. diff --git a/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs b/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs index 25e90b6e..bd8b43bc 100644 --- a/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs +++ b/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs @@ -48,7 +48,7 @@ namespace SharpCompress.Compressors.PPMd public int AllocatorSize { - get { return allocatorSize; } + get => allocatorSize; set { allocatorSize = value; @@ -63,15 +63,8 @@ namespace SharpCompress.Compressors.PPMd } } - public byte[] Properties - { - get - { - return - DataConverter.LittleEndian.GetBytes( - (ushort) - ((ModelOrder - 1) + (((AllocatorSize >> 20) - 1) << 4) + ((ushort)ModelRestorationMethod << 12))); - } - } + public byte[] Properties => DataConverter.LittleEndian.GetBytes( + (ushort) + ((ModelOrder - 1) + (((AllocatorSize >> 20) - 1) << 4) + ((ushort)ModelRestorationMethod << 12))); } } \ No newline at end of file diff --git a/src/SharpCompress/Compressors/PPMd/PpmdStream.cs b/src/SharpCompress/Compressors/PPMd/PpmdStream.cs index 94e5b596..1169ed52 100644 --- a/src/SharpCompress/Compressors/PPMd/PpmdStream.cs +++ b/src/SharpCompress/Compressors/PPMd/PpmdStream.cs @@ -57,11 +57,11 @@ namespace SharpCompress.Compressors.PPMd } } - public override bool CanRead { get { return !compress; } } + public override bool CanRead => !compress; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return compress; } } + public override bool CanWrite => compress; public override void Flush() { @@ -84,9 +84,9 @@ namespace SharpCompress.Compressors.PPMd base.Dispose(isDisposing); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { return position; } set { throw new NotSupportedException(); } } + public override long Position { get => position; set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/Rar/Decode/AudioVariables.cs b/src/SharpCompress/Compressors/Rar/Decode/AudioVariables.cs index 0189009a..cb70b1fd 100644 --- a/src/SharpCompress/Compressors/Rar/Decode/AudioVariables.cs +++ b/src/SharpCompress/Compressors/Rar/Decode/AudioVariables.cs @@ -7,7 +7,7 @@ namespace SharpCompress.Compressors.Rar.Decode Dif = new int[11]; } - internal int[] Dif { get; private set; } + internal int[] Dif { get; } internal int ByteCount { get; set; } internal int D1 { get; set; } diff --git a/src/SharpCompress/Compressors/Rar/Decode/Decode.cs b/src/SharpCompress/Compressors/Rar/Decode/Decode.cs index 69039ffa..dc5dacee 100644 --- a/src/SharpCompress/Compressors/Rar/Decode/Decode.cs +++ b/src/SharpCompress/Compressors/Rar/Decode/Decode.cs @@ -17,17 +17,17 @@ namespace SharpCompress.Compressors.Rar.Decode /// returns the decode Length array /// decodeLength /// - internal int[] DecodeLen { get; private set; } + internal int[] DecodeLen { get; } /// returns the decode num array /// decodeNum /// - internal int[] DecodeNum { get; private set; } + internal int[] DecodeNum { get; } /// returns the decodePos array /// decodePos /// - internal int[] DecodePos { get; private set; } + internal int[] DecodePos { get; } internal int MaxNum { get; set; } } diff --git a/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs b/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs index 5c221a4f..d5618d5f 100644 --- a/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs +++ b/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs @@ -59,6 +59,8 @@ namespace SharpCompress.Compressors.Rar currentPartTotalReadBytes = 0; + CurrentCrc = filePartEnumerator.Current.FileHeader.FileCRC; + streamListener.FireFilePartExtractionBegin(filePartEnumerator.Current.FilePartName, filePartEnumerator.Current.FileHeader.CompressedSize, filePartEnumerator.Current.FileHeader.UncompressedSize); @@ -113,20 +115,22 @@ namespace SharpCompress.Compressors.Rar return totalRead; } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; + + public uint CurrentCrc { get; private set; } public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override long Seek(long offset, SeekOrigin origin) { diff --git a/src/SharpCompress/Compressors/Rar/RarCRC.cs b/src/SharpCompress/Compressors/Rar/RarCRC.cs index 0bf20009..077b2f46 100644 --- a/src/SharpCompress/Compressors/Rar/RarCRC.cs +++ b/src/SharpCompress/Compressors/Rar/RarCRC.cs @@ -6,6 +6,10 @@ namespace SharpCompress.Compressors.Rar { private static readonly uint[] crcTab; + public static uint CheckCrc(uint startCrc, byte b) { + return (crcTab[((int) ((int) startCrc ^ (int) b)) & 0xff] ^ (startCrc >> 8)); + } + public static uint CheckCrc(uint startCrc, byte[] data, int offset, int count) { int size = Math.Min(data.Length - offset, count); diff --git a/src/SharpCompress/Compressors/Rar/RarCrcStream.cs b/src/SharpCompress/Compressors/Rar/RarCrcStream.cs new file mode 100644 index 00000000..3760d252 --- /dev/null +++ b/src/SharpCompress/Compressors/Rar/RarCrcStream.cs @@ -0,0 +1,42 @@ +using System.IO; +using SharpCompress.Common; +using SharpCompress.Common.Rar.Headers; + +namespace SharpCompress.Compressors.Rar { + internal class RarCrcStream : RarStream { + private readonly MultiVolumeReadOnlyStream readStream; + private uint currentCrc; + + public RarCrcStream(Unpack unpack, FileHeader fileHeader, MultiVolumeReadOnlyStream readStream) : base(unpack, fileHeader, readStream) + { + this.readStream = readStream; + ResetCrc(); + } + + public uint GetCrc() + { + return ~currentCrc; + } + + public void ResetCrc() + { + currentCrc = 0xffffffff; + } + + + public override int Read(byte[] buffer, int offset, int count) + { + var result = base.Read(buffer, offset, count); + if (result != 0) + { + currentCrc = RarCRC.CheckCrc(currentCrc, buffer, offset, result); + } + else if (GetCrc() != readStream.CurrentCrc) + { + // NOTE: we use the last FileHeader in a multipart volume to check CRC + throw new InvalidFormatException("file crc mismatch"); + } + return result; + } + } +} \ No newline at end of file diff --git a/src/SharpCompress/Compressors/Rar/RarStream.cs b/src/SharpCompress/Compressors/Rar/RarStream.cs index f118db02..c36f261c 100644 --- a/src/SharpCompress/Compressors/Rar/RarStream.cs +++ b/src/SharpCompress/Compressors/Rar/RarStream.cs @@ -43,19 +43,19 @@ namespace SharpCompress.Compressors.Rar readStream.Dispose(); } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { } - public override long Length { get { return fileHeader.UncompressedSize; } } + public override long Length => fileHeader.UncompressedSize; - public override long Position { get { return fileHeader.UncompressedSize - unpack.DestSize; } set { throw new NotSupportedException(); } } + public override long Position { get => fileHeader.UncompressedSize - unpack.DestSize; set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/Rar/Unpack.cs b/src/SharpCompress/Compressors/Rar/Unpack.cs index 9e8b4736..197d6e51 100644 --- a/src/SharpCompress/Compressors/Rar/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/Unpack.cs @@ -32,7 +32,7 @@ namespace SharpCompress.Compressors.Rar public long DestSize { - get { return destUnpSize; } + get => destUnpSize; set { destUnpSize = value; @@ -40,7 +40,7 @@ namespace SharpCompress.Compressors.Rar } } - public bool Suspended { set { suspended = value; } } + public bool Suspended { set => suspended = value; } public int Char { diff --git a/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs b/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs index 0b985884..fc3238b5 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs @@ -10,8 +10,8 @@ namespace SharpCompress.Compressors.Rar.VM internal VMCommands OpCode { get; set; } internal bool IsByteMode { get; set; } - internal VMPreparedOperand Op1 { get; private set; } + internal VMPreparedOperand Op1 { get; } - internal VMPreparedOperand Op2 { get; private set; } + internal VMPreparedOperand Op2 { get; } } } \ No newline at end of file diff --git a/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs b/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs index 9a6cba31..a5812ed0 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs @@ -9,10 +9,10 @@ namespace SharpCompress.Compressors.Rar.VM Type = type; } - internal int Length { get; private set; } + internal int Length { get; } - internal uint CRC { get; private set; } + internal uint CRC { get; } - internal VMStandardFilters Type { get; private set; } + internal VMStandardFilters Type { get; } } } \ No newline at end of file diff --git a/src/SharpCompress/Converters/DataConverter.cs b/src/SharpCompress/Converters/DataConverter.cs index 29dca6ec..9ea6953f 100644 --- a/src/SharpCompress/Converters/DataConverter.cs +++ b/src/SharpCompress/Converters/DataConverter.cs @@ -146,9 +146,9 @@ namespace SharpCompress.Converters return ret; } - static public DataConverter LittleEndian { get { return BitConverter.IsLittleEndian ? Native : SwapConv; } } + static public DataConverter LittleEndian => BitConverter.IsLittleEndian ? Native : SwapConv; - static public DataConverter BigEndian { get { return BitConverter.IsLittleEndian ? SwapConv : Native; } } + static public DataConverter BigEndian => BitConverter.IsLittleEndian ? SwapConv : Native; static public DataConverter Native { get; } = new CopyConverter(); diff --git a/src/SharpCompress/Crypto/RijndaelEngine.cs b/src/SharpCompress/Crypto/RijndaelEngine.cs index 7aca7aea..6fa73b4b 100644 --- a/src/SharpCompress/Crypto/RijndaelEngine.cs +++ b/src/SharpCompress/Crypto/RijndaelEngine.cs @@ -577,9 +577,9 @@ namespace Org.BouncyCastle.Crypto.Engines throw new ArgumentException("invalid parameter passed to Rijndael init - " + parameters.GetType()); } - public string AlgorithmName { get { return "Rijndael"; } } + public string AlgorithmName => "Rijndael"; - public bool IsPartialBlockOkay { get { return false; } } + public bool IsPartialBlockOkay => false; public int GetBlockSize() { diff --git a/src/SharpCompress/IO/AppendingStream.cs b/src/SharpCompress/IO/AppendingStream.cs index 3c55bfb4..4a024fb1 100644 --- a/src/SharpCompress/IO/AppendingStream.cs +++ b/src/SharpCompress/IO/AppendingStream.cs @@ -14,20 +14,20 @@ namespace SharpCompress.IO this.streams = new Queue(streams); } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotImplementedException(); } - public override long Length { get { throw new NotImplementedException(); } } + public override long Length => throw new NotImplementedException(); - public override long Position { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } + public override long Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/IO/BufferedSubStream.cs b/src/SharpCompress/IO/BufferedSubStream.cs index f98c1c0b..dd913d49 100644 --- a/src/SharpCompress/IO/BufferedSubStream.cs +++ b/src/SharpCompress/IO/BufferedSubStream.cs @@ -30,20 +30,20 @@ namespace SharpCompress.IO public Stream Stream { get; } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/IO/CountingWritableSubStream.cs b/src/SharpCompress/IO/CountingWritableSubStream.cs index 17313612..f6577177 100644 --- a/src/SharpCompress/IO/CountingWritableSubStream.cs +++ b/src/SharpCompress/IO/CountingWritableSubStream.cs @@ -12,21 +12,21 @@ namespace SharpCompress.IO writableStream = stream; } - public uint Count { get; private set; } + public ulong Count { get; private set; } - public override bool CanRead { get { return false; } } + public override bool CanRead => false; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return true; } } + public override bool CanWrite => true; public override void Flush() { } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/IO/ListeningStream.cs b/src/SharpCompress/IO/ListeningStream.cs index bbec0a96..1cc694e0 100644 --- a/src/SharpCompress/IO/ListeningStream.cs +++ b/src/SharpCompress/IO/ListeningStream.cs @@ -24,20 +24,20 @@ namespace SharpCompress.IO public Stream Stream { get; } - public override bool CanRead { get { return Stream.CanRead; } } + public override bool CanRead => Stream.CanRead; - public override bool CanSeek { get { return Stream.CanSeek; } } + public override bool CanSeek => Stream.CanSeek; - public override bool CanWrite { get { return Stream.CanWrite; } } + public override bool CanWrite => Stream.CanWrite; public override void Flush() { Stream.Flush(); } - public override long Length { get { return Stream.Length; } } + public override long Length => Stream.Length; - public override long Position { get { return Stream.Position; } set { Stream.Position = value; } } + public override long Position { get => Stream.Position; set => Stream.Position = value; } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/IO/MarkingBinaryReader.cs b/src/SharpCompress/IO/MarkingBinaryReader.cs index 6732b9c0..aa7c820b 100644 --- a/src/SharpCompress/IO/MarkingBinaryReader.cs +++ b/src/SharpCompress/IO/MarkingBinaryReader.cs @@ -12,9 +12,9 @@ namespace SharpCompress.IO { } - public long CurrentReadByteCount { get; private set; } + public virtual long CurrentReadByteCount { get; protected set; } - public void Mark() + public virtual void Mark() { CurrentReadByteCount = 0; } diff --git a/src/SharpCompress/IO/NonDisposingStream.cs b/src/SharpCompress/IO/NonDisposingStream.cs index ebd77787..0c5363d1 100644 --- a/src/SharpCompress/IO/NonDisposingStream.cs +++ b/src/SharpCompress/IO/NonDisposingStream.cs @@ -16,20 +16,20 @@ namespace SharpCompress.IO public Stream Stream { get; } - public override bool CanRead { get { return Stream.CanRead; } } + public override bool CanRead => Stream.CanRead; - public override bool CanSeek { get { return Stream.CanSeek; } } + public override bool CanSeek => Stream.CanSeek; - public override bool CanWrite { get { return Stream.CanWrite; } } + public override bool CanWrite => Stream.CanWrite; public override void Flush() { Stream.Flush(); } - public override long Length { get { return Stream.Length; } } + public override long Length => Stream.Length; - public override long Position { get { return Stream.Position; } set { Stream.Position = value; } } + public override long Position { get => Stream.Position; set => Stream.Position = value; } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/IO/ReadOnlySubStream.cs b/src/SharpCompress/IO/ReadOnlySubStream.cs index c9c1df3c..48609526 100644 --- a/src/SharpCompress/IO/ReadOnlySubStream.cs +++ b/src/SharpCompress/IO/ReadOnlySubStream.cs @@ -32,20 +32,20 @@ namespace SharpCompress.IO public Stream Stream { get; } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/IO/RewindableStream.cs b/src/SharpCompress/IO/RewindableStream.cs index f1f58436..f5a8d11f 100644 --- a/src/SharpCompress/IO/RewindableStream.cs +++ b/src/SharpCompress/IO/RewindableStream.cs @@ -68,18 +68,18 @@ namespace SharpCompress.IO IsRecording = true; } - public override bool CanRead { get { return true; } } + public override bool CanRead => true; public override bool CanSeek => stream.CanSeek; - public override bool CanWrite { get { return false; } } + public override bool CanWrite => false; public override void Flush() { throw new NotSupportedException(); } - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); public override long Position { diff --git a/src/SharpCompress/LazyReadOnlyCollection.cs b/src/SharpCompress/LazyReadOnlyCollection.cs index d3e3fff4..ecec3aea 100644 --- a/src/SharpCompress/LazyReadOnlyCollection.cs +++ b/src/SharpCompress/LazyReadOnlyCollection.cs @@ -28,7 +28,7 @@ namespace SharpCompress #region IEnumerator Members - public T Current { get { return lazyReadOnlyCollection.backing[index]; } } + public T Current => lazyReadOnlyCollection.backing[index]; #endregion @@ -46,7 +46,7 @@ namespace SharpCompress #region IEnumerator Members - object IEnumerator.Current { get { return Current; } } + object IEnumerator.Current => Current; public bool MoveNext() { @@ -120,7 +120,7 @@ namespace SharpCompress } } - public bool IsReadOnly { get { return true; } } + public bool IsReadOnly => true; public bool Remove(T item) { diff --git a/src/SharpCompress/ReadOnlyCollection.cs b/src/SharpCompress/ReadOnlyCollection.cs index 7b6f54e9..32c2abc8 100644 --- a/src/SharpCompress/ReadOnlyCollection.cs +++ b/src/SharpCompress/ReadOnlyCollection.cs @@ -33,9 +33,9 @@ namespace SharpCompress collection.CopyTo(array, arrayIndex); } - public int Count { get { return collection.Count; } } + public int Count => collection.Count; - public bool IsReadOnly { get { return true; } } + public bool IsReadOnly => true; public bool Remove(T item) { diff --git a/src/SharpCompress/Readers/AbstractReader.cs b/src/SharpCompress/Readers/AbstractReader.cs index 380e8df5..96fc4e62 100644 --- a/src/SharpCompress/Readers/AbstractReader.cs +++ b/src/SharpCompress/Readers/AbstractReader.cs @@ -16,9 +16,8 @@ namespace SharpCompress.Readers private bool completed; private IEnumerator entriesForCurrentReadStream; private bool wroteCurrentEntry; - - public event EventHandler> EntryExtractionBegin; - public event EventHandler> EntryExtractionEnd; + + public event EventHandler> EntryExtractionProgress; public event EventHandler CompressedBytesRead; public event EventHandler FilePartExtractionBegin; @@ -41,7 +40,7 @@ namespace SharpCompress.Readers /// /// Current file entry /// - public TEntry Entry { get { return entriesForCurrentReadStream.Current; } } + public TEntry Entry => entriesForCurrentReadStream.Current; #region IDisposable Members @@ -179,18 +178,16 @@ namespace SharpCompress.Readers "A writable Stream was required. Use Cancel if that was intended."); } - var streamListener = this as IReaderExtractionListener; - streamListener.FireEntryExtractionBegin(Entry); Write(writableStream); - streamListener.FireEntryExtractionEnd(Entry); wroteCurrentEntry = true; } internal void Write(Stream writeStream) { + var streamListener = this as IReaderExtractionListener; using (Stream s = OpenEntryStream()) { - s.TransferTo(writeStream); + s.TransferTo(writeStream, Entry, streamListener); } } @@ -220,47 +217,29 @@ namespace SharpCompress.Readers #endregion - IEntry IReader.Entry { get { return Entry; } } + IEntry IReader.Entry => Entry; void IExtractionListener.FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes) { - if (CompressedBytesRead != null) + CompressedBytesRead?.Invoke(this, new CompressedBytesReadEventArgs { - CompressedBytesRead(this, new CompressedBytesReadEventArgs - { - CurrentFilePartCompressedBytesRead = currentPartCompressedBytes, - CompressedBytesRead = compressedReadBytes - }); - } + CurrentFilePartCompressedBytesRead = currentPartCompressedBytes, + CompressedBytesRead = compressedReadBytes + }); } void IExtractionListener.FireFilePartExtractionBegin(string name, long size, long compressedSize) { - if (FilePartExtractionBegin != null) + FilePartExtractionBegin?.Invoke(this, new FilePartExtractionBeginEventArgs { - FilePartExtractionBegin(this, new FilePartExtractionBeginEventArgs - { - CompressedSize = compressedSize, - Size = size, - Name = name - }); - } + CompressedSize = compressedSize, + Size = size, + Name = name + }); } - - void IReaderExtractionListener.FireEntryExtractionBegin(Entry entry) + void IReaderExtractionListener.FireEntryExtractionProgress(Entry entry, long bytesTransferred, int iterations) { - if (EntryExtractionBegin != null) - { - EntryExtractionBegin(this, new ReaderExtractionEventArgs(entry)); - } - } - - void IReaderExtractionListener.FireEntryExtractionEnd(Entry entry) - { - if (EntryExtractionEnd != null) - { - EntryExtractionEnd(this, new ReaderExtractionEventArgs(entry)); - } + EntryExtractionProgress?.Invoke(this, new ReaderExtractionEventArgs(entry, new ReaderProgress(entry, bytesTransferred, iterations))); } } } \ No newline at end of file diff --git a/src/SharpCompress/Readers/IReader.cs b/src/SharpCompress/Readers/IReader.cs index 0df03177..db11164d 100644 --- a/src/SharpCompress/Readers/IReader.cs +++ b/src/SharpCompress/Readers/IReader.cs @@ -6,8 +6,7 @@ namespace SharpCompress.Readers { public interface IReader : IDisposable { - event EventHandler> EntryExtractionBegin; - event EventHandler> EntryExtractionEnd; + event EventHandler> EntryExtractionProgress; event EventHandler CompressedBytesRead; event EventHandler FilePartExtractionBegin; diff --git a/src/SharpCompress/Readers/IReaderExtractionListener.cs b/src/SharpCompress/Readers/IReaderExtractionListener.cs index 226b0944..4a4adc4e 100644 --- a/src/SharpCompress/Readers/IReaderExtractionListener.cs +++ b/src/SharpCompress/Readers/IReaderExtractionListener.cs @@ -4,8 +4,6 @@ namespace SharpCompress.Readers { internal interface IReaderExtractionListener : IExtractionListener { - // void EnsureEntriesLoaded(); - void FireEntryExtractionBegin(Entry entry); - void FireEntryExtractionEnd(Entry entry); + void FireEntryExtractionProgress(Entry entry, long sizeTransferred, int iterations); } } \ No newline at end of file diff --git a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs index b3bf672f..7bc61e2e 100644 --- a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs +++ b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs @@ -83,7 +83,7 @@ namespace SharpCompress.Readers.Rar { } - object IEnumerator.Current { get { return Current; } } + object IEnumerator.Current => Current; public bool MoveNext() { diff --git a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs index 63a1c10a..c5f62a44 100644 --- a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs +++ b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs @@ -16,6 +16,6 @@ namespace SharpCompress.Readers.Rar return FileHeader.PackedStream; } - internal override string FilePartName { get { return "Unknown Stream - File Entry: " + FileHeader.FileName; } } + internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; } } \ No newline at end of file diff --git a/src/SharpCompress/Readers/Rar/RarReader.cs b/src/SharpCompress/Readers/Rar/RarReader.cs index 5c1f59d0..92e4d737 100644 --- a/src/SharpCompress/Readers/Rar/RarReader.cs +++ b/src/SharpCompress/Readers/Rar/RarReader.cs @@ -22,7 +22,7 @@ namespace SharpCompress.Readers.Rar internal abstract void ValidateArchive(RarVolume archive); - public override RarVolume Volume { get { return volume; } } + public override RarVolume Volume => volume; #region Open @@ -69,9 +69,9 @@ namespace SharpCompress.Readers.Rar protected override EntryStream GetEntryStream() { - return CreateEntryStream(new RarStream(pack, Entry.FileHeader, + return CreateEntryStream(new RarCrcStream(pack, Entry.FileHeader, new MultiVolumeReadOnlyStream( CreateFilePartEnumerableForCurrentEntry().Cast(), this))); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/Rar/RarReaderEntry.cs b/src/SharpCompress/Readers/Rar/RarReaderEntry.cs index bf2ec4a5..2e29d615 100644 --- a/src/SharpCompress/Readers/Rar/RarReaderEntry.cs +++ b/src/SharpCompress/Readers/Rar/RarReaderEntry.cs @@ -15,20 +15,20 @@ namespace SharpCompress.Readers.Rar internal RarFilePart Part { get; } - internal override IEnumerable Parts { get { return Part.AsEnumerable(); } } + internal override IEnumerable Parts => Part.AsEnumerable(); - internal override FileHeader FileHeader { get { return Part.FileHeader; } } + internal override FileHeader FileHeader => Part.FileHeader; - public override CompressionType CompressionType { get { return CompressionType.Rar; } } + public override CompressionType CompressionType => CompressionType.Rar; /// /// The compressed file size /// - public override long CompressedSize { get { return Part.FileHeader.CompressedSize; } } + public override long CompressedSize => Part.FileHeader.CompressedSize; /// /// The uncompressed file size /// - public override long Size { get { return Part.FileHeader.UncompressedSize; } } + public override long Size => Part.FileHeader.UncompressedSize; } } \ No newline at end of file diff --git a/src/SharpCompress/Readers/ReaderProgress.cs b/src/SharpCompress/Readers/ReaderProgress.cs new file mode 100644 index 00000000..7b6f099d --- /dev/null +++ b/src/SharpCompress/Readers/ReaderProgress.cs @@ -0,0 +1,24 @@ + + +using System; +using SharpCompress.Common; + +namespace SharpCompress.Readers +{ + public class ReaderProgress + { + private readonly IEntry _entry; + public long BytesTransferred { get; } + public int Iterations { get; } + + public int PercentageRead => (int)Math.Round(PercentageReadExact); + public double PercentageReadExact => (float)BytesTransferred / _entry.Size * 100; + + public ReaderProgress(IEntry entry, long bytesTransferred, int iterations) + { + _entry = entry; + BytesTransferred = bytesTransferred; + Iterations = iterations; + } + } +} diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj new file mode 100644 index 00000000..60c2e59a --- /dev/null +++ b/src/SharpCompress/SharpCompress.csproj @@ -0,0 +1,35 @@ + + + + SharpCompress - Pure C# Decompression/Compression + en-US + 0.16.1 + 0.16.1.0 + 0.16.1.0 + Adam Hathcock + net45;net35;netstandard1.0;netstandard1.3 + $(LibraryFrameworks) + true + true + SharpCompress + ../../SharpCompress.snk + true + true + SharpCompress + rar;unrar;zip;unzip;bzip2;gzip;tar;7zip + https://github.com/adamhathcock/sharpcompress + https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt + false + false + SharpCompress is a compression library for NET Standard 1.0 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. + + + + $(DefineConstants);NO_FILE;NO_CRYPTO;SILVERLIGHT + + + + $(DefineConstants);NO_FILE;NO_CRYPTO;SILVERLIGHT + + + diff --git a/src/SharpCompress/SharpCompress.xproj b/src/SharpCompress/SharpCompress.xproj deleted file mode 100644 index 269099f5..00000000 --- a/src/SharpCompress/SharpCompress.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - fd19ddd8-72b2-4024-8665-0d1f7a2aa998 - SharpCompress - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index 451075f3..0486a5fd 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using SharpCompress.Readers; namespace SharpCompress { @@ -231,10 +232,10 @@ namespace SharpCompress public static long TransferTo(this Stream source, Stream destination) { - byte[] array = new byte[81920]; + byte[] array = GetTransferByteArray(); int count; long total = 0; - while ((count = source.Read(array, 0, array.Length)) != 0) + while (ReadTransferBlock(source, array, out count)) { total += count; destination.Write(array, 0, count); @@ -242,6 +243,32 @@ namespace SharpCompress return total; } + public static long TransferTo(this Stream source, Stream destination, Common.Entry entry, IReaderExtractionListener readerExtractionListener) + { + byte[] array = GetTransferByteArray(); + int count; + var iterations = 0; + long total = 0; + while (ReadTransferBlock(source, array, out count)) + { + total += count; + destination.Write(array, 0, count); + iterations++; + readerExtractionListener.FireEntryExtractionProgress(entry, total, iterations); + } + return total; + } + + private static bool ReadTransferBlock(Stream source, byte[] array, out int count) + { + return (count = source.Read(array, 0, array.Length)) != 0; + } + + private static byte[] GetTransferByteArray() + { + return new byte[81920]; + } + public static bool ReadFully(this Stream stream, byte[] buffer) { int total = 0; diff --git a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs index 28b9aa63..fd8f4ba4 100644 --- a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs +++ b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs @@ -13,36 +13,56 @@ namespace SharpCompress.Writers.Zip internal DateTime? ModificationTime { get; set; } internal string Comment { get; set; } internal uint Crc { get; set; } - internal uint HeaderOffset { get; set; } - internal uint Compressed { get; set; } - internal uint Decompressed { get; set; } + internal ulong HeaderOffset { get; set; } + internal ulong Compressed { get; set; } + internal ulong Decompressed { get; set; } + internal ushort Zip64HeaderOffset { get; set; } internal uint Write(Stream outputStream, ZipCompressionMethod compression) { byte[] encodedFilename = Encoding.UTF8.GetBytes(FileName); byte[] encodedComment = Encoding.UTF8.GetBytes(Comment); - //constant sig, then version made by, compabitility, then version to extract - outputStream.Write(new byte[] {80, 75, 1, 2, 0x14, 0, 0x0A, 0}, 0, 8); + var zip64_stream = Compressed >= uint.MaxValue || Decompressed >= uint.MaxValue; + var zip64 = zip64_stream || HeaderOffset >= uint.MaxValue || Zip64HeaderOffset != 0; + + var compressedvalue = zip64 ? uint.MaxValue : (uint)Compressed; + var decompressedvalue = zip64 ? uint.MaxValue : (uint)Decompressed; + var headeroffsetvalue = zip64 ? uint.MaxValue : (uint)HeaderOffset; + var extralength = zip64 ? (2 + 2 + 8 + 8 + 8 + 4) : 0; + var version = (byte)(zip64 ? 45 : 20); // Version 20 required for deflate/encryption + HeaderFlags flags = HeaderFlags.UTF8; if (!outputStream.CanSeek) { - flags |= HeaderFlags.UsePostDataDescriptor; + // Cannot use data descriptors with zip64: + // https://blogs.oracle.com/xuemingshen/entry/is_zipinput_outputstream_handling_of + + // We check that streams are not written too large in the ZipWritingStream, + // so this extra guard is not required, but kept to simplify changing the code + // once the zip64 post-data issue is resolved + if (!zip64_stream) + flags |= HeaderFlags.UsePostDataDescriptor; + if (compression == ZipCompressionMethod.LZMA) { flags |= HeaderFlags.Bit1; // eos marker } } + + //constant sig, then version made by, compabitility, then version to extract + outputStream.Write(new byte[] { 80, 75, 1, 2, 0x14, 0, version, 0 }, 0, 8); + outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)flags), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)compression), 0, 2); // zipping method outputStream.Write(DataConverter.LittleEndian.GetBytes(ModificationTime.DateTimeToDosTime()), 0, 4); // zipping date and time outputStream.Write(DataConverter.LittleEndian.GetBytes(Crc), 0, 4); // file CRC - outputStream.Write(DataConverter.LittleEndian.GetBytes(Compressed), 0, 4); // compressed file size - outputStream.Write(DataConverter.LittleEndian.GetBytes(Decompressed), 0, 4); // uncompressed file size + outputStream.Write(DataConverter.LittleEndian.GetBytes(compressedvalue), 0, 4); // compressed file size + outputStream.Write(DataConverter.LittleEndian.GetBytes(decompressedvalue), 0, 4); // uncompressed file size outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedFilename.Length), 0, 2); // Filename in zip - outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // extra length + outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)extralength), 0, 2); // extra length outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedComment.Length), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // disk=0 @@ -51,13 +71,24 @@ namespace SharpCompress.Writers.Zip outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0x8100), 0, 2); // External file attributes (normal/readable) - outputStream.Write(DataConverter.LittleEndian.GetBytes(HeaderOffset), 0, 4); // Offset of header + outputStream.Write(DataConverter.LittleEndian.GetBytes(headeroffsetvalue), 0, 4); // Offset of header outputStream.Write(encodedFilename, 0, encodedFilename.Length); + if (zip64) + { + outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0x0001), 0, 2); + outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)(extralength - 4)), 0, 2); + + outputStream.Write(DataConverter.LittleEndian.GetBytes(Decompressed), 0, 8); + outputStream.Write(DataConverter.LittleEndian.GetBytes(Compressed), 0, 8); + outputStream.Write(DataConverter.LittleEndian.GetBytes(HeaderOffset), 0, 8); + outputStream.Write(DataConverter.LittleEndian.GetBytes(0), 0, 4); // VolumeNumber = 0 + } + outputStream.Write(encodedComment, 0, encodedComment.Length); return (uint)(8 + 2 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 2 - + 2 + 2 + 2 + 2 + 4 + encodedFilename.Length + encodedComment.Length); + + 2 + 2 + 2 + 2 + 4 + encodedFilename.Length + extralength + encodedComment.Length); } } } \ No newline at end of file diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index d89294b5..1f5908b1 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -23,11 +23,13 @@ namespace SharpCompress.Writers.Zip private readonly string zipComment; private long streamPosition; private PpmdProperties ppmdProps; + private readonly bool isZip64; public ZipWriter(Stream destination, ZipWriterOptions zipWriterOptions) : base(ArchiveType.Zip) { zipComment = zipWriterOptions.ArchiveComment ?? string.Empty; + isZip64 = zipWriterOptions.UseZip64; compressionType = zipWriterOptions.CompressionType; compressionLevel = zipWriterOptions.DeflateCompressionLevel; @@ -50,7 +52,7 @@ namespace SharpCompress.Writers.Zip { if (isDisposing) { - uint size = 0; + ulong size = 0; foreach (ZipCentralDirectoryEntry entry in entries) { size += entry.Write(OutputStream, ToZipCompressionMethod(compressionType)); @@ -114,10 +116,15 @@ namespace SharpCompress.Writers.Zip Comment = options.EntryComment, FileName = entryPath, ModificationTime = options.ModificationDateTime, - HeaderOffset = (uint)streamPosition - }; + HeaderOffset = (ulong)streamPosition + }; - var headersize = (uint)WriteHeader(entryPath, options); + // Use the archive default setting for zip64 and allow overrides + var useZip64 = isZip64; + if (options.EnableZip64.HasValue) + useZip64 = options.EnableZip64.Value; + + var headersize = (uint)WriteHeader(entryPath, options, entry, useZip64); streamPosition += headersize; return new ZipWritingStream(this, OutputStream, entry, ToZipCompressionMethod(options.CompressionType ?? compressionType), @@ -137,24 +144,32 @@ namespace SharpCompress.Writers.Zip return filename.Trim('/'); } - private int WriteHeader(string filename, ZipWriterEntryOptions zipWriterEntryOptions) + private int WriteHeader(string filename, ZipWriterEntryOptions zipWriterEntryOptions, ZipCentralDirectoryEntry entry, bool useZip64) { + // We err on the side of caution until the zip specification clarifies how to support this + if (!OutputStream.CanSeek && useZip64) + throw new NotSupportedException("Zip64 extensions are not supported on non-seekable streams"); + var explicitZipCompressionInfo = ToZipCompressionMethod(zipWriterEntryOptions.CompressionType ?? compressionType); byte[] encodedFilename = ArchiveEncoding.Default.GetBytes(filename); OutputStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.ENTRY_HEADER_BYTES), 0, 4); if (explicitZipCompressionInfo == ZipCompressionMethod.Deflate) { - OutputStream.Write(new byte[] {20, 0}, 0, 2); //older version which is more compatible + if (OutputStream.CanSeek && useZip64) + OutputStream.Write(new byte[] { 45, 0 }, 0, 2); //smallest allowed version for zip64 + else + OutputStream.Write(new byte[] { 20, 0 }, 0, 2); //older version which is more compatible } else { - OutputStream.Write(new byte[] {63, 0}, 0, 2); //version says we used PPMd or LZMA + OutputStream.Write(new byte[] { 63, 0 }, 0, 2); //version says we used PPMd or LZMA } HeaderFlags flags = ArchiveEncoding.Default == Encoding.UTF8 ? HeaderFlags.UTF8 : 0; if (!OutputStream.CanSeek) { flags |= HeaderFlags.UsePostDataDescriptor; + if (explicitZipCompressionInfo == ZipCompressionMethod.LZMA) { flags |= HeaderFlags.Bit1; // eos marker @@ -165,14 +180,25 @@ namespace SharpCompress.Writers.Zip OutputStream.Write(DataConverter.LittleEndian.GetBytes(zipWriterEntryOptions.ModificationDateTime.DateTimeToDosTime()), 0, 4); // zipping date and time - OutputStream.Write(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 12); + OutputStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 12); // unused CRC, un/compressed size, updated later OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedFilename.Length), 0, 2); // filename length - OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // extra length + + var extralength = 0; + if (OutputStream.CanSeek && useZip64) + extralength = 2 + 2 + 8 + 8; + + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)extralength), 0, 2); // extra length OutputStream.Write(encodedFilename, 0, encodedFilename.Length); - return 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length; + if (extralength != 0) + { + OutputStream.Write(new byte[extralength], 0, extralength); // reserve space for zip64 data + entry.Zip64HeaderOffset = (ushort)(6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length); + } + + return 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length + extralength; } private void WriteFooter(uint crc, uint compressed, uint uncompressed) @@ -182,15 +208,58 @@ namespace SharpCompress.Writers.Zip OutputStream.Write(DataConverter.LittleEndian.GetBytes(uncompressed), 0, 4); } - private void WriteEndRecord(uint size) + private void WritePostdataDescriptor(uint crc, ulong compressed, ulong uncompressed) + { + OutputStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4); + OutputStream.Write(DataConverter.LittleEndian.GetBytes(crc), 0, 4); + OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)compressed), 0, 4); + OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)uncompressed), 0, 4); + } + + private void WriteEndRecord(ulong size) { byte[] encodedComment = ArchiveEncoding.Default.GetBytes(zipComment); + var zip64 = isZip64 || entries.Count > ushort.MaxValue || streamPosition >= uint.MaxValue || size >= uint.MaxValue; + var sizevalue = size >= uint.MaxValue ? uint.MaxValue : (uint)size; + var streampositionvalue = streamPosition >= uint.MaxValue ? uint.MaxValue : (uint)streamPosition; + + if (zip64) + { + var recordlen = 2 + 2 + 4 + 4 + 8 + 8 + 8 + 8; + + // Write zip64 end of central directory record + OutputStream.Write(new byte[] { 80, 75, 6, 6 }, 0, 4); + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ulong)recordlen), 0, 8); // Size of zip64 end of central directory record + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // Made by + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)45), 0, 2); // Version needed + + OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)0), 0, 4); // Disk number + OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)0), 0, 4); // Central dir disk + + // TODO: entries.Count is int, so max 2^31 files + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ulong)entries.Count), 0, 8); // Entries in this disk + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ulong)entries.Count), 0, 8); // Total entries + OutputStream.Write(DataConverter.LittleEndian.GetBytes(size), 0, 8); // Central Directory size + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ulong)streamPosition), 0, 8); // Disk offset + + // Write zip64 end of central directory locator + OutputStream.Write(new byte[] { 80, 75, 6, 7 }, 0, 4); + + OutputStream.Write(DataConverter.LittleEndian.GetBytes(0uL), 0, 4); // Entry disk + OutputStream.Write(DataConverter.LittleEndian.GetBytes((ulong)streamPosition + size), 0, 8); // Offset to the zip64 central directory + OutputStream.Write(DataConverter.LittleEndian.GetBytes(0u), 0, 4); // Number of disks + + streamPosition += recordlen + (4 + 4 + 8 + 4); + streampositionvalue = streamPosition >= uint.MaxValue ? uint.MaxValue : (uint)streampositionvalue; + } + + // Write normal end of central directory record OutputStream.Write(new byte[] {80, 75, 5, 6, 0, 0, 0, 0}, 0, 8); OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)entries.Count), 0, 2); OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)entries.Count), 0, 2); - OutputStream.Write(DataConverter.LittleEndian.GetBytes(size), 0, 4); - OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)streamPosition), 0, 4); + OutputStream.Write(DataConverter.LittleEndian.GetBytes(sizevalue), 0, 4); + OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint)streampositionvalue), 0, 4); OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedComment.Length), 0, 2); OutputStream.Write(encodedComment, 0, encodedComment.Length); } @@ -207,7 +276,10 @@ namespace SharpCompress.Writers.Zip private readonly ZipCompressionMethod zipCompressionMethod; private readonly CompressionLevel compressionLevel; private CountingWritableSubStream counting; - private uint decompressed; + private ulong decompressed; + + // Flag to prevent throwing exceptions on Dispose + private bool limitsExceeded; internal ZipWritingStream(ZipWriter writer, Stream originalStream, ZipCentralDirectoryEntry entry, ZipCompressionMethod zipCompressionMethod, CompressionLevel compressionLevel) @@ -221,15 +293,15 @@ namespace SharpCompress.Writers.Zip writeStream = GetWriteStream(originalStream); } - public override bool CanRead { get { return false; } } + public override bool CanRead => false; - public override bool CanSeek { get { return false; } } + public override bool CanSeek => false; - public override bool CanWrite { get { return true; } } + public override bool CanWrite => true; - public override long Length { get { throw new NotSupportedException(); } } + public override long Length => throw new NotSupportedException(); - public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } + public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } private Stream GetWriteStream(Stream writeStream) { @@ -280,23 +352,69 @@ namespace SharpCompress.Writers.Zip if (disposing) { writeStream.Dispose(); + + if (limitsExceeded) + { + // We have written invalid data into the archive, + // so we destroy it now, instead of allowing the user to continue + // with a defunct archive + originalStream.Dispose(); + return; + } + entry.Crc = (uint)crc.Crc32Result; entry.Compressed = counting.Count; entry.Decompressed = decompressed; + + var zip64 = entry.Compressed >= uint.MaxValue || entry.Decompressed >= uint.MaxValue; + var compressedvalue = zip64 ? uint.MaxValue : (uint)counting.Count; + var decompressedvalue = zip64 ? uint.MaxValue : (uint)entry.Decompressed; + if (originalStream.CanSeek) { - originalStream.Position = entry.HeaderOffset + 6; + originalStream.Position = (long)(entry.HeaderOffset + 6); originalStream.WriteByte(0); - originalStream.Position = entry.HeaderOffset + 14; - writer.WriteFooter(entry.Crc, counting.Count, decompressed); - originalStream.Position = writer.streamPosition + entry.Compressed; - writer.streamPosition += entry.Compressed; + + originalStream.Position = (long)(entry.HeaderOffset + 14); + + writer.WriteFooter(entry.Crc, compressedvalue, decompressedvalue); + + // Ideally, we should not throw from Dispose() + // We should not get here as the Write call checks the limits + if (zip64 && entry.Zip64HeaderOffset == 0) + throw new NotSupportedException("Attempted to write a stream that is larger than 4GiB without setting the zip64 option"); + + // If we have pre-allocated space for zip64 data, + // fill it out, even if it is not required + if (entry.Zip64HeaderOffset != 0) + { + originalStream.Position = (long)(entry.HeaderOffset + entry.Zip64HeaderOffset); + originalStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0x0001), 0, 2); + originalStream.Write(DataConverter.LittleEndian.GetBytes((ushort)(8 + 8)), 0, 2); + + originalStream.Write(DataConverter.LittleEndian.GetBytes(entry.Decompressed), 0, 8); + originalStream.Write(DataConverter.LittleEndian.GetBytes(entry.Compressed), 0, 8); + } + + originalStream.Position = writer.streamPosition + (long)entry.Compressed; + writer.streamPosition += (long)entry.Compressed; } else { - originalStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4); - writer.WriteFooter(entry.Crc, counting.Count, decompressed); - writer.streamPosition += entry.Compressed + 16; + // We have a streaming archive, so we should add a post-data-descriptor, + // but we cannot as it does not hold the zip64 values + // Throwing an exception until the zip specification is clarified + + // Ideally, we should not throw from Dispose() + // We should not get here as the Write call checks the limits + if (zip64) + throw new NotSupportedException("Streams larger than 4GiB are not supported for non-seekable streams"); + + originalStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4); + writer.WriteFooter(entry.Crc, + (uint)compressedvalue, + (uint)decompressedvalue); + writer.streamPosition += (long)entry.Compressed + 16; } writer.entries.Add(entry); } @@ -324,9 +442,33 @@ namespace SharpCompress.Writers.Zip public override void Write(byte[] buffer, int offset, int count) { + // We check the limits first, because we can keep the archive consistent + // if we can prevent the writes from happening + if (entry.Zip64HeaderOffset == 0) + { + // Pre-check, the counting.Count is not exact, as we do not know the size before having actually compressed it + if (limitsExceeded || ((decompressed + (uint)count) > uint.MaxValue) || (counting.Count + (uint)count) > uint.MaxValue) + throw new NotSupportedException("Attempted to write a stream that is larger than 4GiB without setting the zip64 option"); + } + decompressed += (uint)count; crc.SlurpBlock(buffer, offset, count); writeStream.Write(buffer, offset, count); + + if (entry.Zip64HeaderOffset == 0) + { + // Post-check, this is accurate + if ((decompressed > uint.MaxValue) || counting.Count > uint.MaxValue) + { + // We have written the data, so the archive is now broken + // Throwing the exception here, allows us to avoid + // throwing an exception in Dispose() which is discouraged + // as it can mask other errors + limitsExceeded = true; + throw new NotSupportedException("Attempted to write a stream that is larger than 4GiB without setting the zip64 option"); + } + } + } } diff --git a/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs b/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs index 81f1d1c0..5f1d8152 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs @@ -15,5 +15,13 @@ namespace SharpCompress.Writers.Zip public string EntryComment { get; set; } public DateTime? ModificationDateTime { get; set; } + + /// + /// Allocate an extra 20 bytes for this entry to store, + /// 64 bit length values, thus enabling streams + /// larger than 4GiB. + /// This option is not supported with non-seekable streams. + /// + public bool? EnableZip64 { get; set; } } } \ No newline at end of file diff --git a/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs b/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs index 662a50d4..81c2afbe 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs @@ -15,6 +15,8 @@ namespace SharpCompress.Writers.Zip : base(options.CompressionType) { LeaveStreamOpen = options.LeaveStreamOpen; + if (options is ZipWriterOptions) + UseZip64 = ((ZipWriterOptions)options).UseZip64; } /// /// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default. @@ -22,5 +24,14 @@ namespace SharpCompress.Writers.Zip public CompressionLevel DeflateCompressionLevel { get; set; } = CompressionLevel.Default; public string ArchiveComment { get; set; } + + /// + /// Sets a value indicating if zip64 support is enabled. + /// If this is not set, individual stream lengths cannot exceed 4 GiB. + /// This option is not supported for non-seekable streams. + /// Archives larger than 4GiB are supported as long as all streams + /// are less than 4GiB in length. + /// + public bool UseZip64 { get; set; } } } \ No newline at end of file diff --git a/src/SharpCompress/project.json b/src/SharpCompress/project.json deleted file mode 100644 index 58344cdc..00000000 --- a/src/SharpCompress/project.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "version": "0.15.2", - "title": "SharpCompress - Pure C# Decompression/Compression", - "authors": [ "Adam Hathcock" ], - "language": "en-US", - "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 - }, - "buildOptions": { - "warningsAsErrors": true, - "allowUnsafe": true, - "keyFile": "../../SharpCompress.snk" - }, - "frameworks": { - "net35": { - }, - "net40": { - }, - "net45": { - }, - ".NETPortable,Version=v4.0,Profile=Profile328": { - "buildOptions": { - "define": [ "NO_FILE", "NO_CRYPTO", "SILVERLIGHT" ] - }, - "frameworkAssemblies": { - "mscorlib": { "type": "build" }, - "System": { "type": "build" }, - "System.Core": { "type": "build" } - } - }, - ".NETPortable,Version=v4.5,Profile=Profile259": { - "buildOptions": { - "define": [ "NO_FILE", "NO_CRYPTO", "SILVERLIGHT" ] - }, - "frameworkAssemblies": { - "System": { "type": "build" }, - "System.Collections": { "type": "build" }, - "System.Core": { "type": "build" }, - "System.Diagnostics.Debug": { "type": "build" }, - "System.IO": { "type": "build" }, - "System.Linq": { "type": "build" }, - "System.Linq.Expressions": { "type": "build" }, - "System.Resources.ResourceManager": { "type": "build" }, - "System.Runtime": { "type": "build" }, - "System.Runtime.Extensions": { "type": "build" }, - "System.Text.Encoding": { "type": "build" } - } - }, - "netstandard1.0": { - "buildOptions": { - "define": [ "NO_FILE", "NO_CRYPTO" ] - }, - "dependencies": { - "System.Collections": "4.0.11", - "System.Diagnostics.Debug": "4.0.11", - "System.IO": "4.1.0", - "System.Linq": "4.1.0", - "System.Resources.ResourceManager": "4.0.1", - "System.Runtime.Extensions": "4.1.0", - "System.Text.Encoding.Extensions": "4.0.11" - } - }, - "netstandard1.3": { - "dependencies": { - "System.Collections": "4.0.11", - "System.Diagnostics.Debug": "4.0.11", - "System.IO": "4.1.0", - "System.IO.FileSystem": "4.0.1", - "System.Linq": "4.1.0", - "System.Resources.ResourceManager": "4.0.1", - "System.Runtime.Extensions": "4.1.0", - "System.Security.Cryptography.Algorithms": "4.2.0", - "System.Text.Encoding.Extensions": "4.0.11" - } - } - } -} diff --git a/test/SharpCompress.Test/SharpCompress.Test.xproj b/test/SharpCompress.Test/SharpCompress.Test.xproj deleted file mode 100644 index 707a4032..00000000 --- a/test/SharpCompress.Test/SharpCompress.Test.xproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 3b80e585-a2f3-4666-8f69-c7ffda0dd7e5 - SharpCompress.Test - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - - - - \ No newline at end of file diff --git a/test/SharpCompress.Test/project.json b/test/SharpCompress.Test/project.json deleted file mode 100644 index 0315281d..00000000 --- a/test/SharpCompress.Test/project.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "buildOptions": { - "keyFile": "../../SharpCompress.snk" - }, - - "testRunner": "xunit", - - "frameworks": { - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.1" - } - } - } - }, - "dependencies": { - "Microsoft.Extensions.PlatformAbstractions": "1.0.0", - "SharpCompress": { "target" : "project"}, - "xunit": "2.2.0-beta2-build3300", - "dotnet-test-xunit": "2.2.0-preview2-build1029" - } -} diff --git a/test/SharpCompress.Test/ADCTest.cs b/tests/SharpCompress.Test/ADCTest.cs similarity index 100% rename from test/SharpCompress.Test/ADCTest.cs rename to tests/SharpCompress.Test/ADCTest.cs diff --git a/test/SharpCompress.Test/ArchiveTests.cs b/tests/SharpCompress.Test/ArchiveTests.cs similarity index 88% rename from test/SharpCompress.Test/ArchiveTests.cs rename to tests/SharpCompress.Test/ArchiveTests.cs index f5ddf543..b6d63c9f 100644 --- a/test/SharpCompress.Test/ArchiveTests.cs +++ b/tests/SharpCompress.Test/ArchiveTests.cs @@ -95,9 +95,9 @@ namespace SharpCompress.Test ResetScratch(); using (var archive = ArchiveFactory.Open(path)) { - archive.EntryExtractionBegin += archive_EntryExtractionBegin; - archive.FilePartExtractionBegin += archive_FilePartExtractionBegin; - archive.CompressedBytesRead += archive_CompressedBytesRead; + //archive.EntryExtractionBegin += archive_EntryExtractionBegin; + //archive.FilePartExtractionBegin += archive_FilePartExtractionBegin; + //archive.CompressedBytesRead += archive_CompressedBytesRead; foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { @@ -126,13 +126,13 @@ namespace SharpCompress.Test void archive_FilePartExtractionBegin(object sender, FilePartExtractionBeginEventArgs e) { - this.partTotal = e.Size; + partTotal = e.Size; Console.WriteLine("Initializing File Part Extraction: " + e.Name); } void archive_EntryExtractionBegin(object sender, ArchiveExtractionEventArgs e) { - this.entryTotal = e.Item.Size; + entryTotal = e.Item.Size; Console.WriteLine("Initializing File Entry Extraction: " + e.Item.Key); } @@ -156,10 +156,10 @@ namespace SharpCompress.Test ResetScratch(); using (var archive = ArchiveFactory.Open(path)) { - this.totalSize = archive.TotalUncompressSize; - archive.EntryExtractionBegin += Archive_EntryExtractionBeginEx; - archive.EntryExtractionEnd += Archive_EntryExtractionEndEx; - archive.CompressedBytesRead += Archive_CompressedBytesReadEx; + totalSize = archive.TotalUncompressSize; + //archive.EntryExtractionBegin += Archive_EntryExtractionBeginEx; + //archive.EntryExtractionEnd += Archive_EntryExtractionEndEx; + //archive.CompressedBytesRead += Archive_CompressedBytesReadEx; foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { @@ -179,19 +179,19 @@ namespace SharpCompress.Test private void Archive_EntryExtractionEndEx(object sender, ArchiveExtractionEventArgs e) { - this.partTotal += e.Item.Size; + partTotal += e.Item.Size; } private void Archive_CompressedBytesReadEx(object sender, CompressedBytesReadEventArgs e) { - string percentage = this.entryTotal.HasValue ? this.CreatePercentage(e.CompressedBytesRead, this.entryTotal.Value).ToString() : "-"; - string tortalPercentage = this.CreatePercentage(this.partTotal + e.CompressedBytesRead, this.totalSize).ToString(); + string percentage = entryTotal.HasValue ? CreatePercentage(e.CompressedBytesRead, entryTotal.Value).ToString() : "-"; + string tortalPercentage = CreatePercentage(partTotal + e.CompressedBytesRead, totalSize).ToString(); Console.WriteLine(@"Read Compressed File Progress: {0}% Total Progress {1}%", percentage, tortalPercentage); } private void Archive_EntryExtractionBeginEx(object sender, ArchiveExtractionEventArgs e) { - this.entryTotal = e.Item.Size; + entryTotal = e.Item.Size; } private int CreatePercentage(long n, long d) diff --git a/test/SharpCompress.Test/ForwardOnlyStream.cs b/tests/SharpCompress.Test/ForwardOnlyStream.cs similarity index 85% rename from test/SharpCompress.Test/ForwardOnlyStream.cs rename to tests/SharpCompress.Test/ForwardOnlyStream.cs index 53f4a99a..d9cf85e3 100644 --- a/test/SharpCompress.Test/ForwardOnlyStream.cs +++ b/tests/SharpCompress.Test/ForwardOnlyStream.cs @@ -31,15 +31,12 @@ namespace SharpCompress.Test throw new NotSupportedException(); } - public override long Length - { - get { throw new NotSupportedException(); } - } + public override long Length => throw new NotSupportedException(); public override long Position { - get { throw new NotSupportedException(); } - set { throw new NotSupportedException(); } + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) diff --git a/test/SharpCompress.Test/GZip/GZipArchiveTests.cs b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs similarity index 96% rename from test/SharpCompress.Test/GZip/GZipArchiveTests.cs rename to tests/SharpCompress.Test/GZip/GZipArchiveTests.cs index 64d71d09..ce8c98f9 100644 --- a/test/SharpCompress.Test/GZip/GZipArchiveTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs @@ -5,7 +5,7 @@ using SharpCompress.Archives; using SharpCompress.Archives.GZip; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.GZip { public class GZipArchiveTests : ArchiveTests { @@ -86,7 +86,7 @@ namespace SharpCompress.Test Assert.Equal(size, tarStream.Length); using (var entryStream = archiveEntry.OpenEntryStream()) { - var result = SharpCompress.Archives.Tar.TarArchive.IsTarFile(entryStream); + var result = Archives.Tar.TarArchive.IsTarFile(entryStream); } Assert.Equal(size, tarStream.Length); using (var entryStream = archiveEntry.OpenEntryStream()) diff --git a/test/SharpCompress.Test/GZip/GZipWriterTests.cs b/tests/SharpCompress.Test/GZip/GZipWriterTests.cs similarity index 98% rename from test/SharpCompress.Test/GZip/GZipWriterTests.cs rename to tests/SharpCompress.Test/GZip/GZipWriterTests.cs index 368d8452..cbcf1d6a 100644 --- a/test/SharpCompress.Test/GZip/GZipWriterTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipWriterTests.cs @@ -4,7 +4,7 @@ using SharpCompress.Writers; using SharpCompress.Writers.GZip; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.GZip { public class GZipWriterTests : WriterTests { diff --git a/test/SharpCompress.Test/Rar/RarArchiveTests.cs b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs similarity index 98% rename from test/SharpCompress.Test/Rar/RarArchiveTests.cs rename to tests/SharpCompress.Test/Rar/RarArchiveTests.cs index aba37b87..87ac25b1 100644 --- a/test/SharpCompress.Test/Rar/RarArchiveTests.cs +++ b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs @@ -6,7 +6,7 @@ using SharpCompress.Common; using SharpCompress.Readers; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Rar { public class RarArchiveTests : ArchiveTests { @@ -44,7 +44,7 @@ namespace SharpCompress.Test { if (!entry.IsDirectory) { - Assert.Equal(entry.CompressionType, CompressionType.Rar); + Assert.Equal(CompressionType.Rar, entry.CompressionType); entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, @@ -189,7 +189,7 @@ namespace SharpCompress.Test ResetScratch(); using (var archive = RarArchive.Open(testArchives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) - .Select(p => File.OpenRead(p)))) + .Select(File.OpenRead))) { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { diff --git a/test/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs similarity index 96% rename from test/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs rename to tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs index 99ed66ea..0a5908d3 100644 --- a/test/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs +++ b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs @@ -11,7 +11,7 @@ namespace SharpCompress.Test.Rar /// public class RarHeaderFactoryTest : TestBase { - private RarHeaderFactory rarHeaderFactory; + private readonly RarHeaderFactory rarHeaderFactory; public RarHeaderFactoryTest() { diff --git a/test/SharpCompress.Test/Rar/RarReaderTests.cs b/tests/SharpCompress.Test/Rar/RarReaderTests.cs similarity index 79% rename from test/SharpCompress.Test/Rar/RarReaderTests.cs rename to tests/SharpCompress.Test/Rar/RarReaderTests.cs index 912692ec..9dc0f24a 100644 --- a/test/SharpCompress.Test/Rar/RarReaderTests.cs +++ b/tests/SharpCompress.Test/Rar/RarReaderTests.cs @@ -5,7 +5,7 @@ using SharpCompress.Readers; using SharpCompress.Readers.Rar; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Rar { public class RarReaderTests : ReaderTests { @@ -36,7 +36,7 @@ namespace SharpCompress.Test VerifyFiles(); } - //[Fact] + [Fact] public void Rar_Multi_Reader_Encrypted() { var testArchives = new string[] { "EncryptedParts.part01.rar", @@ -47,20 +47,28 @@ namespace SharpCompress.Test "EncryptedParts.part06.rar"}; - ResetScratch(); - using (var reader = RarReader.Open(testArchives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) - .Select(p => File.OpenRead(p)))) - { - while (reader.MoveToNextEntry()) - { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); - } - } - VerifyFiles(); + Assert.Throws(() => + { + ResetScratch(); + using (var reader = RarReader.Open(testArchives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) + .Select(p => File.OpenRead(p)), + new ReaderOptions() + { + Password = "test" + })) + { + while (reader.MoveToNextEntry()) + { + reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, + new ExtractionOptions() + { + ExtractFullPath = true, + Overwrite = true + }); + } + } + VerifyFiles(); + }); } [Fact] @@ -149,7 +157,7 @@ namespace SharpCompress.Test { if (!reader.Entry.IsDirectory) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.Rar); + Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, @@ -172,7 +180,7 @@ namespace SharpCompress.Test { if (!reader.Entry.IsDirectory) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.Rar); + Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); using (var entryStream = reader.OpenEntryStream()) { string file = Path.GetFileName(reader.Entry.Key); @@ -207,7 +215,7 @@ namespace SharpCompress.Test { while (reader.MoveToNextEntry()) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.Rar); + Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, @@ -231,7 +239,7 @@ namespace SharpCompress.Test { while (reader.MoveToNextEntry()) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.Rar); + Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, @@ -262,7 +270,7 @@ namespace SharpCompress.Test { if (reader.Entry.Key.Contains("jpg")) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.Rar); + Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, @@ -287,7 +295,7 @@ namespace SharpCompress.Test { if (reader.Entry.Key.Contains("jpg")) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.Rar); + Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, diff --git a/test/SharpCompress.Test/ReaderTests.cs b/tests/SharpCompress.Test/ReaderTests.cs similarity index 100% rename from test/SharpCompress.Test/ReaderTests.cs rename to tests/SharpCompress.Test/ReaderTests.cs diff --git a/test/SharpCompress.Test/RewindableStreamTest.cs b/tests/SharpCompress.Test/RewindableStreamTest.cs similarity index 53% rename from test/SharpCompress.Test/RewindableStreamTest.cs rename to tests/SharpCompress.Test/RewindableStreamTest.cs index 991b1acf..52c58227 100644 --- a/test/SharpCompress.Test/RewindableStreamTest.cs +++ b/tests/SharpCompress.Test/RewindableStreamTest.cs @@ -23,25 +23,25 @@ namespace SharpCompress.Test RewindableStream stream = new RewindableStream(ms); stream.StartRecording(); BinaryReader br = new BinaryReader(stream); - Assert.Equal(br.ReadInt32(), 1); - Assert.Equal(br.ReadInt32(), 2); - Assert.Equal(br.ReadInt32(), 3); - Assert.Equal(br.ReadInt32(), 4); + Assert.Equal(1, br.ReadInt32()); + Assert.Equal(2, br.ReadInt32()); + Assert.Equal(3, br.ReadInt32()); + Assert.Equal(4, br.ReadInt32()); stream.Rewind(true); stream.StartRecording(); - Assert.Equal(br.ReadInt32(), 1); - Assert.Equal(br.ReadInt32(), 2); - Assert.Equal(br.ReadInt32(), 3); - Assert.Equal(br.ReadInt32(), 4); - Assert.Equal(br.ReadInt32(), 5); - Assert.Equal(br.ReadInt32(), 6); - Assert.Equal(br.ReadInt32(), 7); + Assert.Equal(1, br.ReadInt32()); + Assert.Equal(2, br.ReadInt32()); + Assert.Equal(3, br.ReadInt32()); + Assert.Equal(4, br.ReadInt32()); + Assert.Equal(5, br.ReadInt32()); + Assert.Equal(6, br.ReadInt32()); + Assert.Equal(7, br.ReadInt32()); stream.Rewind(true); stream.StartRecording(); - Assert.Equal(br.ReadInt32(), 1); - Assert.Equal(br.ReadInt32(), 2); - Assert.Equal(br.ReadInt32(), 3); - Assert.Equal(br.ReadInt32(), 4); + Assert.Equal(1, br.ReadInt32()); + Assert.Equal(2, br.ReadInt32()); + Assert.Equal(3, br.ReadInt32()); + Assert.Equal(4, br.ReadInt32()); } [Fact] @@ -61,23 +61,23 @@ namespace SharpCompress.Test RewindableStream stream = new RewindableStream(ms); stream.StartRecording(); BinaryReader br = new BinaryReader(stream); - Assert.Equal(br.ReadInt32(), 1); - Assert.Equal(br.ReadInt32(), 2); - Assert.Equal(br.ReadInt32(), 3); - Assert.Equal(br.ReadInt32(), 4); + Assert.Equal(1, br.ReadInt32()); + Assert.Equal(2, br.ReadInt32()); + Assert.Equal(3, br.ReadInt32()); + Assert.Equal(4, br.ReadInt32()); stream.Rewind(true); - Assert.Equal(br.ReadInt32(), 1); - Assert.Equal(br.ReadInt32(), 2); + Assert.Equal(1, br.ReadInt32()); + Assert.Equal(2, br.ReadInt32()); stream.StartRecording(); - Assert.Equal(br.ReadInt32(), 3); - Assert.Equal(br.ReadInt32(), 4); - Assert.Equal(br.ReadInt32(), 5); + Assert.Equal(3, br.ReadInt32()); + Assert.Equal(4, br.ReadInt32()); + Assert.Equal(5, br.ReadInt32()); stream.Rewind(true); - Assert.Equal(br.ReadInt32(), 3); - Assert.Equal(br.ReadInt32(), 4); - Assert.Equal(br.ReadInt32(), 5); - Assert.Equal(br.ReadInt32(), 6); - Assert.Equal(br.ReadInt32(), 7); + Assert.Equal(3, br.ReadInt32()); + Assert.Equal(4, br.ReadInt32()); + Assert.Equal(5, br.ReadInt32()); + Assert.Equal(6, br.ReadInt32()); + Assert.Equal(7, br.ReadInt32()); } } } diff --git a/test/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs similarity index 97% rename from test/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs rename to tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs index 59a8340d..4faf74af 100644 --- a/test/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs +++ b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs @@ -1,9 +1,8 @@ - -using System; +using System; using SharpCompress.Common; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.SevenZip { public class SevenZipArchiveTests : ArchiveTests { diff --git a/tests/SharpCompress.Test/SharpCompress.Test.csproj b/tests/SharpCompress.Test/SharpCompress.Test.csproj new file mode 100644 index 00000000..90da286c --- /dev/null +++ b/tests/SharpCompress.Test/SharpCompress.Test.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp1.1 + SharpCompress.Test + ../../SharpCompress.snk + true + true + SharpCompress.Test + true + 1.1.2 + + + + + + + + + + + + + + + + + + + diff --git a/test/SharpCompress.Test/Streams/StreamTests.cs b/tests/SharpCompress.Test/Streams/StreamTests.cs similarity index 100% rename from test/SharpCompress.Test/Streams/StreamTests.cs rename to tests/SharpCompress.Test/Streams/StreamTests.cs diff --git a/test/SharpCompress.Test/Tar/TarArchiveTests.cs b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs similarity index 97% rename from test/SharpCompress.Test/Tar/TarArchiveTests.cs rename to tests/SharpCompress.Test/Tar/TarArchiveTests.cs index df0666a0..e0cf73b4 100644 --- a/test/SharpCompress.Test/Tar/TarArchiveTests.cs +++ b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs @@ -1,5 +1,4 @@ - -using System.IO; +using System.IO; using System.Linq; using SharpCompress.Archives; using SharpCompress.Archives.Tar; @@ -7,7 +6,7 @@ using SharpCompress.Common; using SharpCompress.Writers; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Tar { public class TarArchiveTests : ArchiveTests { @@ -104,7 +103,7 @@ namespace SharpCompress.Test string scratchPath = Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"); string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Tar.noEmptyDirs.tar"); - base.ResetScratch(); + ResetScratch(); using (var archive = TarArchive.Create()) { archive.AddAllFromDirectory(ORIGINAL_FILES_PATH); @@ -120,7 +119,7 @@ namespace SharpCompress.Test string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Tar.mod.tar"); string modified = Path.Combine(TEST_ARCHIVES_PATH, "Tar.noEmptyDirs.tar"); - base.ResetScratch(); + ResetScratch(); using (var archive = TarArchive.Open(unmodified)) { archive.AddEntry("jpg\\test.jpg", jpg); @@ -136,7 +135,7 @@ namespace SharpCompress.Test string modified = Path.Combine(TEST_ARCHIVES_PATH, "Tar.mod.tar"); string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Tar.noEmptyDirs.tar"); - base.ResetScratch(); + ResetScratch(); using (var archive = TarArchive.Open(unmodified)) { var entry = archive.Entries.Single(x => x.Key.EndsWith("jpg")); diff --git a/test/SharpCompress.Test/Tar/TarReaderTests.cs b/tests/SharpCompress.Test/Tar/TarReaderTests.cs similarity index 94% rename from test/SharpCompress.Test/Tar/TarReaderTests.cs rename to tests/SharpCompress.Test/Tar/TarReaderTests.cs index 2251b0d8..60b0171b 100644 --- a/test/SharpCompress.Test/Tar/TarReaderTests.cs +++ b/tests/SharpCompress.Test/Tar/TarReaderTests.cs @@ -1,12 +1,11 @@ using System.Collections.Generic; using System.IO; using SharpCompress.Common; -using Xunit; -using System.Linq; using SharpCompress.Readers; using SharpCompress.Readers.Tar; +using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Tar { public class TarReaderTests : ReaderTests { @@ -50,7 +49,7 @@ namespace SharpCompress.Test { if (!reader.Entry.IsDirectory) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.BZip2); + Assert.Equal(CompressionType.BZip2, reader.Entry.CompressionType); using (var entryStream = reader.OpenEntryStream()) { string file = Path.GetFileName(reader.Entry.Key); @@ -107,7 +106,7 @@ namespace SharpCompress.Test { if (!reader.Entry.IsDirectory) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.BZip2); + Assert.Equal(CompressionType.BZip2, reader.Entry.CompressionType); using (var entryStream = reader.OpenEntryStream()) { entryStream.SkipEntry(); @@ -115,7 +114,7 @@ namespace SharpCompress.Test } } } - Assert.Equal(names.Count, 3); + Assert.Equal(3, names.Count); } } diff --git a/test/SharpCompress.Test/Tar/TarWriterTests.cs b/tests/SharpCompress.Test/Tar/TarWriterTests.cs similarity index 95% rename from test/SharpCompress.Test/Tar/TarWriterTests.cs rename to tests/SharpCompress.Test/Tar/TarWriterTests.cs index c4f783bd..678829a8 100644 --- a/test/SharpCompress.Test/Tar/TarWriterTests.cs +++ b/tests/SharpCompress.Test/Tar/TarWriterTests.cs @@ -1,7 +1,7 @@ using SharpCompress.Common; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Tar { public class TarWriterTests : WriterTests { diff --git a/test/SharpCompress.Test/TestBase.cs b/tests/SharpCompress.Test/TestBase.cs similarity index 99% rename from test/SharpCompress.Test/TestBase.cs rename to tests/SharpCompress.Test/TestBase.cs index f8e4fd91..496cff41 100644 --- a/test/SharpCompress.Test/TestBase.cs +++ b/tests/SharpCompress.Test/TestBase.cs @@ -232,7 +232,7 @@ namespace SharpCompress.Test } } - private static object lockObject = new object(); + private static readonly object lockObject = new object(); public TestBase() { diff --git a/test/SharpCompress.Test/TestStream.cs b/tests/SharpCompress.Test/TestStream.cs similarity index 59% rename from test/SharpCompress.Test/TestStream.cs rename to tests/SharpCompress.Test/TestStream.cs index b6c1abf5..f9e0b713 100644 --- a/test/SharpCompress.Test/TestStream.cs +++ b/tests/SharpCompress.Test/TestStream.cs @@ -4,12 +4,9 @@ namespace SharpCompress.Test { public class TestStream : Stream { - private Stream stream; - private bool read; - private bool write; - private bool seek; + private readonly Stream stream; - public TestStream(Stream stream) + public TestStream(Stream stream) : this(stream, true, true, true) { } @@ -19,9 +16,9 @@ namespace SharpCompress.Test public TestStream(Stream stream, bool read, bool write, bool seek) { this.stream = stream; - this.read = read; - this.write = write; - this.seek = seek; + CanRead = read; + CanWrite = write; + CanSeek = seek; } protected override void Dispose(bool disposing) @@ -31,36 +28,24 @@ namespace SharpCompress.Test IsDisposed = true; } - public override bool CanRead - { - get { return read; } - } + public override bool CanRead { get; } - public override bool CanSeek - { - get { return seek; } - } + public override bool CanSeek { get; } - public override bool CanWrite - { - get { return write; } - } + public override bool CanWrite { get; } - public override void Flush() + public override void Flush() { stream.Flush(); } - public override long Length - { - get { return stream.Length; } - } + public override long Length => stream.Length; - public override long Position + public override long Position { - get { return stream.Position; } - set { stream.Position = value; } - } + get => stream.Position; + set => stream.Position = value; + } public override int Read(byte[] buffer, int offset, int count) { diff --git a/test/SharpCompress.Test/WriterTests.cs b/tests/SharpCompress.Test/WriterTests.cs similarity index 97% rename from test/SharpCompress.Test/WriterTests.cs rename to tests/SharpCompress.Test/WriterTests.cs index ff1cf827..ea2de961 100644 --- a/test/SharpCompress.Test/WriterTests.cs +++ b/tests/SharpCompress.Test/WriterTests.cs @@ -9,7 +9,7 @@ namespace SharpCompress.Test { public class WriterTests : TestBase { - private ArchiveType type; + private readonly ArchiveType type; protected WriterTests(ArchiveType type) { diff --git a/tests/SharpCompress.Test/Zip/Zip64Tests.cs b/tests/SharpCompress.Test/Zip/Zip64Tests.cs new file mode 100644 index 00000000..07955304 --- /dev/null +++ b/tests/SharpCompress.Test/Zip/Zip64Tests.cs @@ -0,0 +1,226 @@ +using System; +using System.IO; +using System.Linq; +using SharpCompress.Archives; +using SharpCompress.Common; +using SharpCompress.Readers; +using SharpCompress.Readers.Zip; +using SharpCompress.Writers; +using SharpCompress.Writers.Zip; +using Xunit; + +namespace SharpCompress.Test.Zip +{ + public class Zip64Tests : WriterTests + { + public Zip64Tests() + : base(ArchiveType.Zip) + { + } + + // 4GiB + 1 + const long FOUR_GB_LIMIT = ((long)uint.MaxValue) + 1; + + [Fact(Skip = "Takes too long")] + [Trait("format", "zip64")] + public void Zip64_Single_Large_File() + { + // One single file, requires zip64 + RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: true, forward_only: false); + } + + [Fact(Skip = "Takes too long")] + [Trait("format", "zip64")] + public void Zip64_Two_Large_Files() + { + // One single file, requires zip64 + RunSingleTest(2, FOUR_GB_LIMIT, set_zip64: true, forward_only: false); + } + + [Fact(Skip = "Takes too long")] + [Trait("format", "zip64")] + public void Zip64_Two_Small_files() + { + // Multiple files, does not require zip64 + RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: false, forward_only: false); + } + + [Fact(Skip = "Takes too long")] + [Trait("format", "zip64")] + public void Zip64_Two_Small_files_stream() + { + // Multiple files, does not require zip64, and works with streams + RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: false, forward_only: true); + } + + [Fact(Skip = "Takes too long")] + [Trait("format", "zip64")] + public void Zip64_Two_Small_Files_Zip64() + { + // Multiple files, use zip64 even though it is not required + RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: true, forward_only: false); + } + + [Fact(Skip = "Takes too long")] + [Trait("format", "zip64")] + public void Zip64_Single_Large_File_Fail() + { + try + { + // One single file, should fail + RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: false, forward_only: false); + throw new Exception("Test did not fail?"); + } + catch (NotSupportedException) + { + } + } + + [Fact(Skip = "Takes too long")] + [Trait("zip64", "true")] + public void Zip64_Single_Large_File_Zip64_Streaming_Fail() + { + try + { + // One single file, should fail (fast) with zip64 + RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: true, forward_only: true); + throw new Exception("Test did not fail?"); + } + catch (NotSupportedException) + { + } + } + + [Fact(Skip = "Takes too long")] + [Trait("zip64", "true")] + public void Zip64_Single_Large_File_Streaming_Fail() + { + try + { + // One single file, should fail once the write discovers the problem + RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: false, forward_only: true); + throw new Exception("Test did not fail?"); + } + catch (NotSupportedException) + { + } + } + + public void RunSingleTest(long files, long filesize, bool set_zip64, bool forward_only, long write_chunk_size = 1024 * 1024, string filename = "zip64-test.zip") + { + ResetScratch(); + filename = Path.Combine(SCRATCH2_FILES_PATH, filename); + + if (File.Exists(filename)) + File.Delete(filename); + + if (!File.Exists(filename)) + CreateZipArchive(filename, files, filesize, write_chunk_size, set_zip64, forward_only); + + var resForward = ReadForwardOnly(filename); + if (resForward.Item1 != files) + throw new Exception($"Incorrect number of items reported: {resForward.Item1}, should have been {files}"); + + if (resForward.Item2 != files * filesize) + throw new Exception($"Incorrect combined size reported: {resForward.Item2}, should have been {files * filesize}"); + + var resArchive = ReadArchive(filename); + if (resArchive.Item1 != files) + throw new Exception($"Incorrect number of items reported: {resArchive.Item1}, should have been {files}"); + if (resArchive.Item2 != files * filesize) + throw new Exception($"Incorrect number of items reported: {resArchive.Item2}, should have been {files * filesize}"); + } + + public void CreateZipArchive(string filename, long files, long filesize, long chunksize, bool set_zip64, bool forward_only) + { + var data = new byte[chunksize]; + + // Use deflate for speed + var opts = new ZipWriterOptions(CompressionType.Deflate) { UseZip64 = set_zip64 }; + + // Use no compression to ensure we hit the limits (actually inflates a bit, but seems better than using method==Store) + var eo = new ZipWriterEntryOptions() { DeflateCompressionLevel = Compressors.Deflate.CompressionLevel.None }; + + using (var zip = File.OpenWrite(filename)) + using(var st = forward_only ? (Stream)new NonSeekableStream(zip) : zip) + using (var zipWriter = (ZipWriter)WriterFactory.Open(st, ArchiveType.Zip, opts)) + { + + for (var i = 0; i < files; i++) + using (var str = zipWriter.WriteToStream(i.ToString(), eo)) + { + var left = filesize; + while (left > 0) + { + var b = (int)Math.Min(left, data.Length); + str.Write(data, 0, b); + left -= b; + } + } + } + } + + public Tuple ReadForwardOnly(string filename) + { + long count = 0; + long size = 0; + Common.Zip.ZipEntry prev = null; + using (var fs = File.OpenRead(filename)) + using (var rd = ZipReader.Open(fs, new ReaderOptions() { LookForHeader = false })) + while (rd.MoveToNextEntry()) + { + using (rd.OpenEntryStream()) + { } + + count++; + if (prev != null) + size += prev.Size; + + prev = rd.Entry; + } + + if (prev != null) + size += prev.Size; + + return new Tuple(count, size); + } + + public Tuple ReadArchive(string filename) + { + using (var archive = ArchiveFactory.Open(filename)) + { + return new Tuple( + archive.Entries.Count(), + archive.Entries.Select(x => x.Size).Sum() + ); + } + } + + /// + /// Helper to create non-seekable streams from filestream + /// + private class NonSeekableStream : Stream + { + private readonly Stream stream; + public NonSeekableStream(Stream s) { stream = s; } + public override bool CanRead => stream.CanRead; + public override bool CanSeek => false; + public override bool CanWrite => stream.CanWrite; + public override long Length => throw new NotImplementedException(); + public override long Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public override void Flush() { stream.Flush(); } + + public override int Read(byte[] buffer, int offset, int count) + { return stream.Read(buffer, offset, count); } + + public override long Seek(long offset, SeekOrigin origin) + { throw new NotImplementedException(); } + + public override void SetLength(long value) + { throw new NotImplementedException(); } + + public override void Write(byte[] buffer, int offset, int count) + { stream.Write(buffer, offset, count); } + } + } +} \ No newline at end of file diff --git a/test/SharpCompress.Test/Zip/ZipArchiveTests.cs b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs similarity index 94% rename from test/SharpCompress.Test/Zip/ZipArchiveTests.cs rename to tests/SharpCompress.Test/Zip/ZipArchiveTests.cs index 257f6da9..b0b26555 100644 --- a/test/SharpCompress.Test/Zip/ZipArchiveTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs @@ -1,5 +1,4 @@ - -using System; +using System; using System.IO; using System.Linq; using System.Text; @@ -10,7 +9,7 @@ using SharpCompress.Readers; using SharpCompress.Writers; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Zip { public class ZipArchiveTests : ArchiveTests { @@ -148,7 +147,7 @@ namespace SharpCompress.Test string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.noEmptyDirs.zip"); string modified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.mod.zip"); - base.ResetScratch(); + ResetScratch(); using (var archive = ZipArchive.Open(unmodified)) { var entry = archive.Entries.Single(x => x.Key.EndsWith("jpg")); @@ -166,7 +165,7 @@ namespace SharpCompress.Test string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.mod.zip"); string modified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.mod2.zip"); - base.ResetScratch(); + ResetScratch(); using (var archive = ZipArchive.Open(unmodified)) { archive.AddEntry("jpg\\test.jpg", jpg); @@ -245,7 +244,7 @@ namespace SharpCompress.Test [Fact] public void Zip_Create_New() { - base.ResetScratch(); + ResetScratch(); foreach (var file in Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)) { var newFileName = file.Substring(ORIGINAL_FILES_PATH.Length); @@ -276,7 +275,7 @@ namespace SharpCompress.Test [Fact] public void Zip_Create_New_Add_Remove() { - base.ResetScratch(); + ResetScratch(); foreach (var file in Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)) { var newFileName = file.Substring(ORIGINAL_FILES_PATH.Length); @@ -324,6 +323,24 @@ namespace SharpCompress.Test VerifyFiles(); } + [Fact] + public void Zip_Deflate_WinzipAES_MultiOpenEntryStream() + { + ResetScratch(); + using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES2.zip"), new ReaderOptions() + { + Password = "test" + })) + { + foreach (var entry in reader.Entries.Where(x => !x.IsDirectory)) + { + var stream = entry.OpenEntryStream(); + Assert.NotNull(stream); + var ex = Record.Exception(() => stream = entry.OpenEntryStream()); + Assert.Null(ex); + } + } + } [Fact] public void Zip_BZip2_Pkware_Read() @@ -351,14 +368,14 @@ namespace SharpCompress.Test { string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.noEmptyDirs.zip"); - base.ResetScratch(); + ResetScratch(); ZipArchive a = ZipArchive.Open(unmodified); int count = 0; foreach (var e in a.Entries) count++; //Prints 3 - Assert.Equal(count, 3); + Assert.Equal(3, count); a.Dispose(); a = ZipArchive.Open(unmodified); @@ -382,7 +399,7 @@ namespace SharpCompress.Test foreach (var e in a.Entries) count3++; - Assert.Equal(count3, 3); + Assert.Equal(3, count3); } [Fact] @@ -411,13 +428,7 @@ namespace SharpCompress.Test class NonSeekableMemoryStream : MemoryStream { - public override bool CanSeek - { - get - { - return false; - } - } + public override bool CanSeek => false; } [Fact] diff --git a/test/SharpCompress.Test/Zip/ZipReaderTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs similarity index 95% rename from test/SharpCompress.Test/Zip/ZipReaderTests.cs rename to tests/SharpCompress.Test/Zip/ZipReaderTests.cs index 35db1278..e766aa94 100644 --- a/test/SharpCompress.Test/Zip/ZipReaderTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs @@ -6,7 +6,7 @@ using SharpCompress.Readers.Zip; using SharpCompress.Writers; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Zip { public class ZipReaderTests : ReaderTests { @@ -100,7 +100,7 @@ namespace SharpCompress.Test { if (!reader.Entry.IsDirectory) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.BZip2); + Assert.Equal(CompressionType.BZip2, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, @@ -179,8 +179,7 @@ namespace SharpCompress.Test { if (!reader.Entry.IsDirectory) { - Assert.Equal(reader.Entry.CompressionType, - CompressionType.Unknown); + Assert.Equal(CompressionType.Unknown, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { @@ -208,7 +207,7 @@ namespace SharpCompress.Test { if (!reader.Entry.IsDirectory) { - Assert.Equal(reader.Entry.CompressionType, CompressionType.Unknown); + Assert.Equal(CompressionType.Unknown, reader.Entry.CompressionType); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { @@ -223,13 +222,7 @@ namespace SharpCompress.Test class NonSeekableMemoryStream : MemoryStream { - public override bool CanSeek - { - get - { - return false; - } - } + public override bool CanSeek => false; } [Fact] diff --git a/test/SharpCompress.Test/Zip/ZipWriterTests.cs b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs similarity index 97% rename from test/SharpCompress.Test/Zip/ZipWriterTests.cs rename to tests/SharpCompress.Test/Zip/ZipWriterTests.cs index 413365a2..af29e5e5 100644 --- a/test/SharpCompress.Test/Zip/ZipWriterTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs @@ -1,7 +1,7 @@ using SharpCompress.Common; using Xunit; -namespace SharpCompress.Test +namespace SharpCompress.Test.Zip { public class ZipWriterTests : WriterTests { diff --git a/test/TestArchives/Archives/7Zip.BZip2.7z b/tests/TestArchives/Archives/7Zip.BZip2.7z similarity index 100% rename from test/TestArchives/Archives/7Zip.BZip2.7z rename to tests/TestArchives/Archives/7Zip.BZip2.7z diff --git a/test/TestArchives/Archives/7Zip.LZMA.7z b/tests/TestArchives/Archives/7Zip.LZMA.7z similarity index 100% rename from test/TestArchives/Archives/7Zip.LZMA.7z rename to tests/TestArchives/Archives/7Zip.LZMA.7z diff --git a/test/TestArchives/Archives/7Zip.LZMA2.7z b/tests/TestArchives/Archives/7Zip.LZMA2.7z similarity index 100% rename from test/TestArchives/Archives/7Zip.LZMA2.7z rename to tests/TestArchives/Archives/7Zip.LZMA2.7z diff --git a/test/TestArchives/Archives/7Zip.PPMd.7z b/tests/TestArchives/Archives/7Zip.PPMd.7z similarity index 100% rename from test/TestArchives/Archives/7Zip.PPMd.7z rename to tests/TestArchives/Archives/7Zip.PPMd.7z diff --git a/test/TestArchives/Archives/Audio_program.rar b/tests/TestArchives/Archives/Audio_program.rar similarity index 100% rename from test/TestArchives/Archives/Audio_program.rar rename to tests/TestArchives/Archives/Audio_program.rar diff --git a/test/TestArchives/Archives/Encrypted.rar b/tests/TestArchives/Archives/Encrypted.rar similarity index 100% rename from test/TestArchives/Archives/Encrypted.rar rename to tests/TestArchives/Archives/Encrypted.rar diff --git a/test/TestArchives/Archives/EncryptedParts.part01.rar b/tests/TestArchives/Archives/EncryptedParts.part01.rar similarity index 100% rename from test/TestArchives/Archives/EncryptedParts.part01.rar rename to tests/TestArchives/Archives/EncryptedParts.part01.rar diff --git a/test/TestArchives/Archives/EncryptedParts.part02.rar b/tests/TestArchives/Archives/EncryptedParts.part02.rar similarity index 100% rename from test/TestArchives/Archives/EncryptedParts.part02.rar rename to tests/TestArchives/Archives/EncryptedParts.part02.rar diff --git a/test/TestArchives/Archives/EncryptedParts.part03.rar b/tests/TestArchives/Archives/EncryptedParts.part03.rar similarity index 100% rename from test/TestArchives/Archives/EncryptedParts.part03.rar rename to tests/TestArchives/Archives/EncryptedParts.part03.rar diff --git a/test/TestArchives/Archives/EncryptedParts.part04.rar b/tests/TestArchives/Archives/EncryptedParts.part04.rar similarity index 100% rename from test/TestArchives/Archives/EncryptedParts.part04.rar rename to tests/TestArchives/Archives/EncryptedParts.part04.rar diff --git a/test/TestArchives/Archives/EncryptedParts.part05.rar b/tests/TestArchives/Archives/EncryptedParts.part05.rar similarity index 100% rename from test/TestArchives/Archives/EncryptedParts.part05.rar rename to tests/TestArchives/Archives/EncryptedParts.part05.rar diff --git a/test/TestArchives/Archives/EncryptedParts.part06.rar b/tests/TestArchives/Archives/EncryptedParts.part06.rar similarity index 100% rename from test/TestArchives/Archives/EncryptedParts.part06.rar rename to tests/TestArchives/Archives/EncryptedParts.part06.rar diff --git a/test/TestArchives/Archives/Original.7z.001 b/tests/TestArchives/Archives/Original.7z.001 similarity index 100% rename from test/TestArchives/Archives/Original.7z.001 rename to tests/TestArchives/Archives/Original.7z.001 diff --git a/test/TestArchives/Archives/Original.7z.002 b/tests/TestArchives/Archives/Original.7z.002 similarity index 100% rename from test/TestArchives/Archives/Original.7z.002 rename to tests/TestArchives/Archives/Original.7z.002 diff --git a/test/TestArchives/Archives/Original.7z.003 b/tests/TestArchives/Archives/Original.7z.003 similarity index 100% rename from test/TestArchives/Archives/Original.7z.003 rename to tests/TestArchives/Archives/Original.7z.003 diff --git a/test/TestArchives/Archives/Original.7z.004 b/tests/TestArchives/Archives/Original.7z.004 similarity index 100% rename from test/TestArchives/Archives/Original.7z.004 rename to tests/TestArchives/Archives/Original.7z.004 diff --git a/test/TestArchives/Archives/Original.7z.005 b/tests/TestArchives/Archives/Original.7z.005 similarity index 100% rename from test/TestArchives/Archives/Original.7z.005 rename to tests/TestArchives/Archives/Original.7z.005 diff --git a/test/TestArchives/Archives/Original.7z.006 b/tests/TestArchives/Archives/Original.7z.006 similarity index 100% rename from test/TestArchives/Archives/Original.7z.006 rename to tests/TestArchives/Archives/Original.7z.006 diff --git a/test/TestArchives/Archives/Original.7z.007 b/tests/TestArchives/Archives/Original.7z.007 similarity index 100% rename from test/TestArchives/Archives/Original.7z.007 rename to tests/TestArchives/Archives/Original.7z.007 diff --git a/test/TestArchives/Archives/Rar.encrypted_filesAndHeader.rar b/tests/TestArchives/Archives/Rar.encrypted_filesAndHeader.rar similarity index 100% rename from test/TestArchives/Archives/Rar.encrypted_filesAndHeader.rar rename to tests/TestArchives/Archives/Rar.encrypted_filesAndHeader.rar diff --git a/test/TestArchives/Archives/Rar.encrypted_filesOnly.rar b/tests/TestArchives/Archives/Rar.encrypted_filesOnly.rar similarity index 100% rename from test/TestArchives/Archives/Rar.encrypted_filesOnly.rar rename to tests/TestArchives/Archives/Rar.encrypted_filesOnly.rar diff --git a/test/TestArchives/Archives/Rar.multi.part01.rar b/tests/TestArchives/Archives/Rar.multi.part01.rar similarity index 100% rename from test/TestArchives/Archives/Rar.multi.part01.rar rename to tests/TestArchives/Archives/Rar.multi.part01.rar diff --git a/test/TestArchives/Archives/Rar.multi.part02.rar b/tests/TestArchives/Archives/Rar.multi.part02.rar similarity index 100% rename from test/TestArchives/Archives/Rar.multi.part02.rar rename to tests/TestArchives/Archives/Rar.multi.part02.rar diff --git a/test/TestArchives/Archives/Rar.multi.part03.rar b/tests/TestArchives/Archives/Rar.multi.part03.rar similarity index 100% rename from test/TestArchives/Archives/Rar.multi.part03.rar rename to tests/TestArchives/Archives/Rar.multi.part03.rar diff --git a/test/TestArchives/Archives/Rar.multi.part04.rar b/tests/TestArchives/Archives/Rar.multi.part04.rar similarity index 100% rename from test/TestArchives/Archives/Rar.multi.part04.rar rename to tests/TestArchives/Archives/Rar.multi.part04.rar diff --git a/test/TestArchives/Archives/Rar.multi.part05.rar b/tests/TestArchives/Archives/Rar.multi.part05.rar similarity index 100% rename from test/TestArchives/Archives/Rar.multi.part05.rar rename to tests/TestArchives/Archives/Rar.multi.part05.rar diff --git a/test/TestArchives/Archives/Rar.multi.part06.rar b/tests/TestArchives/Archives/Rar.multi.part06.rar similarity index 100% rename from test/TestArchives/Archives/Rar.multi.part06.rar rename to tests/TestArchives/Archives/Rar.multi.part06.rar diff --git a/test/TestArchives/Archives/Rar.none.rar b/tests/TestArchives/Archives/Rar.none.rar similarity index 100% rename from test/TestArchives/Archives/Rar.none.rar rename to tests/TestArchives/Archives/Rar.none.rar diff --git a/test/TestArchives/Archives/Rar.rar b/tests/TestArchives/Archives/Rar.rar similarity index 100% rename from test/TestArchives/Archives/Rar.rar rename to tests/TestArchives/Archives/Rar.rar diff --git a/test/TestArchives/Archives/Rar.solid.rar b/tests/TestArchives/Archives/Rar.solid.rar similarity index 100% rename from test/TestArchives/Archives/Rar.solid.rar rename to tests/TestArchives/Archives/Rar.solid.rar diff --git a/test/TestArchives/Archives/Rarjpeg.jpg b/tests/TestArchives/Archives/Rarjpeg.jpg similarity index 100% rename from test/TestArchives/Archives/Rarjpeg.jpg rename to tests/TestArchives/Archives/Rarjpeg.jpg diff --git a/test/TestArchives/Archives/Tar.ContainsRar.tar b/tests/TestArchives/Archives/Tar.ContainsRar.tar similarity index 100% rename from test/TestArchives/Archives/Tar.ContainsRar.tar rename to tests/TestArchives/Archives/Tar.ContainsRar.tar diff --git a/test/TestArchives/Archives/Tar.LongPathsWithLongNameExtension.tar b/tests/TestArchives/Archives/Tar.LongPathsWithLongNameExtension.tar similarity index 100% rename from test/TestArchives/Archives/Tar.LongPathsWithLongNameExtension.tar rename to tests/TestArchives/Archives/Tar.LongPathsWithLongNameExtension.tar diff --git a/test/TestArchives/Archives/Tar.mod.tar b/tests/TestArchives/Archives/Tar.mod.tar similarity index 100% rename from test/TestArchives/Archives/Tar.mod.tar rename to tests/TestArchives/Archives/Tar.mod.tar diff --git a/test/TestArchives/Archives/Tar.noEmptyDirs.tar b/tests/TestArchives/Archives/Tar.noEmptyDirs.tar similarity index 100% rename from test/TestArchives/Archives/Tar.noEmptyDirs.tar rename to tests/TestArchives/Archives/Tar.noEmptyDirs.tar diff --git a/test/TestArchives/Archives/Tar.noEmptyDirs.tar.bz2 b/tests/TestArchives/Archives/Tar.noEmptyDirs.tar.bz2 similarity index 100% rename from test/TestArchives/Archives/Tar.noEmptyDirs.tar.bz2 rename to tests/TestArchives/Archives/Tar.noEmptyDirs.tar.bz2 diff --git a/test/TestArchives/Archives/Tar.tar b/tests/TestArchives/Archives/Tar.tar similarity index 100% rename from test/TestArchives/Archives/Tar.tar rename to tests/TestArchives/Archives/Tar.tar diff --git a/test/TestArchives/Archives/Tar.tar.bz2 b/tests/TestArchives/Archives/Tar.tar.bz2 similarity index 100% rename from test/TestArchives/Archives/Tar.tar.bz2 rename to tests/TestArchives/Archives/Tar.tar.bz2 diff --git a/test/TestArchives/Archives/Tar.tar.gz b/tests/TestArchives/Archives/Tar.tar.gz similarity index 100% rename from test/TestArchives/Archives/Tar.tar.gz rename to tests/TestArchives/Archives/Tar.tar.gz diff --git a/test/TestArchives/Archives/Tar.tar.lz b/tests/TestArchives/Archives/Tar.tar.lz similarity index 100% rename from test/TestArchives/Archives/Tar.tar.lz rename to tests/TestArchives/Archives/Tar.tar.lz diff --git a/test/TestArchives/Archives/Zip.bzip2.dd.zip b/tests/TestArchives/Archives/Zip.bzip2.dd.zip similarity index 100% rename from test/TestArchives/Archives/Zip.bzip2.dd.zip rename to tests/TestArchives/Archives/Zip.bzip2.dd.zip diff --git a/test/TestArchives/Archives/Zip.bzip2.noEmptyDirs.zip b/tests/TestArchives/Archives/Zip.bzip2.noEmptyDirs.zip similarity index 100% rename from test/TestArchives/Archives/Zip.bzip2.noEmptyDirs.zip rename to tests/TestArchives/Archives/Zip.bzip2.noEmptyDirs.zip diff --git a/test/TestArchives/Archives/Zip.bzip2.pkware.zip b/tests/TestArchives/Archives/Zip.bzip2.pkware.zip similarity index 100% rename from test/TestArchives/Archives/Zip.bzip2.pkware.zip rename to tests/TestArchives/Archives/Zip.bzip2.pkware.zip diff --git a/test/TestArchives/Archives/Zip.bzip2.zip b/tests/TestArchives/Archives/Zip.bzip2.zip similarity index 100% rename from test/TestArchives/Archives/Zip.bzip2.zip rename to tests/TestArchives/Archives/Zip.bzip2.zip diff --git a/test/TestArchives/Archives/Zip.deflate.WinzipAES.zip b/tests/TestArchives/Archives/Zip.deflate.WinzipAES.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.WinzipAES.zip rename to tests/TestArchives/Archives/Zip.deflate.WinzipAES.zip diff --git a/tests/TestArchives/Archives/Zip.deflate.WinzipAES2.zip b/tests/TestArchives/Archives/Zip.deflate.WinzipAES2.zip new file mode 100644 index 00000000..523670fe Binary files /dev/null and b/tests/TestArchives/Archives/Zip.deflate.WinzipAES2.zip differ diff --git a/test/TestArchives/Archives/Zip.deflate.dd-.zip b/tests/TestArchives/Archives/Zip.deflate.dd-.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.dd-.zip rename to tests/TestArchives/Archives/Zip.deflate.dd-.zip diff --git a/test/TestArchives/Archives/Zip.deflate.dd.zip b/tests/TestArchives/Archives/Zip.deflate.dd.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.dd.zip rename to tests/TestArchives/Archives/Zip.deflate.dd.zip diff --git a/test/TestArchives/Archives/Zip.deflate.mod.zip b/tests/TestArchives/Archives/Zip.deflate.mod.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.mod.zip rename to tests/TestArchives/Archives/Zip.deflate.mod.zip diff --git a/test/TestArchives/Archives/Zip.deflate.mod2.zip b/tests/TestArchives/Archives/Zip.deflate.mod2.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.mod2.zip rename to tests/TestArchives/Archives/Zip.deflate.mod2.zip diff --git a/test/TestArchives/Archives/Zip.deflate.noEmptyDirs.zip b/tests/TestArchives/Archives/Zip.deflate.noEmptyDirs.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.noEmptyDirs.zip rename to tests/TestArchives/Archives/Zip.deflate.noEmptyDirs.zip diff --git a/test/TestArchives/Archives/Zip.deflate.pkware.zip b/tests/TestArchives/Archives/Zip.deflate.pkware.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.pkware.zip rename to tests/TestArchives/Archives/Zip.deflate.pkware.zip diff --git a/test/TestArchives/Archives/Zip.deflate.zip b/tests/TestArchives/Archives/Zip.deflate.zip similarity index 100% rename from test/TestArchives/Archives/Zip.deflate.zip rename to tests/TestArchives/Archives/Zip.deflate.zip diff --git a/test/TestArchives/Archives/Zip.lzma.WinzipAES.zip b/tests/TestArchives/Archives/Zip.lzma.WinzipAES.zip similarity index 100% rename from test/TestArchives/Archives/Zip.lzma.WinzipAES.zip rename to tests/TestArchives/Archives/Zip.lzma.WinzipAES.zip diff --git a/test/TestArchives/Archives/Zip.lzma.dd.zip b/tests/TestArchives/Archives/Zip.lzma.dd.zip similarity index 100% rename from test/TestArchives/Archives/Zip.lzma.dd.zip rename to tests/TestArchives/Archives/Zip.lzma.dd.zip diff --git a/test/TestArchives/Archives/Zip.lzma.noEmptyDirs.zip b/tests/TestArchives/Archives/Zip.lzma.noEmptyDirs.zip similarity index 100% rename from test/TestArchives/Archives/Zip.lzma.noEmptyDirs.zip rename to tests/TestArchives/Archives/Zip.lzma.noEmptyDirs.zip diff --git a/test/TestArchives/Archives/Zip.lzma.zip b/tests/TestArchives/Archives/Zip.lzma.zip similarity index 100% rename from test/TestArchives/Archives/Zip.lzma.zip rename to tests/TestArchives/Archives/Zip.lzma.zip diff --git a/test/TestArchives/Archives/Zip.none.noEmptyDirs.zip b/tests/TestArchives/Archives/Zip.none.noEmptyDirs.zip similarity index 100% rename from test/TestArchives/Archives/Zip.none.noEmptyDirs.zip rename to tests/TestArchives/Archives/Zip.none.noEmptyDirs.zip diff --git a/test/TestArchives/Archives/Zip.none.zip b/tests/TestArchives/Archives/Zip.none.zip similarity index 100% rename from test/TestArchives/Archives/Zip.none.zip rename to tests/TestArchives/Archives/Zip.none.zip diff --git a/test/TestArchives/Archives/Zip.ppmd.dd.zip b/tests/TestArchives/Archives/Zip.ppmd.dd.zip similarity index 100% rename from test/TestArchives/Archives/Zip.ppmd.dd.zip rename to tests/TestArchives/Archives/Zip.ppmd.dd.zip diff --git a/test/TestArchives/Archives/Zip.ppmd.noEmptyDirs.zip b/tests/TestArchives/Archives/Zip.ppmd.noEmptyDirs.zip similarity index 100% rename from test/TestArchives/Archives/Zip.ppmd.noEmptyDirs.zip rename to tests/TestArchives/Archives/Zip.ppmd.noEmptyDirs.zip diff --git a/test/TestArchives/Archives/Zip.ppmd.zip b/tests/TestArchives/Archives/Zip.ppmd.zip similarity index 100% rename from test/TestArchives/Archives/Zip.ppmd.zip rename to tests/TestArchives/Archives/Zip.ppmd.zip diff --git a/test/TestArchives/Archives/Zip.zip64.zip b/tests/TestArchives/Archives/Zip.zip64.zip similarity index 100% rename from test/TestArchives/Archives/Zip.zip64.zip rename to tests/TestArchives/Archives/Zip.zip64.zip diff --git a/test/TestArchives/Archives/Zip.zipx b/tests/TestArchives/Archives/Zip.zipx similarity index 100% rename from test/TestArchives/Archives/Zip.zipx rename to tests/TestArchives/Archives/Zip.zipx diff --git a/test/TestArchives/Archives/adc_compressed.bin b/tests/TestArchives/Archives/adc_compressed.bin similarity index 100% rename from test/TestArchives/Archives/adc_compressed.bin rename to tests/TestArchives/Archives/adc_compressed.bin diff --git a/test/TestArchives/Archives/adc_decompressed.bin b/tests/TestArchives/Archives/adc_decompressed.bin similarity index 100% rename from test/TestArchives/Archives/adc_decompressed.bin rename to tests/TestArchives/Archives/adc_decompressed.bin diff --git a/test/TestArchives/Archives/test_invalid_exttime.rar b/tests/TestArchives/Archives/test_invalid_exttime.rar similarity index 100% rename from test/TestArchives/Archives/test_invalid_exttime.rar rename to tests/TestArchives/Archives/test_invalid_exttime.rar diff --git a/test/TestArchives/Archives/ustar with long names.tar b/tests/TestArchives/Archives/ustar with long names.tar similarity index 100% rename from test/TestArchives/Archives/ustar with long names.tar rename to tests/TestArchives/Archives/ustar with long names.tar diff --git a/test/TestArchives/Archives/very long filename.tar b/tests/TestArchives/Archives/very long filename.tar similarity index 100% rename from test/TestArchives/Archives/very long filename.tar rename to tests/TestArchives/Archives/very long filename.tar diff --git a/test/TestArchives/MiscTest/test.dat b/tests/TestArchives/MiscTest/test.dat similarity index 100% rename from test/TestArchives/MiscTest/test.dat rename to tests/TestArchives/MiscTest/test.dat diff --git a/test/TestArchives/Original/exe/test.exe b/tests/TestArchives/Original/exe/test.exe similarity index 100% rename from test/TestArchives/Original/exe/test.exe rename to tests/TestArchives/Original/exe/test.exe diff --git a/test/TestArchives/Original/jpg/test.jpg b/tests/TestArchives/Original/jpg/test.jpg similarity index 100% rename from test/TestArchives/Original/jpg/test.jpg rename to tests/TestArchives/Original/jpg/test.jpg diff --git a/test/TestArchives/Original/тест.txt b/tests/TestArchives/Original/тест.txt similarity index 100% rename from test/TestArchives/Original/тест.txt rename to tests/TestArchives/Original/тест.txt diff --git a/test/TestArchives/SharpCompress.AES.zip b/tests/TestArchives/SharpCompress.AES.zip similarity index 100% rename from test/TestArchives/SharpCompress.AES.zip rename to tests/TestArchives/SharpCompress.AES.zip diff --git a/test/TestArchives/SharpCompress.Encrypted.zip b/tests/TestArchives/SharpCompress.Encrypted.zip similarity index 100% rename from test/TestArchives/SharpCompress.Encrypted.zip rename to tests/TestArchives/SharpCompress.Encrypted.zip diff --git a/test/TestArchives/SharpCompress.Encrypted2.zip b/tests/TestArchives/SharpCompress.Encrypted2.zip similarity index 100% rename from test/TestArchives/SharpCompress.Encrypted2.zip rename to tests/TestArchives/SharpCompress.Encrypted2.zip