mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-25 00:15:15 +00:00
Merge branch 'master' into master
This commit is contained in:
4
.github/workflows/dotnetcore.yml
vendored
4
.github/workflows/dotnetcore.yml
vendored
@@ -12,9 +12,7 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-dotnet@v2
|
||||
with:
|
||||
dotnet-version: |
|
||||
5.0.x
|
||||
6.0.x
|
||||
dotnet-version: 6.0.x
|
||||
- run: dotnet run -p build/build.csproj
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
||||
@@ -52,7 +52,7 @@ Target(Build,
|
||||
|
||||
Target(Test,
|
||||
DependsOn(Build),
|
||||
ForEach("net5.0", "net6.0", "net461"),
|
||||
ForEach("net6.0", "net461"),
|
||||
framework =>
|
||||
{
|
||||
IEnumerable<string> GetFiles(string d)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -54,7 +54,7 @@ namespace SharpCompress.Archives.GZip
|
||||
{
|
||||
//ensure new stream is at the start, this could be reset
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return new NonDisposingStream(stream);
|
||||
return NonDisposingStream.Create(stream);
|
||||
}
|
||||
|
||||
internal override void Close()
|
||||
@@ -65,4 +65,4 @@ namespace SharpCompress.Archives.GZip
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -53,7 +53,7 @@ namespace SharpCompress.Archives.Tar
|
||||
{
|
||||
//ensure new stream is at the start, this could be reset
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return new NonDisposingStream(stream);
|
||||
return NonDisposingStream.Create(stream);
|
||||
}
|
||||
|
||||
internal override void Close()
|
||||
@@ -64,4 +64,4 @@ namespace SharpCompress.Archives.Tar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
@@ -53,7 +53,7 @@ namespace SharpCompress.Archives.Zip
|
||||
{
|
||||
//ensure new stream is at the start, this could be reset
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return new NonDisposingStream(stream);
|
||||
return NonDisposingStream.Create(stream);
|
||||
}
|
||||
|
||||
internal override void Close()
|
||||
@@ -65,4 +65,4 @@ namespace SharpCompress.Archives.Zip
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.IO;
|
||||
using SharpCompress.Readers;
|
||||
@@ -14,7 +14,7 @@ namespace SharpCompress.Common
|
||||
ReaderOptions = readerOptions;
|
||||
if (readerOptions.LeaveStreamOpen)
|
||||
{
|
||||
stream = new NonDisposingStream(stream);
|
||||
stream = NonDisposingStream.Create(stream);
|
||||
}
|
||||
_actualStream = stream;
|
||||
}
|
||||
@@ -48,4 +48,4 @@ namespace SharpCompress.Common
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using SharpCompress.Common.Zip.Headers;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
using SharpCompress.IO;
|
||||
@@ -28,7 +28,7 @@ namespace SharpCompress.Common.Zip
|
||||
_decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod);
|
||||
if (LeaveStreamOpen)
|
||||
{
|
||||
return new NonDisposingStream(_decompressionStream);
|
||||
return NonDisposingStream.Create(_decompressionStream);
|
||||
}
|
||||
return _decompressionStream;
|
||||
}
|
||||
@@ -56,4 +56,4 @@ namespace SharpCompress.Common.Zip
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -37,7 +37,7 @@ namespace SharpCompress.Common.Zip
|
||||
Stream decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod);
|
||||
if (LeaveStreamOpen)
|
||||
{
|
||||
return new NonDisposingStream(decompressionStream);
|
||||
return NonDisposingStream.Create(decompressionStream);
|
||||
}
|
||||
return decompressionStream;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ namespace SharpCompress.Common.Zip
|
||||
&& FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor))
|
||||
|| Header.IsZip64)
|
||||
{
|
||||
plainStream = new NonDisposingStream(plainStream); //make sure AES doesn't close
|
||||
plainStream = NonDisposingStream.Create(plainStream); //make sure AES doesn't close
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -22,7 +22,7 @@ namespace SharpCompress.Compressors.Xz
|
||||
|
||||
public static XZFooter FromStream(Stream stream)
|
||||
{
|
||||
var footer = new XZFooter(new BinaryReader(new NonDisposingStream(stream), Encoding.UTF8));
|
||||
var footer = new XZFooter(new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8));
|
||||
footer.Process();
|
||||
return footer;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -21,7 +21,7 @@ namespace SharpCompress.Compressors.Xz
|
||||
|
||||
public static XZHeader FromStream(Stream stream)
|
||||
{
|
||||
var header = new XZHeader(new BinaryReader(new NonDisposingStream(stream), Encoding.UTF8));
|
||||
var header = new XZHeader(new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8));
|
||||
header.Process();
|
||||
return header;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -30,7 +30,7 @@ namespace SharpCompress.Compressors.Xz
|
||||
|
||||
public static XZIndex FromStream(Stream stream, bool indexMarkerAlreadyVerified)
|
||||
{
|
||||
var index = new XZIndex(new BinaryReader(new NonDisposingStream(stream), Encoding.UTF8), indexMarkerAlreadyVerified);
|
||||
var index = new XZIndex(new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8), indexMarkerAlreadyVerified);
|
||||
index.Process();
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SharpCompress.IO
|
||||
{
|
||||
public class NonDisposingStream : Stream
|
||||
{
|
||||
public NonDisposingStream(Stream stream, bool throwOnDispose = false)
|
||||
public static NonDisposingStream Create(Stream stream, bool throwOnDispose = false)
|
||||
{
|
||||
if (stream is NonDisposingStream nonDisposingStream && nonDisposingStream.ThrowOnDispose == throwOnDispose)
|
||||
{
|
||||
return nonDisposingStream;
|
||||
}
|
||||
return new NonDisposingStream(stream, throwOnDispose);
|
||||
}
|
||||
|
||||
protected NonDisposingStream(Stream stream, bool throwOnDispose = false)
|
||||
{
|
||||
Stream = stream;
|
||||
ThrowOnDispose = throwOnDispose;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SharpCompress.IO
|
||||
@@ -65,6 +65,19 @@ namespace SharpCompress.IO
|
||||
return value;
|
||||
}
|
||||
|
||||
#if !NETFRAMEWORK && !NETSTANDARD2_0
|
||||
public override int Read(Span<byte> buffer)
|
||||
{
|
||||
var slice_len = BytesLeftToRead < buffer.Length ? BytesLeftToRead : buffer.Length;
|
||||
var read = Stream.Read(buffer.Slice(0,(int)slice_len));
|
||||
if (read > 0)
|
||||
{
|
||||
BytesLeftToRead -= read;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
@@ -80,4 +93,4 @@ namespace SharpCompress.IO
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SharpCompress.IO
|
||||
@@ -119,8 +119,10 @@ namespace SharpCompress.IO
|
||||
int read;
|
||||
if (isRewound && bufferStream.Position != bufferStream.Length)
|
||||
{
|
||||
read = bufferStream.Read(buffer, offset, count);
|
||||
if (read < count)
|
||||
// don't read more than left
|
||||
int readCount = Math.Min(count, (int)(bufferStream.Length - bufferStream.Position));
|
||||
read = bufferStream.Read(buffer, offset, readCount);
|
||||
if (read < readCount)
|
||||
{
|
||||
int tempRead = stream.Read(buffer, offset + read, count - read);
|
||||
if (IsRecording)
|
||||
@@ -160,4 +162,4 @@ namespace SharpCompress.IO
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,8 @@ namespace SharpCompress.IO
|
||||
if (!IsVolumes && count != 0 && Current.Position == Current.Length)
|
||||
{
|
||||
_prevSize += Current.Length;
|
||||
SetStream(_stream + 1); //will load next file
|
||||
if (!SetStream(_stream + 1)) //will load next file if present
|
||||
break;
|
||||
Current.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -131,26 +131,27 @@ namespace SharpCompress.Readers
|
||||
|
||||
private void Skip()
|
||||
{
|
||||
var part = Entry.Parts.First();
|
||||
part.Skipped = true;
|
||||
|
||||
if (ArchiveType != ArchiveType.Rar
|
||||
&& !Entry.IsSolid
|
||||
&& Entry.CompressedSize > 0)
|
||||
{
|
||||
//not solid and has a known compressed size then we can skip raw bytes.
|
||||
var part = Entry.Parts.First();
|
||||
var rawStream = part.GetRawStream();
|
||||
|
||||
if (rawStream != null)
|
||||
{
|
||||
var bytesToAdvance = Entry.CompressedSize;
|
||||
rawStream.Skip(bytesToAdvance);
|
||||
part.Skipped = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//don't know the size so we have to try to decompress to skip
|
||||
using (var s = OpenEntryStream())
|
||||
{
|
||||
s.Skip();
|
||||
s.SkipEntry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Archives.GZip;
|
||||
using SharpCompress.Archives.Rar;
|
||||
@@ -58,7 +58,7 @@ namespace SharpCompress.Readers
|
||||
if (BZip2Stream.IsBZip2(rewindableStream))
|
||||
{
|
||||
rewindableStream.Rewind(false);
|
||||
BZip2Stream testStream = new BZip2Stream(new NonDisposingStream(rewindableStream), CompressionMode.Decompress, false);
|
||||
BZip2Stream testStream = new BZip2Stream(NonDisposingStream.Create(rewindableStream), CompressionMode.Decompress, false);
|
||||
if (TarArchive.IsTarFile(testStream))
|
||||
{
|
||||
rewindableStream.Rewind(true);
|
||||
@@ -70,7 +70,7 @@ namespace SharpCompress.Readers
|
||||
if (LZipStream.IsLZipFile(rewindableStream))
|
||||
{
|
||||
rewindableStream.Rewind(false);
|
||||
LZipStream testStream = new LZipStream(new NonDisposingStream(rewindableStream), CompressionMode.Decompress);
|
||||
LZipStream testStream = new LZipStream(NonDisposingStream.Create(rewindableStream), CompressionMode.Decompress);
|
||||
if (TarArchive.IsTarFile(testStream))
|
||||
{
|
||||
rewindableStream.Rewind(true);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
<PropertyGroup>
|
||||
<AssemblyTitle>SharpCompress - Pure C# Decompression/Compression</AssemblyTitle>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<VersionPrefix>0.31.0</VersionPrefix>
|
||||
<AssemblyVersion>0.31.0</AssemblyVersion>
|
||||
<FileVersion>0.31.0</FileVersion>
|
||||
<VersionPrefix>0.32.1</VersionPrefix>
|
||||
<AssemblyVersion>0.32.1</AssemblyVersion>
|
||||
<FileVersion>0.32.1</FileVersion>
|
||||
<Authors>Adam Hathcock</Authors>
|
||||
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0</TargetFrameworks>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<AssemblyName>SharpCompress</AssemblyName>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors;
|
||||
@@ -16,7 +16,7 @@ namespace SharpCompress.Writers.GZip
|
||||
{
|
||||
if (WriterOptions.LeaveStreamOpen)
|
||||
{
|
||||
destination = new NonDisposingStream(destination);
|
||||
destination = NonDisposingStream.Create(destination);
|
||||
}
|
||||
InitalizeStream(new GZipStream(destination, CompressionMode.Compress,
|
||||
options?.CompressionLevel ?? CompressionLevel.Default,
|
||||
@@ -46,4 +46,4 @@ namespace SharpCompress.Writers.GZip
|
||||
_wroteToStream = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Tar.Headers;
|
||||
@@ -25,7 +25,7 @@ namespace SharpCompress.Writers.Tar
|
||||
}
|
||||
if (WriterOptions.LeaveStreamOpen)
|
||||
{
|
||||
destination = new NonDisposingStream(destination);
|
||||
destination = NonDisposingStream.Create(destination);
|
||||
}
|
||||
switch (options.CompressionType)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@@ -98,10 +98,24 @@ namespace SharpCompress.Writers.Zip
|
||||
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // disk=0
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // file type: binary
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // Internal file attributes
|
||||
|
||||
// Internal file attributes:
|
||||
// Bit 0: apparent ASCII/ text file
|
||||
// Bit 1: reserved
|
||||
// Bit 2: control field records precede logical records
|
||||
// Bits 3 - 16: unused
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // file type: binary, Internal file attributes
|
||||
|
||||
// External flags are host-dependent, this might match DOS
|
||||
// Bit 0: Read-Only
|
||||
// Bit 1: Hidden
|
||||
// Bit 2: System
|
||||
// Bit 3: Label
|
||||
// Bit 4: Directory
|
||||
// Bit 5: Archive
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // External file attributes
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0x8100);
|
||||
outputStream.Write(intBuf.Slice(0, 2));
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -40,7 +40,7 @@ namespace SharpCompress.Writers.Zip
|
||||
|
||||
if (WriterOptions.LeaveStreamOpen)
|
||||
{
|
||||
destination = new NonDisposingStream(destination);
|
||||
destination = NonDisposingStream.Create(destination);
|
||||
}
|
||||
InitalizeStream(destination);
|
||||
}
|
||||
|
||||
@@ -32,31 +32,42 @@ namespace SharpCompress.Test
|
||||
{
|
||||
foreach (var path in testArchives)
|
||||
{
|
||||
using (var stream = new NonDisposingStream(File.OpenRead(path), true))
|
||||
using (var archive = ArchiveFactory.Open(stream))
|
||||
using (var stream = NonDisposingStream.Create(File.OpenRead(path), true))
|
||||
{
|
||||
Assert.True(archive.IsSolid);
|
||||
using (var reader = archive.ExtractAllEntries())
|
||||
try
|
||||
{
|
||||
UseReader(reader, compression);
|
||||
}
|
||||
VerifyFiles();
|
||||
using (var archive = ArchiveFactory.Open(stream))
|
||||
{
|
||||
Assert.True(archive.IsSolid);
|
||||
using (var reader = archive.ExtractAllEntries())
|
||||
{
|
||||
UseReader(reader, compression);
|
||||
}
|
||||
VerifyFiles();
|
||||
|
||||
if (archive.Entries.First().CompressionType == CompressionType.Rar)
|
||||
if (archive.Entries.First().CompressionType == CompressionType.Rar)
|
||||
{
|
||||
stream.ThrowOnDispose = false;
|
||||
return;
|
||||
}
|
||||
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
|
||||
{
|
||||
entry.WriteToDirectory(SCRATCH_FILES_PATH,
|
||||
new ExtractionOptions
|
||||
{
|
||||
ExtractFullPath = true,
|
||||
Overwrite = true
|
||||
});
|
||||
}
|
||||
stream.ThrowOnDispose = false;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Otherwise this will hide the original exception.
|
||||
stream.ThrowOnDispose = false;
|
||||
return;
|
||||
throw;
|
||||
}
|
||||
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
|
||||
{
|
||||
entry.WriteToDirectory(SCRATCH_FILES_PATH,
|
||||
new ExtractionOptions
|
||||
{
|
||||
ExtractFullPath = true,
|
||||
Overwrite = true
|
||||
});
|
||||
}
|
||||
stream.ThrowOnDispose = false;
|
||||
}
|
||||
VerifyFiles();
|
||||
}
|
||||
@@ -77,7 +88,7 @@ namespace SharpCompress.Test
|
||||
{
|
||||
foreach (var path in testArchives)
|
||||
{
|
||||
using (var stream = new NonDisposingStream(File.OpenRead(path), true))
|
||||
using (var stream = NonDisposingStream.Create(File.OpenRead(path), true))
|
||||
using (var archive = ArchiveFactory.Open(stream, readerOptions))
|
||||
{
|
||||
try
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
using SharpCompress.Readers;
|
||||
@@ -27,7 +27,7 @@ namespace SharpCompress.Test
|
||||
{
|
||||
using (var file = File.OpenRead(testArchive))
|
||||
{
|
||||
using (var protectedStream = new NonDisposingStream(new ForwardOnlyStream(file), throwOnDispose: true))
|
||||
using (var protectedStream = NonDisposingStream.Create(new ForwardOnlyStream(file), throwOnDispose: true))
|
||||
{
|
||||
using (var testStream = new TestStream(protectedStream))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net5.0;net6.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0;net461</TargetFrameworks>
|
||||
<AssemblyName>SharpCompress.Test</AssemblyName>
|
||||
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace SharpCompress.Test.Streams
|
||||
|
||||
private void Compress(Stream input, Stream output, int compressionLevel)
|
||||
{
|
||||
using (var zlibStream = new ZlibStream(new NonDisposingStream(output), CompressionMode.Compress, (CompressionLevel)compressionLevel))
|
||||
using (var zlibStream = new ZlibStream(NonDisposingStream.Create(output), CompressionMode.Compress, (CompressionLevel)compressionLevel))
|
||||
{
|
||||
zlibStream.FlushMode = FlushType.Sync;
|
||||
input.CopyTo(zlibStream);
|
||||
@@ -72,7 +72,7 @@ namespace SharpCompress.Test.Streams
|
||||
|
||||
private void Decompress(Stream input, Stream output)
|
||||
{
|
||||
using (var zlibStream = new ZlibStream(new NonDisposingStream(input), CompressionMode.Decompress))
|
||||
using (var zlibStream = new ZlibStream(NonDisposingStream.Create(input), CompressionMode.Decompress))
|
||||
{
|
||||
zlibStream.CopyTo(output);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
@@ -41,7 +41,7 @@ namespace SharpCompress.Test
|
||||
|
||||
readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;
|
||||
|
||||
using (var reader = ReaderFactory.Open(new NonDisposingStream(stream), readerOptions))
|
||||
using (var reader = ReaderFactory.Open(NonDisposingStream.Create(stream), readerOptions))
|
||||
{
|
||||
reader.WriteAllToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions()
|
||||
{
|
||||
|
||||
@@ -680,6 +680,28 @@ namespace SharpCompress.Test.Zip
|
||||
firstStream.CopyTo(memoryStream);
|
||||
Assert.Equal(199, memoryStream.Length);
|
||||
}
|
||||
|
||||
var len1 = 0;
|
||||
var buffer1 = new byte[firstEntry.Size + 256];
|
||||
|
||||
using (var firstStream = firstEntry.OpenEntryStream())
|
||||
{
|
||||
len1 = firstStream.Read(buffer1, 0, buffer.Length);
|
||||
}
|
||||
|
||||
Assert.Equal(199, len1);
|
||||
|
||||
#if !NETFRAMEWORK && !NETSTANDARD2_0
|
||||
var len2 = 0;
|
||||
var buffer2 = new byte[firstEntry.Size + 256];
|
||||
|
||||
using (var firstStream = firstEntry.OpenEntryStream())
|
||||
{
|
||||
len2 = firstStream.Read(buffer2.AsSpan());
|
||||
}
|
||||
Assert.Equal(len1, len2);
|
||||
Assert.Equal(buffer1, buffer2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,5 +735,17 @@ namespace SharpCompress.Test.Zip
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Zip_Uncompressed_Skip_All()
|
||||
{
|
||||
string zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.uncompressed.zip");
|
||||
using (var stream = File.Open(zipPath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
IArchive archive = ArchiveFactory.Open(stream);
|
||||
IReader reader = archive.ExtractAllEntries();
|
||||
while (reader.MoveToNextEntry())
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace SharpCompress.Test.Zip
|
||||
stream = new MemoryStream(memory.ToArray());
|
||||
File.WriteAllBytes(Path.Combine(SCRATCH_FILES_PATH, "foo.zip"), memory.ToArray());
|
||||
|
||||
using (IReader zipReader = ZipReader.Open(new NonDisposingStream(stream, true)))
|
||||
using (IReader zipReader = ZipReader.Open(NonDisposingStream.Create(stream, true)))
|
||||
{
|
||||
var i = 0;
|
||||
while (zipReader.MoveToNextEntry())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
using SharpCompress.Common;
|
||||
using Xunit;
|
||||
|
||||
BIN
tests/TestArchives/Archives/Zip.uncompressed.zip
Normal file
BIN
tests/TestArchives/Archives/Zip.uncompressed.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user