mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-05 13:34:59 +00:00
Compare commits
5 Commits
recycle-me
...
build-netc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce6fd9b976 | ||
|
|
ae7e8c03f2 | ||
|
|
22e2526f4c | ||
|
|
50283d9411 | ||
|
|
6f387336c0 |
@@ -1,16 +0,0 @@
|
||||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: mcr.microsoft.com/dotnet/core/sdk:2.2-alpine
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Install Cake
|
||||
command: |
|
||||
dotnet tool install -g Cake.Tool
|
||||
echo 'export PATH=$PATH:/root/.dotnet/tools' >> $BASH_ENV
|
||||
source $BASH_ENV
|
||||
- run:
|
||||
name: Build
|
||||
command: dotnet cake build.cake
|
||||
18
.github/workflows/dotnetcore.yml
vendored
Normal file
18
.github/workflows/dotnetcore.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
name: Build and Test CaseFunnel
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.100
|
||||
- name: Run the Cake script
|
||||
uses: ecampidoglio/cake-action@master
|
||||
@@ -1,6 +1,6 @@
|
||||
# SharpCompress
|
||||
|
||||
SharpCompress is a compression library in pure C# for .NET Standard 1.4 and 2.0 and .NET 4.6 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 Standard 1.3 and 2.0 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).
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version: '{build}'
|
||||
image: Visual Studio 2017
|
||||
image: Visual Studio 2019
|
||||
|
||||
pull_requests:
|
||||
do_not_increment_build_number: true
|
||||
|
||||
54
build.cake
54
build.cake
@@ -11,23 +11,32 @@ Task("Build")
|
||||
.IsDependentOn("Restore")
|
||||
.Does(() =>
|
||||
{
|
||||
var settings = new DotNetCoreBuildSettings
|
||||
{
|
||||
Framework = "netstandard1.4",
|
||||
Configuration = "Release",
|
||||
NoRestore = true
|
||||
};
|
||||
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
|
||||
if (IsRunningOnWindows())
|
||||
{
|
||||
settings.Framework = "net46";
|
||||
MSBuild("./sharpcompress.sln", c =>
|
||||
{
|
||||
c.SetConfiguration("Release")
|
||||
.SetVerbosity(Verbosity.Minimal)
|
||||
.UseToolVersion(MSBuildToolVersion.VS2019);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var settings = new DotNetCoreBuildSettings
|
||||
{
|
||||
Framework = "netstandard1.3",
|
||||
Configuration = "Release",
|
||||
NoRestore = true
|
||||
};
|
||||
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
|
||||
settings.Framework = "netstandard2.0";
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
|
||||
settings.Framework = "netstandard2.1";
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
}
|
||||
|
||||
settings.Framework = "netstandard2.0";
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
});
|
||||
|
||||
Task("Test")
|
||||
@@ -40,7 +49,7 @@ Task("Test")
|
||||
var settings = new DotNetCoreTestSettings
|
||||
{
|
||||
Configuration = "Release",
|
||||
Framework = "netcoreapp2.2"
|
||||
Framework = "netcoreapp3.1"
|
||||
};
|
||||
DotNetCoreTest(file.ToString(), settings);
|
||||
}
|
||||
@@ -49,17 +58,16 @@ Task("Test")
|
||||
Task("Pack")
|
||||
.IsDependentOn("Build")
|
||||
.Does(() =>
|
||||
{
|
||||
{
|
||||
if (IsRunningOnWindows())
|
||||
{
|
||||
var settings = new DotNetCorePackSettings
|
||||
{
|
||||
Configuration = "Release",
|
||||
NoBuild = true
|
||||
};
|
||||
|
||||
DotNetCorePack("src/SharpCompress/SharpCompress.csproj", settings);
|
||||
}
|
||||
MSBuild("src/SharpCompress/SharpCompress.csproj", c => c
|
||||
.SetConfiguration("Release")
|
||||
.SetVerbosity(Verbosity.Minimal)
|
||||
.UseToolVersion(MSBuildToolVersion.VS2019)
|
||||
.WithProperty("NoBuild", "true")
|
||||
.WithTarget("Pack"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Information("Skipping Pack as this is not Windows");
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace SharpCompress.Archives
|
||||
protected ReaderOptions ReaderOptions { get; }
|
||||
|
||||
private bool disposed;
|
||||
|
||||
|
||||
internal AbstractArchive(ArchiveType type, FileInfo fileInfo, ReaderOptions readerOptions)
|
||||
{
|
||||
Type = type;
|
||||
@@ -140,12 +140,12 @@ namespace SharpCompress.Archives
|
||||
|
||||
/// <summary>
|
||||
/// Use this method to extract all entries in an archive in order.
|
||||
/// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
|
||||
/// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
|
||||
/// extracted sequentially for the best performance.
|
||||
///
|
||||
///
|
||||
/// This method will load all entry information from the archive.
|
||||
///
|
||||
/// WARNING: this will reuse the underlying stream for the archive. Errors may
|
||||
///
|
||||
/// WARNING: this will reuse the underlying stream for the archive. Errors may
|
||||
/// occur if this is used at the same time as other extraction methods on this instance.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
@@ -174,4 +174,4 @@ namespace SharpCompress.Archives
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,4 +142,4 @@ namespace SharpCompress.Archives
|
||||
modifiedEntries.Cast<Entry>().ForEach(x => x.Close());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace SharpCompress.Archives.SevenZip
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(stream);
|
||||
byte[] signatureBytes = reader.ReadBytes(6);
|
||||
return signatureBytes.BinaryEquals(SIGNATURE);
|
||||
return signatureBytes.SequenceEqual(SIGNATURE);
|
||||
}
|
||||
|
||||
protected override IReader CreateReaderForSolidExtraction()
|
||||
@@ -201,7 +201,7 @@ namespace SharpCompress.Archives.SevenZip
|
||||
return CreateEntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class PasswordProvider : IPasswordProvider
|
||||
{
|
||||
private readonly string _password;
|
||||
@@ -209,7 +209,6 @@ namespace SharpCompress.Archives.SevenZip
|
||||
public PasswordProvider(string password)
|
||||
{
|
||||
_password = password;
|
||||
|
||||
}
|
||||
|
||||
public string CryptoGetTextPassword()
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace SharpCompress.Archives.Tar
|
||||
|
||||
using (var entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
using (var memoryStream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream())
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
entryStream.TransferTo(memoryStream);
|
||||
memoryStream.Position = 0;
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Runtime.CompilerServices;
|
||||
[assembly: AssemblyTitle("SharpCompress")]
|
||||
[assembly: AssemblyProduct("SharpCompress")]
|
||||
[assembly: InternalsVisibleTo("SharpCompress.Test" + SharpCompress.AssemblyInfo.PublicKeySuffix)]
|
||||
[assembly: InternalsVisibleTo("SharpCompress.Test.Portable" + SharpCompress.AssemblyInfo.PublicKeySuffix)]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
namespace SharpCompress
|
||||
|
||||
@@ -1396,7 +1396,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
else
|
||||
{
|
||||
_stream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
_stream = new MemoryStream();
|
||||
}
|
||||
_rem = _db._files[index].Size;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace SharpCompress.Compressors.ADC
|
||||
position += chunkSize + 1;
|
||||
break;
|
||||
case TWO_BYTE:
|
||||
tempMs = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
tempMs = new MemoryStream();
|
||||
chunkSize = GetChunkSize((byte)readByte);
|
||||
tempMs.WriteByte((byte)readByte);
|
||||
tempMs.WriteByte((byte)input.ReadByte());
|
||||
@@ -173,7 +173,7 @@ namespace SharpCompress.Compressors.ADC
|
||||
}
|
||||
break;
|
||||
case THREE_BYTE:
|
||||
tempMs = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
tempMs = new MemoryStream();
|
||||
chunkSize = GetChunkSize((byte)readByte);
|
||||
tempMs.WriteByte((byte)readByte);
|
||||
tempMs.WriteByte((byte)input.ReadByte());
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace SharpCompress.Compressors.LZMA
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NETSTANDARD1_4 || NETSTANDARD2_0
|
||||
#if NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
using (IncrementalHash sha = IncrementalHash.CreateHash(HashAlgorithmName.SHA256))
|
||||
{
|
||||
byte[] counter = new byte[8];
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace SharpCompress.Compressors.PPMd.H
|
||||
|
||||
private void RestartModelRare()
|
||||
{
|
||||
Utility.Fill(_charMask, 0);
|
||||
new Span<int>(_charMask).Fill(0);
|
||||
SubAlloc.InitSubAllocator();
|
||||
_initRl = -(_maxOrder < 12 ? _maxOrder : 12) - 1;
|
||||
int addr = SubAlloc.AllocContext();
|
||||
@@ -228,7 +228,7 @@ namespace SharpCompress.Compressors.PPMd.H
|
||||
private void ClearMask()
|
||||
{
|
||||
_escCount = 1;
|
||||
Utility.Fill(_charMask, 0);
|
||||
new Span<int>(_charMask).Fill(0);
|
||||
}
|
||||
|
||||
internal bool DecodeInit(IRarUnpack unpackRead, int escChar)
|
||||
@@ -912,4 +912,4 @@ namespace SharpCompress.Compressors.PPMd.H
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace SharpCompress.Compressors.PPMd.H
|
||||
_freeListPos = _heapStart + allocSize;
|
||||
|
||||
//UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
|
||||
//assert(realAllocSize - tempMemBlockPos == RarMemBlock.size): realAllocSize
|
||||
//assert(realAllocSize - tempMemBlockPos == RarMemBlock.size): realAllocSize
|
||||
//+ + tempMemBlockPos + + RarMemBlock.size;
|
||||
|
||||
// Init freeList
|
||||
@@ -360,7 +360,7 @@ namespace SharpCompress.Compressors.PPMd.H
|
||||
public virtual void InitSubAllocator()
|
||||
{
|
||||
int i, k;
|
||||
Utility.Fill(_heap, _freeListPos, _freeListPos + SizeOfFreeList(), (byte)0);
|
||||
new Span<byte>(_heap, _freeListPos, SizeOfFreeList()).Fill(0);
|
||||
|
||||
_pText = _heapStart;
|
||||
|
||||
@@ -448,4 +448,4 @@ namespace SharpCompress.Compressors.PPMd.H
|
||||
UNIT_SIZE = Math.Max(PpmContext.SIZE, RarMemBlock.SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,10 +78,7 @@ namespace SharpCompress.Compressors.PPMd
|
||||
{
|
||||
if (_compress)
|
||||
{
|
||||
using (var stream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream())
|
||||
{
|
||||
_model.EncodeBlock(_stream, stream, true);
|
||||
}
|
||||
_model.EncodeBlock(_stream, new MemoryStream(), true);
|
||||
}
|
||||
}
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
@@ -32,9 +32,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
}
|
||||
}
|
||||
|
||||
public bool Suspended {
|
||||
public bool Suspended {
|
||||
get => suspended;
|
||||
set => suspended = value;
|
||||
set => suspended = value;
|
||||
}
|
||||
|
||||
public int Char
|
||||
@@ -139,12 +139,12 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
case 36: // alternative hash
|
||||
Unpack29(fileHeader.IsSolid);
|
||||
break;
|
||||
|
||||
|
||||
case 50: // rar 5.x compression
|
||||
Unpack5(fileHeader.IsSolid);
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
throw new InvalidFormatException("unknown rar compression version " + fileHeader.CompressionAlgorithm);
|
||||
}
|
||||
}
|
||||
@@ -729,13 +729,13 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
if (!solid)
|
||||
{
|
||||
tablesRead = false;
|
||||
Utility.Fill(oldDist, 0); // memset(oldDist,0,sizeof(OldDist));
|
||||
new Span<int>(oldDist).Fill(0); // memset(oldDist,0,sizeof(OldDist));
|
||||
|
||||
oldDistPtr = 0;
|
||||
lastDist = 0;
|
||||
lastLength = 0;
|
||||
|
||||
Utility.Fill(unpOldTable, (byte)0); // memset(UnpOldTable,0,sizeof(UnpOldTable));
|
||||
new Span<byte>(unpOldTable).Fill(0); // memset(UnpOldTable,0,sizeof(UnpOldTable));
|
||||
|
||||
unpPtr = 0;
|
||||
wrPtr = 0;
|
||||
@@ -837,7 +837,7 @@ WriteBorder=Math.Min(MaxWinSize,UNPACK_MAX_WRITE)&MaxWinMask;
|
||||
|
||||
if ((bitField & 0x4000) == 0)
|
||||
{
|
||||
Utility.Fill(unpOldTable, (byte)0); // memset(UnpOldTable,0,sizeof(UnpOldTable));
|
||||
new Span<byte>(unpOldTable).Fill(0); // memset(UnpOldTable,0,sizeof(UnpOldTable));
|
||||
}
|
||||
AddBits(2);
|
||||
|
||||
@@ -1109,7 +1109,7 @@ WriteBorder=Math.Min(MaxWinSize,UNPACK_MAX_WRITE)&MaxWinMask;
|
||||
oldFilterLengths[FiltPos] = StackFilter.BlockLength;
|
||||
|
||||
// memset(StackFilter->Prg.InitR,0,sizeof(StackFilter->Prg.InitR));
|
||||
Utility.Fill(StackFilter.Program.InitR, 0);
|
||||
new Span<int>(StackFilter.Program.InitR).Fill(0);
|
||||
StackFilter.Program.InitR[3] = RarVM.VM_GLOBALMEMADDR; // StackFilter->Prg.InitR[3]=VM_GLOBALMEMADDR;
|
||||
StackFilter.Program.InitR[4] = StackFilter.BlockLength;
|
||||
|
||||
@@ -1267,4 +1267,4 @@ WriteBorder=Math.Min(MaxWinSize,UNPACK_MAX_WRITE)&MaxWinMask;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Original author: Edmund Wagner
|
||||
* Creation date: 21.06.2007
|
||||
*
|
||||
* the unrar licence applies to all junrar source and binary distributions
|
||||
* the unrar licence applies to all junrar source and binary distributions
|
||||
* you are not allowed to use this source to re-create the RAR compression algorithm
|
||||
*/
|
||||
|
||||
@@ -652,9 +652,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
ChSetC[I] = ((~I + 1) & 0xff) << 8;
|
||||
}
|
||||
|
||||
Utility.Fill(NToPl, 0); // memset(NToPl,0,sizeof(NToPl));
|
||||
Utility.Fill(NToPlB, 0); // memset(NToPlB,0,sizeof(NToPlB));
|
||||
Utility.Fill(NToPlC, 0); // memset(NToPlC,0,sizeof(NToPlC));
|
||||
new Span<int>(NToPl).Fill(0); // memset(NToPl,0,sizeof(NToPl));
|
||||
new Span<int>(NToPlB).Fill(0); // memset(NToPlB,0,sizeof(NToPlB));
|
||||
new Span<int>(NToPlC).Fill(0); // memset(NToPlC,0,sizeof(NToPlC));
|
||||
corrHuff(ChSetB, NToPlB);
|
||||
}
|
||||
|
||||
@@ -670,7 +670,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
// & ~0xff) | I;
|
||||
}
|
||||
}
|
||||
Utility.Fill(NumToPlace, 0); // memset(NumToPlace,0,sizeof(NToPl));
|
||||
new Span<int>(NumToPlace).Fill(0); // memset(NumToPlace,0,sizeof(NToPl));
|
||||
for (I = 6; I >= 0; I--)
|
||||
{
|
||||
NumToPlace[I] = (7 - I) * 32;
|
||||
@@ -717,4 +717,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
wrPtr = unpPtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Original author: Edmund Wagner
|
||||
* Creation date: 21.06.2007
|
||||
*
|
||||
* the unrar licence applies to all junrar source and binary distributions
|
||||
* the unrar licence applies to all junrar source and binary distributions
|
||||
* you are not allowed to use this source to re-create the RAR compression algorithm
|
||||
*/
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
if (0 == (BitField & 0x4000))
|
||||
{
|
||||
// memset(UnpOldTable20,0,sizeof(UnpOldTable20));
|
||||
Utility.Fill(UnpOldTable20, (byte)0);
|
||||
new Span<byte>(UnpOldTable20).Fill(0);
|
||||
}
|
||||
AddBits(2);
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
AudV[3] = new AudioVariables();
|
||||
|
||||
// memset(UnpOldTable20,0,sizeof(UnpOldTable20));
|
||||
Utility.Fill(UnpOldTable20, (byte)0);
|
||||
new Span<byte>(UnpOldTable20).Fill(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,4 +521,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
return ((byte)Ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SharpCompress.Compressors.Rar.VM;
|
||||
using System;
|
||||
using SharpCompress.Compressors.Rar.VM;
|
||||
|
||||
namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
{
|
||||
@@ -186,9 +187,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
int i;
|
||||
long M, N;
|
||||
|
||||
Utility.Fill(lenCount, 0); // memset(LenCount,0,sizeof(LenCount));
|
||||
|
||||
Utility.Fill(dec.DecodeNum, 0); // memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));
|
||||
new Span<int>(dec.DecodeNum).Fill(0); // memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
@@ -217,4 +216,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1
|
||||
dec.MaxNum = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
|
||||
// Check TablesRead5 to be sure that we read tables at least once
|
||||
// regardless of current block header TablePresent flag.
|
||||
// So we can safefly use these tables below.
|
||||
if (!ReadBlockHeader(Inp,ref BlockHeader) ||
|
||||
if (!ReadBlockHeader(Inp,ref BlockHeader) ||
|
||||
!ReadTables(Inp,ref BlockHeader, ref BlockTables) || !TablesRead5)
|
||||
return;
|
||||
}
|
||||
@@ -45,8 +45,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
|
||||
|
||||
// We use 'while', because for empty block containing only Huffman table,
|
||||
// we'll be on the block border once again just after reading the table.
|
||||
while (Inp.InAddr>BlockHeader.BlockStart+BlockHeader.BlockSize-1 ||
|
||||
Inp.InAddr==BlockHeader.BlockStart+BlockHeader.BlockSize-1 &&
|
||||
while (Inp.InAddr>BlockHeader.BlockStart+BlockHeader.BlockSize-1 ||
|
||||
Inp.InAddr==BlockHeader.BlockStart+BlockHeader.BlockSize-1 &&
|
||||
Inp.InBit>=BlockHeader.BlockBitSize)
|
||||
{
|
||||
if (BlockHeader.LastBlockInFile)
|
||||
@@ -415,7 +415,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
|
||||
|
||||
// Choose the nearest among WriteBorder and WrPtr actual written border.
|
||||
// If border is equal to UnpPtr, it means that we have MaxWinSize data ahead.
|
||||
if (WriteBorder==UnpPtr ||
|
||||
if (WriteBorder==UnpPtr ||
|
||||
WrPtr!=UnpPtr && ((WrPtr-UnpPtr)&MaxWinMask)<((WriteBorder-UnpPtr)&MaxWinMask))
|
||||
WriteBorder=WrPtr;
|
||||
}
|
||||
@@ -563,11 +563,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
|
||||
if (!UnpReadBuf())
|
||||
return false;
|
||||
Inp.faddbits((uint)((8-Inp.InBit)&7));
|
||||
|
||||
|
||||
byte BlockFlags=(byte)(Inp.fgetbits()>>8);
|
||||
Inp.faddbits(8);
|
||||
uint ByteCount=(uint)(((BlockFlags>>3)&3)+1); // Block size byte count.
|
||||
|
||||
|
||||
if (ByteCount==4)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ public Unpack(/* ComprDataIO *DataIO */)
|
||||
|
||||
// Set the entire DecodeNum to zero.
|
||||
//memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));
|
||||
Utility.FillFast<ushort>(Dec.DecodeNum, 0);
|
||||
new Span<ushort>(Dec.DecodeNum).Fill(0);
|
||||
|
||||
// Initialize not really used entry for zero length code.
|
||||
Dec.DecodePos[0]=0;
|
||||
@@ -272,7 +272,7 @@ public Unpack(/* ComprDataIO *DataIO */)
|
||||
Dec.DecodeLen[I]=(uint)LeftAligned;
|
||||
|
||||
// Every item of this array contains the sum of all preceding items.
|
||||
// So it contains the start position in code list for every bit length.
|
||||
// So it contains the start position in code list for every bit length.
|
||||
Dec.DecodePos[I]=Dec.DecodePos[I-1]+LengthCount[I-1];
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ public Unpack(/* ComprDataIO *DataIO */)
|
||||
uint BitField=Code<<(int)(16-Dec.QuickBits);
|
||||
|
||||
// Prepare the table for quick decoding of bit lengths.
|
||||
|
||||
|
||||
// Find the upper limit for current bit field and adjust the bit length
|
||||
// accordingly if necessary.
|
||||
while (CurBitLength<Dec.DecodeLen.Length && BitField>=Dec.DecodeLen[CurBitLength])
|
||||
|
||||
@@ -190,12 +190,12 @@ namespace SharpCompress.Compressors.Rar.VM
|
||||
{
|
||||
//prg.GlobalData.Clear();
|
||||
// ->GlobalData.Add(dataSize+VM_FIXEDGLOBALSIZE);
|
||||
prg.GlobalData.SetSize(dataSize + VM_FIXEDGLOBALSIZE);
|
||||
prg.GlobalData.Capacity = dataSize + VM_FIXEDGLOBALSIZE;
|
||||
for (int i = 0; i < dataSize + VM_FIXEDGLOBALSIZE; i++)
|
||||
|
||||
// memcpy(&Prg->GlobalData[0],&Mem[VM_GLOBALMEMADDR],DataSize+VM_FIXEDGLOBALSIZE);
|
||||
{
|
||||
prg.GlobalData[i] = Mem[VM_GLOBALMEMADDR + i];
|
||||
prg.GlobalData.Add(Mem[VM_GLOBALMEMADDR + i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1449,4 +1449,4 @@ namespace SharpCompress.Compressors.Rar.VM
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.IO;
|
||||
using SharpCompress.Compressors.Filters;
|
||||
|
||||
namespace SharpCompress.IO
|
||||
@@ -8,7 +7,7 @@ namespace SharpCompress.IO
|
||||
internal class RewindableStream : Stream
|
||||
{
|
||||
private readonly Stream stream;
|
||||
private MemoryStream bufferStream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
private MemoryStream bufferStream = new MemoryStream();
|
||||
private bool isRewound;
|
||||
private bool isDisposed;
|
||||
|
||||
@@ -30,7 +29,6 @@ namespace SharpCompress.IO
|
||||
if (disposing)
|
||||
{
|
||||
stream.Dispose();
|
||||
bufferStream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +51,7 @@ namespace SharpCompress.IO
|
||||
bufferStream.TransferTo(buffer);
|
||||
//create new memorystream to allow proper resizing as memorystream could be a user provided buffer
|
||||
//https://github.com/adamhathcock/sharpcompress/issues/306
|
||||
bufferStream.Dispose();
|
||||
bufferStream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
bufferStream = new MemoryStream();
|
||||
buffer.Position = 0;
|
||||
buffer.TransferTo(bufferStream);
|
||||
bufferStream.Position = 0;
|
||||
|
||||
@@ -148,4 +148,4 @@ namespace SharpCompress
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
<AssemblyVersion>0.24.0</AssemblyVersion>
|
||||
<FileVersion>0.24.0</FileVersion>
|
||||
<Authors>Adam Hathcock</Authors>
|
||||
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net46;netstandard1.4;netstandard2.0</TargetFrameworks>
|
||||
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">netstandard1.3;netstandard2.0;netstandard2.1;net46</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AssemblyName>SharpCompress</AssemblyName>
|
||||
@@ -16,15 +17,14 @@
|
||||
<PackageId>SharpCompress</PackageId>
|
||||
<PackageTags>rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz</PackageTags>
|
||||
<PackageProjectUrl>https://github.com/adamhathcock/sharpcompress</PackageProjectUrl>
|
||||
<PackageLicense>https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt</PackageLicense>
|
||||
<PackageLicenseUrl>https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt</PackageLicenseUrl>
|
||||
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<Description>SharpCompress is a compression library for NET Standard 1.3/2.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</Description>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0" />
|
||||
<PackageReference Include="System.Buffers" Version="4.5.0" />
|
||||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.3.0" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" />
|
||||
<PackageReference Include="System.Memory" Version="4.5.3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -2,15 +2,12 @@ using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.IO;
|
||||
using SharpCompress.Readers;
|
||||
|
||||
namespace SharpCompress
|
||||
{
|
||||
internal static class Utility
|
||||
{
|
||||
public static readonly RecyclableMemoryStreamManager RECYCLABLE_MEMORY_STREAM_MANAGER = new RecyclableMemoryStreamManager();
|
||||
public static ReadOnlyCollection<T> ToReadOnly<T>(this ICollection<T> items)
|
||||
{
|
||||
return new ReadOnlyCollection<T>(items);
|
||||
@@ -46,78 +43,18 @@ namespace SharpCompress
|
||||
return (number >> bits) + (2L << ~bits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills the array with an specific value from an specific index to an specific index.
|
||||
/// </summary>
|
||||
/// <param name="array">The array to be filled.</param>
|
||||
/// <param name="fromindex">The first index to be filled.</param>
|
||||
/// <param name="toindex">The last index to be filled.</param>
|
||||
/// <param name="val">The value to fill the array with.</param>
|
||||
public static void Fill<T>(T[] array, int fromindex, int toindex, T val) where T : struct
|
||||
{
|
||||
if (array.Length == 0)
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
if (fromindex > toindex)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
if ((fromindex < 0) || array.Length < toindex)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
for (int index = (fromindex > 0) ? fromindex-- : fromindex; index < toindex; index++)
|
||||
{
|
||||
array[index] = val;
|
||||
}
|
||||
}
|
||||
public static void Memset(byte[] array, byte what, int length)
|
||||
{
|
||||
ref byte ptr = ref array[0];
|
||||
Unsafe.InitBlock(ref ptr, what, (uint)length);
|
||||
}
|
||||
=> new Span<byte>(array, 0, length).Fill(what);
|
||||
|
||||
public static void Memset<T>(T[] array, T what, int length)
|
||||
{
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
array[i] = what;
|
||||
}
|
||||
}
|
||||
|
||||
public static void FillFast<T>(T[] array, T val) where T : struct
|
||||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
public static void FillFast<T>(T[] array, int start, int length, T val) where T : struct
|
||||
{
|
||||
int toIndex = start + length;
|
||||
for (int i = start; i < toIndex; i++)
|
||||
{
|
||||
array[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fills the array with an specific value.
|
||||
/// </summary>
|
||||
/// <param name="array">The array to be filled.</param>
|
||||
/// <param name="val">The value to fill the array with.</param>
|
||||
public static void Fill<T>(T[] array, T val) where T : struct
|
||||
{
|
||||
Fill(array, 0, array.Length, val);
|
||||
}
|
||||
=> new Span<T>(array, 0, length).Fill(what);
|
||||
|
||||
public static void SetSize(this List<byte> list, int count)
|
||||
{
|
||||
if (count > list.Count)
|
||||
{
|
||||
// Ensure the list only needs to grow once
|
||||
list.Capacity = count;
|
||||
for (int i = list.Count; i < count; i++)
|
||||
{
|
||||
list.Add(0x0);
|
||||
@@ -125,18 +62,7 @@ namespace SharpCompress
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] temp = new byte[count];
|
||||
list.CopyTo(temp, 0);
|
||||
list.Clear();
|
||||
list.AddRange(temp);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddRange<T>(this ICollection<T> destination, IEnumerable<T> source)
|
||||
{
|
||||
foreach (T item in source)
|
||||
{
|
||||
destination.Add(item);
|
||||
list.RemoveRange(count, list.Count - count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,21 +300,5 @@ namespace SharpCompress
|
||||
{
|
||||
return source.Replace('\0', ' ').Trim();
|
||||
}
|
||||
|
||||
public static bool BinaryEquals(this byte[] source, byte[] target)
|
||||
{
|
||||
if (source.Length != target.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
if (source[i] != target[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.2</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AssemblyName>SharpCompress.Test</AssemblyName>
|
||||
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
@@ -12,7 +12,7 @@
|
||||
<ProjectReference Include="..\..\src\SharpCompress\SharpCompress.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="Xunit.SkippableFact" Version="1.3.12" />
|
||||
|
||||
Reference in New Issue
Block a user