You've already forked linux-packaging-mono
Imported Upstream version 5.10.0.69
Former-commit-id: fc39669a0b707dd3c063977486506b6793da2890
This commit is contained in:
parent
d8f8abd549
commit
e2950ec768
@@ -93,6 +93,8 @@ namespace System.IO.Compression
|
||||
public System.DateTimeOffset LastWriteTime { get { throw null; } set { } }
|
||||
public long Length { get { throw null; } }
|
||||
public string Name { get { throw null; } }
|
||||
[CLSCompliant(false)]
|
||||
public uint Crc32 { get { throw null; } }
|
||||
public void Delete() { }
|
||||
public System.IO.Stream Open() { throw null; }
|
||||
public override string ToString() { throw null; }
|
||||
|
@@ -1,7 +0,0 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Security;
|
||||
|
||||
[assembly: SecurityTransparentAttribute()]
|
@@ -11,26 +11,26 @@ internal static partial class Interop
|
||||
{
|
||||
private static readonly byte[] ZLibVersion = { (byte)'1', (byte)'.', (byte)'2', (byte)'.', (byte)'3', 0 };
|
||||
|
||||
[DllImport(Libraries.Zlib)]
|
||||
[DllImport(Libraries.CompressionNative)]
|
||||
private extern static unsafe int deflateInit2_(byte* stream, int level, int method, int windowBits, int memLevel, int strategy,
|
||||
byte* version, int stream_size);
|
||||
|
||||
[DllImport(Libraries.Zlib)]
|
||||
[DllImport(Libraries.CompressionNative)]
|
||||
private extern static unsafe int deflate(byte* stream, int flush);
|
||||
|
||||
[DllImport(Libraries.Zlib)]
|
||||
[DllImport(Libraries.CompressionNative)]
|
||||
private extern static unsafe int deflateEnd(byte* strm);
|
||||
|
||||
[DllImport(Libraries.Zlib)]
|
||||
[DllImport(Libraries.CompressionNative)]
|
||||
internal extern static unsafe uint crc32(uint crc, byte* buffer, int len);
|
||||
|
||||
[DllImport(Libraries.Zlib)]
|
||||
[DllImport(Libraries.CompressionNative)]
|
||||
private extern static unsafe int inflateInit2_(byte* stream, int windowBits, byte* version, int stream_size);
|
||||
|
||||
[DllImport(Libraries.Zlib)]
|
||||
[DllImport(Libraries.CompressionNative)]
|
||||
private extern static unsafe int inflate(byte* stream, int flush);
|
||||
|
||||
[DllImport(Libraries.Zlib)]
|
||||
[DllImport(Libraries.CompressionNative)]
|
||||
private extern static unsafe int inflateEnd(byte* stream);
|
||||
|
||||
internal static unsafe ZLibNative.ErrorCode DeflateInit2_(
|
||||
|
@@ -1,5 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
@@ -251,6 +310,6 @@
|
||||
<value>Zip 64 End of Central Directory Record not where indicated.</value>
|
||||
</data>
|
||||
<data name="Argument_InvalidPathChars" xml:space="preserve">
|
||||
<value>Illegal characters in path.</value>
|
||||
<value>Illegal characters in path '{0}'.</value>
|
||||
</data>
|
||||
</root>
|
@@ -55,7 +55,6 @@
|
||||
<Compile Include="System\IO\Compression\DeflateZLib\Inflater.cs" />
|
||||
<Compile Include="System\IO\Compression\DeflateZLib\ZLibException.cs" />
|
||||
<Compile Include="System\IO\Compression\DeflateZLib\ZLibNative.cs" />
|
||||
<Compile Include="System\IO\Compression\ZLibException.Serialization.cs" />
|
||||
<Compile Include="System\IO\Compression\ZipArchiveEntry.netcoreapp.cs" />
|
||||
<Compile Include="System\IO\Compression\ZipCustomStreams.netcoreapp.cs" />
|
||||
<Compile Include="System\IO\Compression\PositionPreservingWriteOnlyStreamWrapper.netcoreapp.cs" />
|
||||
@@ -101,9 +100,9 @@
|
||||
<ItemGroup Condition="'$(TargetGroup)' != 'netfx'">
|
||||
<Reference Include="System.Buffers" />
|
||||
<Reference Include="System.Collections" />
|
||||
<Reference Include="System.Diagnostics.Contracts" />
|
||||
<Reference Include="System.Diagnostics.Debug" />
|
||||
<Reference Include="System.Diagnostics.Tools" />
|
||||
<Reference Include="System.Memory" />
|
||||
<Reference Include="System.Resources.ResourceManager" />
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.Extensions" />
|
||||
@@ -112,7 +111,6 @@
|
||||
<Reference Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'netfx'">
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
|
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.IO.Compression
|
||||
{
|
||||
@@ -12,7 +13,7 @@ namespace System.IO.Compression
|
||||
public static unsafe uint UpdateCrc32(uint crc32, byte[] buffer, int offset, int length)
|
||||
{
|
||||
Debug.Assert((buffer != null) && (offset >= 0) && (length >= 0) && (offset <= buffer.Length - length));
|
||||
fixed (byte* bufferPtr = buffer)
|
||||
fixed (byte* bufferPtr = &buffer[offset])
|
||||
{
|
||||
return Interop.zlib.crc32(crc32, bufferPtr, length);
|
||||
}
|
||||
@@ -20,7 +21,7 @@ namespace System.IO.Compression
|
||||
|
||||
public static unsafe uint UpdateCrc32(uint crc32, ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
fixed (byte* bufferPtr = &buffer.DangerousGetPinnableReference())
|
||||
fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer))
|
||||
{
|
||||
return Interop.zlib.crc32(crc32, bufferPtr, buffer.Length);
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ namespace System.IO.Compression
|
||||
StartIndex = state._startIndex;
|
||||
}
|
||||
|
||||
internal struct InputState
|
||||
internal readonly struct InputState
|
||||
{
|
||||
internal readonly int _count;
|
||||
internal readonly int _startIndex;
|
||||
|
@@ -106,7 +106,7 @@ namespace System.IO.Compression
|
||||
_bitCount = state._bitCount;
|
||||
}
|
||||
|
||||
internal struct BufferState
|
||||
internal readonly struct BufferState
|
||||
{
|
||||
internal readonly int _pos; // position
|
||||
internal readonly uint _bitBuf; // store uncomplete bits
|
||||
|
@@ -5,6 +5,7 @@
|
||||
using System.Buffers;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -270,8 +271,6 @@ namespace System.IO.Compression
|
||||
|
||||
if (_inflater.Finished())
|
||||
{
|
||||
// if we finished decompressing, we can't have anything left in the outputwindow.
|
||||
Debug.Assert(_inflater.AvailableOutput == 0, "We should have copied all stuff out!");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -495,7 +494,7 @@ namespace System.IO.Compression
|
||||
unsafe
|
||||
{
|
||||
// Pass new bytes through deflater and write them too:
|
||||
fixed (byte* bufferPtr = &source.DangerousGetPinnableReference())
|
||||
fixed (byte* bufferPtr = &MemoryMarshal.GetReference(source))
|
||||
{
|
||||
_deflater.SetInput(bufferPtr, source.Length);
|
||||
WriteDeflaterOutput();
|
||||
@@ -844,7 +843,6 @@ namespace System.IO.Compression
|
||||
Debug.Assert(oldValue == 1, $"Expected {nameof(_activeAsyncOperation)} to be 1, got {oldValue}");
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static void ThrowInvalidBeginCall()
|
||||
{
|
||||
throw new InvalidOperationException(SR.InvalidBeginCall);
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
using System.Buffers;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Security;
|
||||
|
||||
using ZErrorCode = System.IO.Compression.ZLibNative.ErrorCode;
|
||||
@@ -75,7 +74,6 @@ namespace System.IO.Compression
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!_isDisposed)
|
||||
@@ -93,7 +91,7 @@ namespace System.IO.Compression
|
||||
internal unsafe void SetInput(ReadOnlyMemory<byte> inputBuffer)
|
||||
{
|
||||
Debug.Assert(NeedsInput(), "We have something left in previous input!");
|
||||
Debug.Assert(_inputBufferHandle.PinnedPointer == null);
|
||||
Debug.Assert(!_inputBufferHandle.HasPointer);
|
||||
|
||||
if (0 == inputBuffer.Length)
|
||||
{
|
||||
@@ -104,7 +102,7 @@ namespace System.IO.Compression
|
||||
{
|
||||
_inputBufferHandle = inputBuffer.Retain(pin: true);
|
||||
|
||||
_zlibStream.NextIn = (IntPtr)_inputBufferHandle.PinnedPointer;
|
||||
_zlibStream.NextIn = (IntPtr)_inputBufferHandle.Pointer;
|
||||
_zlibStream.AvailIn = (uint)inputBuffer.Length;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +111,7 @@ namespace System.IO.Compression
|
||||
{
|
||||
Debug.Assert(NeedsInput(), "We have something left in previous input!");
|
||||
Debug.Assert(inputBufferPtr != null);
|
||||
Debug.Assert(_inputBufferHandle.PinnedPointer == null);
|
||||
Debug.Assert(!_inputBufferHandle.HasPointer);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
@@ -129,8 +127,6 @@ namespace System.IO.Compression
|
||||
|
||||
internal int GetDeflateOutput(byte[] outputBuffer)
|
||||
{
|
||||
Contract.Ensures(Contract.Result<int>() >= 0 && Contract.Result<int>() <= outputBuffer.Length);
|
||||
|
||||
Debug.Assert(null != outputBuffer, "Can't pass in a null output buffer!");
|
||||
Debug.Assert(!NeedsInput(), "GetDeflateOutput should only be called after providing input");
|
||||
|
||||
@@ -173,15 +169,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
Debug.Assert(null != outputBuffer, "Can't pass in a null output buffer!");
|
||||
Debug.Assert(outputBuffer.Length > 0, "Can't pass in an empty output buffer!");
|
||||
Debug.Assert(NeedsInput(), "We have something left in previous input!");
|
||||
unsafe
|
||||
{
|
||||
Debug.Assert(_inputBufferHandle.PinnedPointer == null);
|
||||
}
|
||||
|
||||
// Note: we require that NeedsInput() == true, i.e. that 0 == _zlibStream.AvailIn.
|
||||
// If there is still input left we should never be getting here; instead we
|
||||
// should be calling GetDeflateOutput.
|
||||
|
||||
ZErrorCode errC = ReadDeflateOutput(outputBuffer, ZFlushCode.Finish, out bytesRead);
|
||||
return errC == ZErrorCode.StreamEnd;
|
||||
@@ -195,10 +182,8 @@ namespace System.IO.Compression
|
||||
Debug.Assert(null != outputBuffer, "Can't pass in a null output buffer!");
|
||||
Debug.Assert(outputBuffer.Length > 0, "Can't pass in an empty output buffer!");
|
||||
Debug.Assert(NeedsInput(), "We have something left in previous input!");
|
||||
unsafe
|
||||
{
|
||||
Debug.Assert(_inputBufferHandle.PinnedPointer == null);
|
||||
}
|
||||
Debug.Assert(!_inputBufferHandle.HasPointer);
|
||||
|
||||
|
||||
// Note: we require that NeedsInput() == true, i.e. that 0 == _zlibStream.AvailIn.
|
||||
// If there is still input left we should never be getting here; instead we
|
||||
@@ -217,7 +202,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
private void DeflateInit(ZLibNative.CompressionLevel compressionLevel, int windowBits, int memLevel,
|
||||
ZLibNative.CompressionStrategy strategy)
|
||||
{
|
||||
@@ -251,7 +235,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
private ZErrorCode Deflate(ZFlushCode flushCode)
|
||||
{
|
||||
ZErrorCode errC;
|
||||
|
@@ -39,7 +39,7 @@ namespace System.IO.Compression
|
||||
/// <summary>
|
||||
/// Returns true if the end of the stream has been reached.
|
||||
/// </summary>
|
||||
public bool Finished() => _finished && _zlibStream.AvailIn == 0 && _zlibStream.AvailOut == 0;
|
||||
public bool Finished() => _finished;
|
||||
|
||||
public unsafe bool Inflate(out byte b)
|
||||
{
|
||||
@@ -70,7 +70,7 @@ namespace System.IO.Compression
|
||||
if (destination.Length == 0)
|
||||
return 0;
|
||||
|
||||
fixed (byte* bufPtr = &destination.DangerousGetPinnableReference())
|
||||
fixed (byte* bufPtr = &MemoryMarshal.GetReference(destination))
|
||||
{
|
||||
return InflateVerified(bufPtr, destination.Length);
|
||||
}
|
||||
@@ -119,7 +119,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!_isDisposed)
|
||||
@@ -148,7 +147,6 @@ namespace System.IO.Compression
|
||||
/// <summary>
|
||||
/// Creates the ZStream that will handle inflation.
|
||||
/// </summary>
|
||||
[SecuritySafeCritical]
|
||||
private void InflateInit(int windowBits)
|
||||
{
|
||||
ZLibNative.ErrorCode error;
|
||||
@@ -200,7 +198,6 @@ namespace System.IO.Compression
|
||||
/// <summary>
|
||||
/// Wrapper around the ZLib inflate function
|
||||
/// </summary>
|
||||
[SecuritySafeCritical]
|
||||
private ZLibNative.ErrorCode Inflate(ZLibNative.FlushCode flushCode)
|
||||
{
|
||||
ZLibNative.ErrorCode errC;
|
||||
|
@@ -2,20 +2,20 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Security;
|
||||
|
||||
using ZErrorCode = System.IO.Compression.ZLibNative.ErrorCode;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace System.IO.Compression
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the exception that is thrown when a ZLib returns an error code indicating an unrecoverable error.
|
||||
/// </summary>
|
||||
internal partial class ZLibException : IOException
|
||||
[Serializable]
|
||||
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
public class ZLibException : IOException, ISerializable
|
||||
{
|
||||
private readonly string _zlibErrorContext = string.Empty;
|
||||
private readonly string _zlibErrorMessage = string.Empty;
|
||||
private readonly ZErrorCode _zlibErrorCode = ZErrorCode.Ok;
|
||||
private readonly ZLibNative.ErrorCode _zlibErrorCode = ZLibNative.ErrorCode.Ok;
|
||||
|
||||
/// <summary>
|
||||
/// This is the preferred constructor to use.
|
||||
@@ -28,7 +28,7 @@ namespace System.IO.Compression
|
||||
public ZLibException(string message, string zlibErrorContext, int zlibErrorCode, string zlibErrorMessage) : base(message)
|
||||
{
|
||||
_zlibErrorContext = zlibErrorContext;
|
||||
_zlibErrorCode = (ZErrorCode)zlibErrorCode;
|
||||
_zlibErrorCode = (ZLibNative.ErrorCode)zlibErrorCode;
|
||||
_zlibErrorMessage = zlibErrorMessage;
|
||||
}
|
||||
|
||||
@@ -47,5 +47,25 @@ namespace System.IO.Compression
|
||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
||||
/// <param name="inner">The exception that is the cause of the current exception, or a <code>null</code>.</param>
|
||||
public ZLibException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new ZLibException with serialized data.
|
||||
/// </summary>
|
||||
/// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
|
||||
/// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
|
||||
protected ZLibException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
_zlibErrorContext = info.GetString("zlibErrorContext");
|
||||
_zlibErrorCode = (ZLibNative.ErrorCode)info.GetInt32("zlibErrorCode");
|
||||
_zlibErrorMessage = info.GetString("zlibErrorMessage");
|
||||
}
|
||||
|
||||
void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(si, context);
|
||||
si.AddValue("zlibErrorContext", _zlibErrorContext);
|
||||
si.AddValue("zlibErrorCode", (int)_zlibErrorCode);
|
||||
si.AddValue("zlibErrorMessage", _zlibErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,7 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
@@ -168,14 +167,12 @@ namespace System.IO.Compression
|
||||
/// <code>false</code>, which can for instance happen if the underlying ZLib <code>XxxxEnd</code>
|
||||
/// routines return an failure error code.
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public sealed class ZLibStreamHandle : SafeHandle
|
||||
{
|
||||
public enum State { NotInitialized, InitializedForDeflate, InitializedForInflate, Disposed }
|
||||
|
||||
private ZStream _zStream;
|
||||
|
||||
[SecurityCritical]
|
||||
private volatile State _initializationState;
|
||||
|
||||
|
||||
@@ -191,19 +188,15 @@ namespace System.IO.Compression
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
[SecurityCritical]
|
||||
get { return handle == new IntPtr(-1); }
|
||||
}
|
||||
|
||||
public State InitializationState
|
||||
{
|
||||
[Pure]
|
||||
[SecurityCritical]
|
||||
get { return _initializationState; }
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
switch (InitializationState)
|
||||
@@ -218,30 +211,28 @@ namespace System.IO.Compression
|
||||
|
||||
public IntPtr NextIn
|
||||
{
|
||||
[SecurityCritical] get { return _zStream.nextIn; }
|
||||
[SecurityCritical] set { _zStream.nextIn = value; }
|
||||
get { return _zStream.nextIn; }
|
||||
set { _zStream.nextIn = value; }
|
||||
}
|
||||
|
||||
public uint AvailIn
|
||||
{
|
||||
[SecurityCritical] get { return _zStream.availIn; }
|
||||
[SecurityCritical] set { _zStream.availIn = value; }
|
||||
get { return _zStream.availIn; }
|
||||
set { _zStream.availIn = value; }
|
||||
}
|
||||
|
||||
public IntPtr NextOut
|
||||
{
|
||||
[SecurityCritical] get { return _zStream.nextOut; }
|
||||
[SecurityCritical] set { _zStream.nextOut = value; }
|
||||
get { return _zStream.nextOut; }
|
||||
set { _zStream.nextOut = value; }
|
||||
}
|
||||
|
||||
public uint AvailOut
|
||||
{
|
||||
[SecurityCritical] get { return _zStream.availOut; }
|
||||
[SecurityCritical] set { _zStream.availOut = value; }
|
||||
get { return _zStream.availOut; }
|
||||
set { _zStream.availOut = value; }
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[SecurityCritical]
|
||||
private void EnsureNotDisposed()
|
||||
{
|
||||
if (InitializationState == State.Disposed)
|
||||
@@ -249,8 +240,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[Pure]
|
||||
[SecurityCritical]
|
||||
private void EnsureState(State requiredState)
|
||||
{
|
||||
if (InitializationState != requiredState)
|
||||
@@ -258,7 +247,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
public ErrorCode DeflateInit2_(CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy)
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
@@ -271,7 +259,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
public ErrorCode Deflate(FlushCode flush)
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
@@ -280,7 +267,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
public ErrorCode DeflateEnd()
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
@@ -293,7 +279,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
public ErrorCode InflateInit2_(int windowBits)
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
@@ -306,7 +291,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
public ErrorCode Inflate(FlushCode flush)
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
@@ -315,7 +299,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
public ErrorCode InflateEnd()
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
@@ -328,11 +311,9 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
// This can work even after XxflateEnd().
|
||||
[SecurityCritical]
|
||||
public string GetErrorMessage() => _zStream.msg != ZNullPtr ? Marshal.PtrToStringAnsi(_zStream.msg) : string.Empty;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public static ErrorCode CreateZLibStreamForDeflate(out ZLibStreamHandle zLibStreamHandle, CompressionLevel level,
|
||||
int windowBits, int memLevel, CompressionStrategy strategy)
|
||||
{
|
||||
@@ -341,7 +322,6 @@ namespace System.IO.Compression
|
||||
}
|
||||
|
||||
|
||||
[SecurityCritical]
|
||||
public static ErrorCode CreateZLibStreamForInflate(out ZLibStreamHandle zLibStreamHandle, int windowBits)
|
||||
{
|
||||
zLibStreamHandle = new ZLibStreamHandle();
|
||||
|
@@ -1,27 +0,0 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace System.IO.Compression
|
||||
{
|
||||
[Serializable]
|
||||
internal partial class ZLibException : IOException, ISerializable
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new ZLibException with serialized data.
|
||||
/// </summary>
|
||||
/// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
|
||||
/// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
|
||||
protected ZLibException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(si, context);
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,7 +8,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
|
||||
namespace System.IO.Compression
|
||||
@@ -123,8 +122,6 @@ namespace System.IO.Compression
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
|
||||
Contract.EndContractBlock();
|
||||
|
||||
EntryNameEncoding = entryNameEncoding;
|
||||
Init(stream, mode, leaveOpen);
|
||||
}
|
||||
@@ -139,8 +136,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<ReadOnlyCollection<ZipArchiveEntry>>() != null);
|
||||
|
||||
if (_mode == ZipArchiveMode.Create)
|
||||
throw new NotSupportedException(SR.EntriesInCreateMode);
|
||||
|
||||
@@ -158,11 +153,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(
|
||||
Contract.Result<ZipArchiveMode>() == ZipArchiveMode.Create
|
||||
|| Contract.Result<ZipArchiveMode>() == ZipArchiveMode.Read
|
||||
|| Contract.Result<ZipArchiveMode>() == ZipArchiveMode.Update);
|
||||
|
||||
return _mode;
|
||||
}
|
||||
}
|
||||
@@ -184,9 +174,6 @@ namespace System.IO.Compression
|
||||
/// <returns>A wrapper for the newly created file entry in the archive.</returns>
|
||||
public ZipArchiveEntry CreateEntry(string entryName)
|
||||
{
|
||||
Contract.Ensures(Contract.Result<ZipArchiveEntry>() != null);
|
||||
Contract.EndContractBlock();
|
||||
|
||||
return DoCreateEntry(entryName, null);
|
||||
}
|
||||
|
||||
@@ -202,9 +189,6 @@ namespace System.IO.Compression
|
||||
/// <returns>A wrapper for the newly created file entry in the archive.</returns>
|
||||
public ZipArchiveEntry CreateEntry(string entryName, CompressionLevel compressionLevel)
|
||||
{
|
||||
Contract.Ensures(Contract.Result<ZipArchiveEntry>() != null);
|
||||
Contract.EndContractBlock();
|
||||
|
||||
return DoCreateEntry(entryName, compressionLevel);
|
||||
}
|
||||
|
||||
@@ -261,7 +245,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
if (entryName == null)
|
||||
throw new ArgumentNullException(nameof(entryName));
|
||||
Contract.EndContractBlock();
|
||||
|
||||
if (_mode == ZipArchiveMode.Create)
|
||||
throw new NotSupportedException(SR.EntriesInCreateMode);
|
||||
@@ -319,8 +302,6 @@ namespace System.IO.Compression
|
||||
|
||||
private ZipArchiveEntry DoCreateEntry(string entryName, CompressionLevel? compressionLevel)
|
||||
{
|
||||
Contract.Ensures(Contract.Result<ZipArchiveEntry>() != null);
|
||||
|
||||
if (entryName == null)
|
||||
throw new ArgumentNullException(nameof(entryName));
|
||||
|
||||
|
@@ -5,7 +5,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
|
||||
namespace System.IO.Compression
|
||||
@@ -145,6 +144,9 @@ namespace System.IO.Compression
|
||||
/// </summary>
|
||||
public ZipArchive Archive => _archive;
|
||||
|
||||
[CLSCompliant(false)]
|
||||
public uint Crc32 => _crc32;
|
||||
|
||||
/// <summary>
|
||||
/// The compressed size of the entry. If the archive that the entry belongs to is in Create mode, attempts to get this property will always throw an exception. If the archive that the entry belongs to is in update mode, this property will only be valid if the entry has not been opened.
|
||||
/// </summary>
|
||||
@@ -153,8 +155,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<long>() >= 0);
|
||||
|
||||
if (_everOpenedForWrite)
|
||||
throw new InvalidOperationException(SR.LengthAfterWrite);
|
||||
return _compressedSize;
|
||||
@@ -181,7 +181,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<string>() != null);
|
||||
return _storedEntryName;
|
||||
}
|
||||
|
||||
@@ -242,8 +241,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<long>() >= 0);
|
||||
|
||||
if (_everOpenedForWrite)
|
||||
throw new InvalidOperationException(SR.LengthAfterWrite);
|
||||
return _uncompressedSize;
|
||||
@@ -288,8 +285,6 @@ namespace System.IO.Compression
|
||||
/// <exception cref="ObjectDisposedException">The ZipArchive that this entry belongs to has been disposed.</exception>
|
||||
public Stream Open()
|
||||
{
|
||||
Contract.Ensures(Contract.Result<Stream>() != null);
|
||||
|
||||
ThrowIfInvalidArchive();
|
||||
|
||||
switch (_archive.Mode)
|
||||
@@ -311,8 +306,6 @@ namespace System.IO.Compression
|
||||
/// <returns>FullName of the entry</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
Contract.Ensures(Contract.Result<string>() != null);
|
||||
|
||||
return FullName;
|
||||
}
|
||||
|
||||
@@ -1117,8 +1110,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<long>() >= 0);
|
||||
|
||||
ThrowIfDisposed();
|
||||
return _position;
|
||||
}
|
||||
@@ -1170,7 +1161,6 @@ namespace System.IO.Compression
|
||||
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentNeedNonNegative);
|
||||
if ((buffer.Length - offset) < count)
|
||||
throw new ArgumentException(SR.OffsetLengthInvalid);
|
||||
Contract.EndContractBlock();
|
||||
|
||||
ThrowIfDisposed();
|
||||
Debug.Assert(CanWrite);
|
||||
|
@@ -371,7 +371,7 @@ namespace System.IO.Compression
|
||||
}
|
||||
}
|
||||
|
||||
internal struct ZipLocalFileHeader
|
||||
internal readonly struct ZipLocalFileHeader
|
||||
{
|
||||
public const uint DataDescriptorSignature = 0x08074B50;
|
||||
public const uint SignatureConstant = 0x04034B50;
|
||||
|
@@ -2,7 +2,6 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace System.IO.Compression
|
||||
@@ -168,8 +167,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<long>() >= 0);
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
return _endInSuperStream - _startInSuperStream;
|
||||
@@ -180,8 +177,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<long>() >= 0);
|
||||
|
||||
ThrowIfDisposed();
|
||||
|
||||
return _positionInSuperStream - _startInSuperStream;
|
||||
@@ -329,7 +324,6 @@ namespace System.IO.Compression
|
||||
{
|
||||
get
|
||||
{
|
||||
Contract.Ensures(Contract.Result<long>() >= 0);
|
||||
ThrowIfDisposed();
|
||||
return _position;
|
||||
}
|
||||
@@ -381,7 +375,6 @@ namespace System.IO.Compression
|
||||
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentNeedNonNegative);
|
||||
if ((buffer.Length - offset) < count)
|
||||
throw new ArgumentException(SR.OffsetLengthInvalid);
|
||||
Contract.EndContractBlock();
|
||||
|
||||
// if we're not actually writing anything, we don't want to trigger as if we did write something
|
||||
ThrowIfDisposed();
|
||||
|
@@ -1,264 +0,0 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace System.IO.Compression.Tests
|
||||
{
|
||||
public abstract class CompressionStreamAsyncTestBase
|
||||
{
|
||||
public abstract bool StripHeaders { get; }
|
||||
public abstract Task<int> ReadAsync(Stream unzip, byte[] buffer, int offset, int count);
|
||||
public abstract Task WriteAsync(Stream unzip, byte[] buffer, int offset, int count);
|
||||
public abstract Stream CreateStream(Stream stream, CompressionMode mode);
|
||||
public abstract Stream CreateStream(Stream stream, CompressionMode mode, bool leaveOpen);
|
||||
|
||||
protected static string gzTestFile(string fileName) { return Path.Combine("GZTestData", fileName); }
|
||||
|
||||
[Fact]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Full Framework Flush is a no-op.")]
|
||||
public async Task OverlappingFlushAsync_DuringFlushAsync()
|
||||
{
|
||||
byte[] buffer = null;
|
||||
string testFilePath = gzTestFile("GZTestDocument.pdf");
|
||||
using (var origStream = await LocalMemoryStream.readAppFileAsync(testFilePath))
|
||||
{
|
||||
buffer = origStream.ToArray();
|
||||
}
|
||||
|
||||
using (var writeStream = new ManualSyncMemoryStream(false))
|
||||
using (var zip = CreateStream(writeStream, CompressionMode.Compress))
|
||||
{
|
||||
Task task = null;
|
||||
try
|
||||
{
|
||||
writeStream.manualResetEvent.Set();
|
||||
await WriteAsync(zip, buffer, 0, buffer.Length);
|
||||
writeStream.manualResetEvent.Reset();
|
||||
writeStream.WriteHit = false;
|
||||
task = zip.FlushAsync();
|
||||
Assert.True(writeStream.WriteHit);
|
||||
Assert.Throws<InvalidOperationException>(() => { zip.FlushAsync(); }); // "overlapping flushes"
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unblock Async operations
|
||||
writeStream.manualResetEvent.Set();
|
||||
// The original WriteAsync should be able to complete
|
||||
Assert.True(task.Wait(100 * 500));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Full Framework Flush is a no-op.")]
|
||||
public async Task OverlappingFlushAsync_DuringWriteAsync()
|
||||
{
|
||||
byte[] buffer = null;
|
||||
string testFilePath = gzTestFile("GZTestDocument.pdf");
|
||||
using (var origStream = await LocalMemoryStream.readAppFileAsync(testFilePath))
|
||||
{
|
||||
buffer = origStream.ToArray();
|
||||
}
|
||||
|
||||
using (var writeStream = new ManualSyncMemoryStream(false))
|
||||
using (var zip = CreateStream(writeStream, CompressionMode.Compress))
|
||||
{
|
||||
Task task = null;
|
||||
try
|
||||
{
|
||||
task = WriteAsync(zip, buffer, 0, buffer.Length);
|
||||
Assert.True(writeStream.WriteHit);
|
||||
Assert.Throws<InvalidOperationException>(() => { zip.FlushAsync(); }); // "overlapping flushes"
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unblock Async operations
|
||||
writeStream.manualResetEvent.Set();
|
||||
// The original WriteAsync should be able to complete
|
||||
Assert.True(task.Wait(100 * 500));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Full Framework Flush is a no-op.")]
|
||||
public async Task OverlappingFlushAsync_DuringReadAsync()
|
||||
{
|
||||
byte[] buffer = new byte[32];
|
||||
string testFilePath = gzTestFile("GZTestDocument.pdf.gz");
|
||||
using (var readStream = await ManualSyncMemoryStream.GetStreamFromFileAsync(testFilePath, false, StripHeaders))
|
||||
using (var unzip = CreateStream(readStream, CompressionMode.Decompress, true))
|
||||
{
|
||||
Task task = null;
|
||||
try
|
||||
{
|
||||
readStream.manualResetEvent.Reset();
|
||||
readStream.ReadHit = false;
|
||||
task = ReadAsync(unzip, buffer, 0, 32);
|
||||
Assert.True(readStream.ReadHit);
|
||||
Assert.Throws<InvalidOperationException>(() => { unzip.FlushAsync(); }); // "overlapping read"
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unblock Async operations
|
||||
readStream.manualResetEvent.Set();
|
||||
// The original ReadAsync should be able to complete
|
||||
Assert.True(task.Wait(100 * 500));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OverlappingWriteAsync()
|
||||
{
|
||||
byte[] buffer = null;
|
||||
string testFilePath = gzTestFile("GZTestDocument.pdf");
|
||||
using (var origStream = await LocalMemoryStream.readAppFileAsync(testFilePath))
|
||||
{
|
||||
buffer = origStream.ToArray();
|
||||
}
|
||||
|
||||
using (var writeStream = new ManualSyncMemoryStream(false))
|
||||
using (var zip = CreateStream(writeStream, CompressionMode.Compress))
|
||||
{
|
||||
Task task = null;
|
||||
try
|
||||
{
|
||||
task = WriteAsync(zip, buffer, 0, buffer.Length); // write needs to be bigger than the internal write buffer
|
||||
Assert.Throws<InvalidOperationException>(() => { zip.WriteAsync(buffer, 32, 32); }); // "overlapping write"
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unblock Async operations
|
||||
writeStream.manualResetEvent.Set();
|
||||
// The original WriteAsync should be able to complete
|
||||
Assert.True(task.Wait(100 * 500));
|
||||
Assert.True(writeStream.WriteHit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OverlappingReadAsync()
|
||||
{
|
||||
byte[] buffer = new byte[32];
|
||||
string testFilePath = gzTestFile("GZTestDocument.pdf.gz");
|
||||
using (var readStream = await ManualSyncMemoryStream.GetStreamFromFileAsync(testFilePath, false, StripHeaders))
|
||||
using (var unzip = CreateStream(readStream, CompressionMode.Decompress, true))
|
||||
{
|
||||
Task<int> task = null;
|
||||
try
|
||||
{
|
||||
task = ReadAsync(unzip, buffer, 0, 32);
|
||||
Assert.Throws<InvalidOperationException>(() => { ReadAsync(unzip, buffer, 0, 32); }); // "overlapping read"
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unblock Async operations
|
||||
readStream.manualResetEvent.Set();
|
||||
// The original ReadAsync should be able to complete
|
||||
Assert.True(task.Wait(100 * 500));
|
||||
Assert.True(readStream.ReadHit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DecompressWorks()
|
||||
{
|
||||
var compareStream = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.txt"));
|
||||
var gzStream = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.txt.gz"));
|
||||
|
||||
await DecompressAsync(compareStream, gzStream);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DecompressWorksWithBinaryFile()
|
||||
{
|
||||
var compareStream = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.doc"));
|
||||
var gzStream = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.doc.gz"));
|
||||
|
||||
await DecompressAsync(compareStream, gzStream);
|
||||
}
|
||||
|
||||
// Making this async since regular read/write are tested below
|
||||
private async Task DecompressAsync(MemoryStream compareStream, MemoryStream gzStream)
|
||||
{
|
||||
var sourceStream = StripHeaders ? StripHeaderAndFooter.Strip(gzStream) : gzStream;
|
||||
|
||||
var ms = new MemoryStream();
|
||||
var zip = CreateStream(sourceStream, CompressionMode.Decompress);
|
||||
|
||||
var Stream = new MemoryStream();
|
||||
|
||||
int _bufferSize = 1024;
|
||||
var bytes = new byte[_bufferSize];
|
||||
bool finished = false;
|
||||
int retCount;
|
||||
while (!finished)
|
||||
{
|
||||
retCount = await ReadAsync(zip, bytes, 0, _bufferSize);
|
||||
|
||||
if (retCount != 0)
|
||||
await Stream.WriteAsync(bytes, 0, retCount);
|
||||
else
|
||||
finished = true;
|
||||
}
|
||||
|
||||
Stream.Position = 0;
|
||||
compareStream.Position = 0;
|
||||
|
||||
byte[] compareArray = compareStream.ToArray();
|
||||
byte[] writtenArray = Stream.ToArray();
|
||||
|
||||
Assert.Equal(compareArray.Length, writtenArray.Length);
|
||||
for (int i = 0; i < compareArray.Length; i++)
|
||||
{
|
||||
Assert.Equal(compareArray[i], writtenArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TaskDeflateStreamTests : CompressionStreamAsyncTestBase
|
||||
{
|
||||
public override bool StripHeaders => true;
|
||||
public override Task<int> ReadAsync(Stream unzip, byte[] buffer, int offset, int count) => ((DeflateStream)unzip).ReadAsync(buffer, offset, count);
|
||||
public override Task WriteAsync(Stream unzip, byte[] buffer, int offset, int count) => ((DeflateStream)unzip).WriteAsync(buffer, offset, count);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode) => new DeflateStream(stream, mode);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode, bool leaveOpen) => new DeflateStream(stream, mode, leaveOpen);
|
||||
}
|
||||
|
||||
public sealed class TaskGZipStreamTests : CompressionStreamAsyncTestBase
|
||||
{
|
||||
public override bool StripHeaders => false;
|
||||
public override Task<int> ReadAsync(Stream unzip, byte[] buffer, int offset, int count) => ((GZipStream)unzip).ReadAsync(buffer, offset, count);
|
||||
public override Task WriteAsync(Stream unzip, byte[] buffer, int offset, int count) => ((GZipStream)unzip).WriteAsync(buffer, offset, count);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode) => new GZipStream(stream, mode);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode, bool leaveOpen) => new GZipStream(stream, mode, leaveOpen);
|
||||
}
|
||||
|
||||
public sealed class BeginEndDeflateStreamTests : CompressionStreamAsyncTestBase
|
||||
{
|
||||
public override bool StripHeaders => true;
|
||||
public override Task<int> ReadAsync(Stream unzip, byte[] buffer, int offset, int count) =>
|
||||
Task<int>.Factory.FromAsync<byte[], int, int>(((DeflateStream)unzip).BeginRead, ((DeflateStream)unzip).EndRead, buffer, offset, count, null);
|
||||
public override Task WriteAsync(Stream unzip, byte[] buffer, int offset, int count) =>
|
||||
Task.Factory.FromAsync<byte[], int, int>(((DeflateStream)unzip).BeginWrite, ((DeflateStream)unzip).EndWrite, buffer, offset, count, null);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode) => new DeflateStream(stream, mode);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode, bool leaveOpen) => new DeflateStream(stream, mode, leaveOpen);
|
||||
}
|
||||
|
||||
public sealed class BeginEndGZipStreamTests : CompressionStreamAsyncTestBase
|
||||
{
|
||||
public override bool StripHeaders => false;
|
||||
public override Task<int> ReadAsync(Stream unzip, byte[] buffer, int offset, int count) =>
|
||||
Task<int>.Factory.FromAsync<byte[], int, int>(((GZipStream)unzip).BeginRead, ((GZipStream)unzip).EndRead, buffer, offset, count, null);
|
||||
public override Task WriteAsync(Stream unzip, byte[] buffer, int offset, int count) =>
|
||||
Task.Factory.FromAsync<byte[], int, int>(((GZipStream)unzip).BeginWrite, ((GZipStream)unzip).EndWrite, buffer, offset, count, null);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode) => new GZipStream(stream, mode);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode, bool leaveOpen) => new GZipStream(stream, mode, leaveOpen);
|
||||
}
|
||||
}
|
111
external/corefx/src/System.IO.Compression/tests/CompressionStreamUnitTests.Deflate.cs
vendored
Normal file
111
external/corefx/src/System.IO.Compression/tests/CompressionStreamUnitTests.Deflate.cs
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace System.IO.Compression
|
||||
{
|
||||
public class DeflateStreamUnitTests : CompressionStreamUnitTestBase
|
||||
{
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode) => new DeflateStream(stream, mode);
|
||||
public override Stream CreateStream(Stream stream, CompressionMode mode, bool leaveOpen) => new DeflateStream(stream, mode, leaveOpen);
|
||||
public override Stream CreateStream(Stream stream, CompressionLevel level) => new DeflateStream(stream, level);
|
||||
public override Stream CreateStream(Stream stream, CompressionLevel level, bool leaveOpen) => new DeflateStream(stream, level, leaveOpen);
|
||||
public override Stream BaseStream(Stream stream) => ((DeflateStream)stream).BaseStream;
|
||||
protected override string CompressedTestFile(string uncompressedPath) => Path.Combine("DeflateTestData", Path.GetFileName(uncompressedPath));
|
||||
|
||||
/// <summary>
|
||||
/// Test to pass gzipstream data to a deflatestream
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[MemberData(nameof(UncompressedTestFiles))]
|
||||
public async Task DecompressFailsWithRealGzStream(string uncompressedPath)
|
||||
{
|
||||
string fileName = Path.Combine("GZipTestData", Path.GetFileName(uncompressedPath) + ".gz");
|
||||
var baseStream = await LocalMemoryStream.readAppFileAsync(fileName);
|
||||
var zip = CreateStream(baseStream, CompressionMode.Decompress);
|
||||
int _bufferSize = 2048;
|
||||
var bytes = new byte[_bufferSize];
|
||||
Assert.Throws<InvalidDataException>(() => { zip.Read(bytes, 0, _bufferSize); });
|
||||
zip.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Precancellation()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using (Stream compressor = new DeflateStream(ms, CompressionMode.Compress, leaveOpen: true))
|
||||
{
|
||||
Assert.True(compressor.WriteAsync(new byte[1], 0, 1, new CancellationToken(true)).IsCanceled);
|
||||
Assert.True(compressor.FlushAsync(new CancellationToken(true)).IsCanceled);
|
||||
}
|
||||
using (Stream decompressor = CreateStream(ms, CompressionMode.Decompress, leaveOpen: true))
|
||||
{
|
||||
Assert.True(decompressor.ReadAsync(new byte[1], 0, 1, new CancellationToken(true)).IsCanceled);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DerivedStream_ReadWriteSpan_UsesReadWriteArray()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using (var compressor = new DerivedDeflateStream(ms, CompressionMode.Compress, leaveOpen: true))
|
||||
{
|
||||
compressor.Write(new Span<byte>(new byte[1]));
|
||||
Assert.True(compressor.WriteArrayInvoked);
|
||||
}
|
||||
ms.Position = 0;
|
||||
using (var compressor = new DerivedDeflateStream(ms, CompressionMode.Decompress, leaveOpen: true))
|
||||
{
|
||||
compressor.Read(new Span<byte>(new byte[1]));
|
||||
Assert.True(compressor.ReadArrayInvoked);
|
||||
}
|
||||
ms.Position = 0;
|
||||
using (var compressor = new DerivedDeflateStream(ms, CompressionMode.Decompress, leaveOpen: true))
|
||||
{
|
||||
compressor.ReadAsync(new Memory<byte>(new byte[1])).AsTask().Wait();
|
||||
Assert.True(compressor.ReadArrayInvoked);
|
||||
}
|
||||
ms.Position = 0;
|
||||
using (var compressor = new DerivedDeflateStream(ms, CompressionMode.Compress, leaveOpen: true))
|
||||
{
|
||||
compressor.WriteAsync(new ReadOnlyMemory<byte>(new byte[1])).Wait();
|
||||
Assert.True(compressor.WriteArrayInvoked);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DerivedDeflateStream : DeflateStream
|
||||
{
|
||||
public bool ReadArrayInvoked = false, WriteArrayInvoked = false;
|
||||
internal DerivedDeflateStream(Stream stream, CompressionMode mode) : base(stream, mode) { }
|
||||
internal DerivedDeflateStream(Stream stream, CompressionMode mode, bool leaveOpen) : base(stream, mode, leaveOpen) { }
|
||||
|
||||
public override int Read(byte[] array, int offset, int count)
|
||||
{
|
||||
ReadArrayInvoked = true;
|
||||
return base.Read(array, offset, count);
|
||||
}
|
||||
|
||||
public override Task<int> ReadAsync(byte[] array, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
ReadArrayInvoked = true;
|
||||
return base.ReadAsync(array, offset, count, cancellationToken);
|
||||
}
|
||||
|
||||
public override void Write(byte[] array, int offset, int count)
|
||||
{
|
||||
WriteArrayInvoked = true;
|
||||
base.Write(array, offset, count);
|
||||
}
|
||||
|
||||
public override Task WriteAsync(byte[] array, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
WriteArrayInvoked = true;
|
||||
return base.WriteAsync(array, offset, count, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user