mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 13:34:59 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a34f5a855c | ||
|
|
6474741af1 | ||
|
|
c10bd840c5 | ||
|
|
8a022c4b18 | ||
|
|
cfef228afc | ||
|
|
237ff9f055 | ||
|
|
020f862814 | ||
|
|
fa6107200d | ||
|
|
eb81f972c4 | ||
|
|
93c1ff396e |
@@ -19,7 +19,6 @@
|
||||
| Tar.XZ | LZMA2 | Decompress | TarArchive | TarReader | TarWriter (3) |
|
||||
| GZip (single file) | DEFLATE | Both | GZipArchive | GZipReader | GZipWriter |
|
||||
| 7Zip (4) | LZMA, LZMA2, BZip2, PPMd, BCJ, BCJ2, Deflate | Decompress | SevenZipArchive | N/A | N/A |
|
||||
| LZip (single file) (5) | LZip (LZMA) | Both | LZipArchive | LZipReader | LZipWriter |
|
||||
|
||||
1. SOLID Rars are only supported in the RarReader API.
|
||||
2. Zip format supports pkware and WinzipAES encryption. However, encrypted LZMA is not supported. Zip64 reading/writing is supported but only with seekable streams as the Zip spec doesn't support Zip64 data in post data descriptors. Deflate64 is only supported for reading.
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
public override DateTime? ArchivedTime => null;
|
||||
|
||||
public override bool IsEncrypted => false;
|
||||
public override bool IsEncrypted => FilePart.IsEncrypted;
|
||||
|
||||
public override bool IsDirectory => FilePart.Header.IsDir;
|
||||
|
||||
|
||||
@@ -102,5 +102,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsEncrypted => Folder!._coders.FindIndex(c => c._methodId._id == CMethodId.K_AES_ID) != -1;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
#if NET461 || NETSTANDARD2_0
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
|
||||
namespace System.IO
|
||||
namespace SharpCompress
|
||||
{
|
||||
public static class StreamExtensions
|
||||
internal static class StreamExtensions
|
||||
{
|
||||
public static int Read(this Stream stream, Span<byte> buffer)
|
||||
internal static int Read(this Stream stream, Span<byte> buffer)
|
||||
{
|
||||
byte[] temp = ArrayPool<byte>.Shared.Rent(buffer.Length);
|
||||
|
||||
try
|
||||
{
|
||||
int read = stream.Read(buffer);
|
||||
int read = stream.Read(temp, 0, buffer.Length);
|
||||
|
||||
temp.AsSpan(0, read).CopyTo(buffer);
|
||||
|
||||
@@ -24,7 +26,7 @@ namespace System.IO
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(this Stream stream, ReadOnlySpan<byte> buffer)
|
||||
internal static void Write(this Stream stream, ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
byte[] temp = ArrayPool<byte>.Shared.Rent(buffer.Length);
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#if NET461 || NETSTANDARD2_0
|
||||
|
||||
namespace System
|
||||
namespace SharpCompress
|
||||
{
|
||||
public static class StringExtensions
|
||||
internal static class StringExtensions
|
||||
{
|
||||
public static bool EndsWith(this string text, char value)
|
||||
internal static bool EndsWith(this string text, char value)
|
||||
{
|
||||
return text.Length > 0 && text[text.Length - 1] == value;
|
||||
}
|
||||
|
||||
public static bool Contains(this string text, char value)
|
||||
internal static bool Contains(this string text, char value)
|
||||
{
|
||||
return text.IndexOf(value) > -1;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<PropertyGroup>
|
||||
<AssemblyTitle>SharpCompress - Pure C# Decompression/Compression</AssemblyTitle>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<VersionPrefix>0.28.0</VersionPrefix>
|
||||
<AssemblyVersion>0.28.0</AssemblyVersion>
|
||||
<FileVersion>0.28.0</FileVersion>
|
||||
<VersionPrefix>0.28.2</VersionPrefix>
|
||||
<AssemblyVersion>0.28.2</AssemblyVersion>
|
||||
<FileVersion>0.28.2</FileVersion>
|
||||
<Authors>Adam Hathcock</Authors>
|
||||
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
|
||||
@@ -280,7 +280,22 @@ namespace SharpCompress
|
||||
{
|
||||
return ArrayPool<byte>.Shared.Rent(81920);
|
||||
}
|
||||
|
||||
|
||||
public static bool ReadFully(this Stream stream, byte[] buffer)
|
||||
{
|
||||
int total = 0;
|
||||
int read;
|
||||
while ((read = stream.Read(buffer, total, buffer.Length - total)) > 0)
|
||||
{
|
||||
total += read;
|
||||
if (total >= buffer.Length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return (total >= buffer.Length);
|
||||
}
|
||||
|
||||
public static bool ReadFully(this Stream stream, Span<byte> buffer)
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
@@ -268,6 +268,34 @@ namespace SharpCompress.Test.Zip
|
||||
}
|
||||
VerifyFiles();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Zip_Deflate_ZipCrypto_Read()
|
||||
{
|
||||
int count = 0;
|
||||
using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "zipcrypto.zip")))
|
||||
using (var reader = ZipReader.Open(stream, new ReaderOptions()
|
||||
{
|
||||
Password = "test"
|
||||
}))
|
||||
{
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
if (!reader.Entry.IsDirectory)
|
||||
{
|
||||
Assert.Equal(CompressionType.None, reader.Entry.CompressionType);
|
||||
reader.WriteEntryToDirectory(SCRATCH_FILES_PATH,
|
||||
new ExtractionOptions()
|
||||
{
|
||||
ExtractFullPath = true,
|
||||
Overwrite = true
|
||||
});
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.Equal(8, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSharpCompressWithEmptyStream()
|
||||
|
||||
BIN
tests/TestArchives/Archives/zipcrypto.zip
Normal file
BIN
tests/TestArchives/Archives/zipcrypto.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user