Compare commits

..

4 Commits

Author SHA1 Message Date
Adam Hathcock
bd9417e74c Mark for 0.19 2017-12-12 11:17:57 +00:00
Adam Hathcock
694e869162 Use arraypool for transfer/skip (#326)
* Use arraypool for transfer/skip

* Merge fixes

* Remove redundant constant
2017-12-08 13:58:38 +00:00
Adam Hathcock
45845f8963 Add Circle CI build 2017-12-08 12:03:28 +00:00
Adam Hathcock
a8b6def76a Netcore2 (#302)
* Add netstandard 2.0 target and netcoreapp2.0 tests

* Update xunit

* set tests explicitly to netcore2

* update travis

* Don't say build as netcoreapp1.0

* try adding dotnet 1 too

* Remove .NET Core 1 support

* switch to circle

* update cake

* fix circle build

* try fix file ending test again

* Fix casing on files

* Another casing fix

* Add back netstandard1.0

* Finish adding netstandard 1.0 back

* Add netstandard1.3 back
2017-12-08 12:00:29 +00:00
4 changed files with 103 additions and 45 deletions

View File

@@ -54,13 +54,13 @@ Task("Test")
DotNetCoreTest(file.ToString(), settings);
settings = new DotNetCoreTestSettings
{
Configuration = "Release",
Framework = "netcoreapp2.0"
};
settings = new DotNetCoreTestSettings
{
Configuration = "Release",
Framework = "netcoreapp1.1"
};
DotNetCoreTest(file.ToString(), settings);
DotNetCoreTest(file.ToString(), settings);
}
});

View File

@@ -2,9 +2,9 @@
<PropertyGroup>
<AssemblyTitle>SharpCompress - Pure C# Decompression/Compression</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>0.18.2</VersionPrefix>
<AssemblyVersion>0.18.2.0</AssemblyVersion>
<FileVersion>0.18.2.0</FileVersion>
<VersionPrefix>0.19.0</VersionPrefix>
<AssemblyVersion>0.19.0.0</AssemblyVersion>
<FileVersion>0.19.0.0</FileVersion>
<Authors>Adam Hathcock</Authors>
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net45;net35;netstandard1.0;netstandard1.3;netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -24,4 +24,19 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
<DefineConstants>$(DefineConstants);NO_FILE;NO_CRYPTO;SILVERLIGHT</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Buffers" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Buffers" Version="4.4.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<PackageReference Include="System.Buffers" Version="4.4.0" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,7 @@
using System;
#if NETCORE || NET45
using System.Buffers;
#endif
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -7,7 +10,7 @@ using SharpCompress.Readers;
namespace SharpCompress
{
internal static class Utility
{
{
public static ReadOnlyCollection<T> ToReadOnly<T>(this IEnumerable<T> items)
{
return new ReadOnlyCollection<T>(items.ToList());
@@ -139,36 +142,54 @@ namespace SharpCompress
public static void Skip(this Stream source, long advanceAmount)
{
byte[] buffer = GetTransferByteArray();
int read = 0;
int readCount = 0;
do
try
{
readCount = buffer.Length;
if (readCount > advanceAmount)
int read = 0;
int readCount = 0;
do
{
readCount = (int)advanceAmount;
}
read = source.Read(buffer, 0, readCount);
if (read <= 0)
{
break;
}
advanceAmount -= read;
if (advanceAmount == 0)
{
break;
readCount = buffer.Length;
if (readCount > advanceAmount)
{
readCount = (int)advanceAmount;
}
read = source.Read(buffer, 0, readCount);
if (read <= 0)
{
break;
}
advanceAmount -= read;
if (advanceAmount == 0)
{
break;
}
}
while (true);
}
finally
{
#if NETCORE || NET45
ArrayPool<byte>.Shared.Return(buffer);
#endif
}
while (true);
}
public static void Skip(this Stream source)
{
byte[] buffer = GetTransferByteArray();
do
try
{
do
{
}
while (source.Read(buffer, 0, buffer.Length) == buffer.Length);
}
finally
{
#if NETCORE || NET45
ArrayPool<byte>.Shared.Return(buffer);
#endif
}
while (source.Read(buffer, 0, buffer.Length) == buffer.Length);
}
public static DateTime DosDateToDateTime(UInt16 iDate, UInt16 iTime)
@@ -233,30 +254,48 @@ namespace SharpCompress
public static long TransferTo(this Stream source, Stream destination)
{
byte[] array = GetTransferByteArray();
int count;
long total = 0;
while (ReadTransferBlock(source, array, out count))
try
{
total += count;
destination.Write(array, 0, count);
int count;
long total = 0;
while (ReadTransferBlock(source, array, out count))
{
total += count;
destination.Write(array, 0, count);
}
return total;
}
finally
{
#if NETCORE || NET45
ArrayPool<byte>.Shared.Return(array);
#endif
}
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))
try
{
total += count;
destination.Write(array, 0, count);
iterations++;
readerExtractionListener.FireEntryExtractionProgress(entry, total, iterations);
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;
}
finally
{
#if NETCORE || NET45
ArrayPool<byte>.Shared.Return(array);
#endif
}
return total;
}
private static bool ReadTransferBlock(Stream source, byte[] array, out int count)
@@ -266,7 +305,11 @@ namespace SharpCompress
private static byte[] GetTransferByteArray()
{
#if NETCORE || NET45
return ArrayPool<byte>.Shared.Rent(81920);
#else
return new byte[81920];
#endif
}
public static bool ReadFully(this Stream stream, byte[] buffer)

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp1.1;netcoreapp2.0</TargetFrameworks>
<AssemblyName>SharpCompress.Test</AssemblyName>
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>