mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
Compare commits
4 Commits
0.34.0
...
recycle-me
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6a6085d75 | ||
|
|
b5a897819d | ||
|
|
9e842ee8ec | ||
|
|
a04a0a5912 |
@@ -2,7 +2,7 @@ version: 2
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: microsoft/dotnet:2.2.104-sdk
|
||||
- image: mcr.microsoft.com/dotnet/core/sdk:2.2-alpine
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SharpCompress
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream).
|
||||
|
||||
|
||||
49
build.cake
49
build.cake
@@ -11,29 +11,23 @@ Task("Build")
|
||||
.IsDependentOn("Restore")
|
||||
.Does(() =>
|
||||
{
|
||||
var settings = new DotNetCoreBuildSettings
|
||||
{
|
||||
Framework = "netstandard1.4",
|
||||
Configuration = "Release",
|
||||
NoRestore = true
|
||||
};
|
||||
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
|
||||
if (IsRunningOnWindows())
|
||||
{
|
||||
MSBuild("./sharpcompress.sln", c =>
|
||||
{
|
||||
c.SetConfiguration("Release")
|
||||
.SetVerbosity(Verbosity.Minimal)
|
||||
.UseToolVersion(MSBuildToolVersion.VS2017);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var settings = new DotNetCoreBuildSettings
|
||||
{
|
||||
Framework = "netstandard1.3",
|
||||
Configuration = "Release",
|
||||
NoRestore = true
|
||||
};
|
||||
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
|
||||
settings.Framework = "netstandard2.0";
|
||||
settings.Framework = "net46";
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
}
|
||||
|
||||
settings.Framework = "netstandard2.0";
|
||||
DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings);
|
||||
});
|
||||
|
||||
Task("Test")
|
||||
@@ -55,16 +49,17 @@ Task("Test")
|
||||
Task("Pack")
|
||||
.IsDependentOn("Build")
|
||||
.Does(() =>
|
||||
{
|
||||
{
|
||||
if (IsRunningOnWindows())
|
||||
{
|
||||
MSBuild("src/SharpCompress/SharpCompress.csproj", c => c
|
||||
.SetConfiguration("Release")
|
||||
.SetVerbosity(Verbosity.Minimal)
|
||||
.UseToolVersion(MSBuildToolVersion.VS2017)
|
||||
.WithProperty("NoBuild", "true")
|
||||
.WithTarget("Pack"));
|
||||
}
|
||||
var settings = new DotNetCorePackSettings
|
||||
{
|
||||
Configuration = "Release",
|
||||
NoBuild = true
|
||||
};
|
||||
|
||||
DotNetCorePack("src/SharpCompress/SharpCompress.csproj", settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
Information("Skipping Pack as this is not Windows");
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace SharpCompress.Archives.Tar
|
||||
|
||||
using (var entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
using (var memoryStream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream())
|
||||
{
|
||||
entryStream.TransferTo(memoryStream);
|
||||
memoryStream.Position = 0;
|
||||
|
||||
@@ -1396,7 +1396,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
else
|
||||
{
|
||||
_stream = new MemoryStream();
|
||||
_stream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
}
|
||||
_rem = _db._files[index].Size;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace SharpCompress.Compressors.ADC
|
||||
position += chunkSize + 1;
|
||||
break;
|
||||
case TWO_BYTE:
|
||||
tempMs = new MemoryStream();
|
||||
tempMs = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
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 = new MemoryStream();
|
||||
tempMs = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
chunkSize = GetChunkSize((byte)readByte);
|
||||
tempMs.WriteByte((byte)readByte);
|
||||
tempMs.WriteByte((byte)input.ReadByte());
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace SharpCompress.Compressors.LZMA
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD2_0
|
||||
#if NETSTANDARD1_4 || NETSTANDARD2_0
|
||||
using (IncrementalHash sha = IncrementalHash.CreateHash(HashAlgorithmName.SHA256))
|
||||
{
|
||||
byte[] counter = new byte[8];
|
||||
|
||||
@@ -78,7 +78,10 @@ namespace SharpCompress.Compressors.PPMd
|
||||
{
|
||||
if (_compress)
|
||||
{
|
||||
_model.EncodeBlock(_stream, new MemoryStream(), true);
|
||||
using (var stream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream())
|
||||
{
|
||||
_model.EncodeBlock(_stream, stream, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.IO;
|
||||
using SharpCompress.Compressors.Filters;
|
||||
|
||||
namespace SharpCompress.IO
|
||||
@@ -7,7 +8,7 @@ namespace SharpCompress.IO
|
||||
internal class RewindableStream : Stream
|
||||
{
|
||||
private readonly Stream stream;
|
||||
private MemoryStream bufferStream = new MemoryStream();
|
||||
private MemoryStream bufferStream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
private bool isRewound;
|
||||
private bool isDisposed;
|
||||
|
||||
@@ -29,6 +30,7 @@ namespace SharpCompress.IO
|
||||
if (disposing)
|
||||
{
|
||||
stream.Dispose();
|
||||
bufferStream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +53,8 @@ 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 = new MemoryStream();
|
||||
bufferStream.Dispose();
|
||||
bufferStream = Utility.RECYCLABLE_MEMORY_STREAM_MANAGER.GetStream();
|
||||
buffer.Position = 0;
|
||||
buffer.TransferTo(bufferStream);
|
||||
bufferStream.Position = 0;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<AssemblyVersion>0.24.0</AssemblyVersion>
|
||||
<FileVersion>0.24.0</FileVersion>
|
||||
<Authors>Adam Hathcock</Authors>
|
||||
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">netstandard1.3;netstandard2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net46;netstandard1.4;netstandard2.0</TargetFrameworks>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<AssemblyName>SharpCompress</AssemblyName>
|
||||
@@ -16,7 +16,7 @@
|
||||
<PackageId>SharpCompress</PackageId>
|
||||
<PackageTags>rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz</PackageTags>
|
||||
<PackageProjectUrl>https://github.com/adamhathcock/sharpcompress</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt</PackageLicenseUrl>
|
||||
<PackageLicense>https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt</PackageLicense>
|
||||
<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>
|
||||
@@ -25,5 +25,6 @@
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -3,12 +3,14 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user