mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-10 05:31:29 +00:00
Compare commits
8 Commits
copilot/ad
...
adam/make-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
436b2f4a11 | ||
|
|
61133bc010 | ||
|
|
8f64d351ac | ||
|
|
6bfe4071aa | ||
|
|
9fa425d8c5 | ||
|
|
56c3c92f30 | ||
|
|
8f3ff5fd65 | ||
|
|
0e96aa4263 |
@@ -3,7 +3,7 @@
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"csharpier": {
|
||||
"version": "1.2.6",
|
||||
"version": "1.2.5",
|
||||
"commands": [
|
||||
"csharpier"
|
||||
],
|
||||
|
||||
@@ -69,7 +69,7 @@ public static partial class ArchiveFactory
|
||||
options ??= new ReaderOptions { LeaveStreamOpen = false };
|
||||
|
||||
var factory = await FindFactoryAsync<IMultiArchiveFactory>(fileInfo, cancellationToken);
|
||||
return factory.OpenAsyncArchive(filesArray, options);
|
||||
return factory.OpenAsyncArchive(filesArray, options, cancellationToken);
|
||||
}
|
||||
|
||||
public static async ValueTask<IAsyncArchive> OpenAsyncArchive(
|
||||
|
||||
@@ -23,9 +23,11 @@ public partial class GZipArchive
|
||||
{
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IWritableAsyncArchive)OpenArchive(
|
||||
new FileInfo(path),
|
||||
@@ -102,33 +104,41 @@ public partial class GZipArchive
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(streams, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,17 +20,20 @@ public interface IArchiveOpenable<TSync, TASync>
|
||||
|
||||
public static abstract TASync OpenAsyncArchive(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public static abstract TASync OpenAsyncArchive(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public static abstract TASync OpenAsyncArchive(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,10 @@ public interface IMultiArchiveFactory : IFactory
|
||||
/// </summary>
|
||||
/// <param name="fileInfos"></param>
|
||||
/// <param name="readerOptions">reading options.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
|
||||
@@ -22,12 +22,14 @@ public interface IMultiArchiveOpenable<TSync, TASync>
|
||||
|
||||
public static abstract TASync OpenAsyncArchive(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public static abstract TASync OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,9 +22,11 @@ public partial class RarArchive
|
||||
{
|
||||
public static IRarAsyncArchive OpenAsyncArchive(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IRarAsyncArchive)OpenArchive(new FileInfo(path), readerOptions);
|
||||
}
|
||||
@@ -100,33 +102,41 @@ public partial class RarArchive
|
||||
|
||||
public static IRarAsyncArchive OpenAsyncArchive(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IRarAsyncArchive)OpenArchive(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IRarAsyncArchive OpenAsyncArchive(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IRarAsyncArchive)OpenArchive(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
public static IRarAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IRarAsyncArchive)OpenArchive(streams, readerOptions);
|
||||
}
|
||||
|
||||
public static IRarAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IRarAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,13 @@ public partial class SevenZipArchive
|
||||
IMultiArchiveOpenable<IArchive, IAsyncArchive>
|
||||
#endif
|
||||
{
|
||||
public static IAsyncArchive OpenAsyncArchive(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncArchive OpenAsyncArchive(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty("path");
|
||||
return (IAsyncArchive)OpenArchive(new FileInfo(path), readerOptions ?? new ReaderOptions());
|
||||
}
|
||||
@@ -86,32 +91,43 @@ public partial class SevenZipArchive
|
||||
);
|
||||
}
|
||||
|
||||
public static IAsyncArchive OpenAsyncArchive(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncArchive OpenAsyncArchive(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncArchive OpenAsyncArchive(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(streams, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,41 +87,51 @@ public partial class TarArchive
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(streams, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,41 +87,51 @@ public partial class ZipArchive
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(path, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(streams, readerOptions);
|
||||
}
|
||||
|
||||
public static IWritableAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IWritableAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,5 +10,4 @@ public enum ArchiveType
|
||||
Arc,
|
||||
Arj,
|
||||
Ace,
|
||||
Lzw,
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace SharpCompress.Common.Lzw;
|
||||
|
||||
public partial class LzwEntry
|
||||
{
|
||||
internal static async IAsyncEnumerable<LzwEntry> GetEntriesAsync(
|
||||
Stream stream,
|
||||
OptionsBase options,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
yield return new LzwEntry(
|
||||
await LzwFilePart.CreateAsync(stream, options.ArchiveEncoding, cancellationToken)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace SharpCompress.Common.Lzw;
|
||||
|
||||
public partial class LzwEntry : Entry
|
||||
{
|
||||
private readonly LzwFilePart? _filePart;
|
||||
|
||||
internal LzwEntry(LzwFilePart? filePart) => _filePart = filePart;
|
||||
|
||||
public override CompressionType CompressionType => CompressionType.Lzw;
|
||||
|
||||
public override long Crc => 0;
|
||||
|
||||
public override string? Key => _filePart?.FilePartName;
|
||||
|
||||
public override string? LinkTarget => null;
|
||||
|
||||
public override long CompressedSize => 0;
|
||||
|
||||
public override long Size => 0;
|
||||
|
||||
public override DateTime? LastModifiedTime => null;
|
||||
|
||||
public override DateTime? CreatedTime => null;
|
||||
|
||||
public override DateTime? LastAccessedTime => null;
|
||||
|
||||
public override DateTime? ArchivedTime => null;
|
||||
|
||||
public override bool IsEncrypted => false;
|
||||
|
||||
public override bool IsDirectory => false;
|
||||
|
||||
public override bool IsSplitAfter => false;
|
||||
|
||||
internal override IEnumerable<FilePart> Parts => _filePart.Empty();
|
||||
|
||||
internal static IEnumerable<LzwEntry> GetEntries(Stream stream, OptionsBase options)
|
||||
{
|
||||
yield return new LzwEntry(LzwFilePart.Create(stream, options.ArchiveEncoding));
|
||||
}
|
||||
|
||||
// Async methods moved to LzwEntry.Async.cs
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharpCompress.Common.Lzw;
|
||||
|
||||
internal sealed partial class LzwFilePart
|
||||
{
|
||||
internal static async ValueTask<LzwFilePart> CreateAsync(
|
||||
Stream stream,
|
||||
IArchiveEncoding archiveEncoding,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var part = new LzwFilePart(stream, archiveEncoding);
|
||||
|
||||
// For non-seekable streams, we can't track position, so use 0 since the stream will be
|
||||
// read sequentially from its current position.
|
||||
part.EntryStartPosition = stream.CanSeek ? stream.Position : 0;
|
||||
return part;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System.IO;
|
||||
using SharpCompress.Compressors.Lzw;
|
||||
|
||||
namespace SharpCompress.Common.Lzw;
|
||||
|
||||
internal sealed partial class LzwFilePart : FilePart
|
||||
{
|
||||
private readonly Stream _stream;
|
||||
private readonly string? _name;
|
||||
|
||||
internal static LzwFilePart Create(Stream stream, IArchiveEncoding archiveEncoding)
|
||||
{
|
||||
var part = new LzwFilePart(stream, archiveEncoding);
|
||||
|
||||
// For non-seekable streams, we can't track position, so use 0 since the stream will be
|
||||
// read sequentially from its current position.
|
||||
part.EntryStartPosition = stream.CanSeek ? stream.Position : 0;
|
||||
return part;
|
||||
}
|
||||
|
||||
private LzwFilePart(Stream stream, IArchiveEncoding archiveEncoding)
|
||||
: base(archiveEncoding)
|
||||
{
|
||||
_stream = stream;
|
||||
_name = DeriveFileName(stream);
|
||||
}
|
||||
|
||||
internal long EntryStartPosition { get; private set; }
|
||||
|
||||
internal override string? FilePartName => _name;
|
||||
|
||||
internal override Stream GetCompressedStream() =>
|
||||
new LzwStream(_stream) { IsStreamOwner = false };
|
||||
|
||||
internal override Stream GetRawStream() => _stream;
|
||||
|
||||
private static string? DeriveFileName(Stream stream)
|
||||
{
|
||||
// Unwrap SharpCompressStream to get to the underlying FileStream
|
||||
var unwrappedStream = stream;
|
||||
if (stream is SharpCompress.IO.IStreamStack streamStack)
|
||||
{
|
||||
unwrappedStream = streamStack.BaseStream();
|
||||
}
|
||||
|
||||
// Try to derive filename from FileStream
|
||||
if (unwrappedStream is FileStream fileStream && !string.IsNullOrEmpty(fileStream.Name))
|
||||
{
|
||||
var fileName = Path.GetFileName(fileStream.Name);
|
||||
// Strip .Z extension if present
|
||||
if (fileName.EndsWith(".Z", System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return fileName.Substring(0, fileName.Length - 2);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
// Default name for non-file streams
|
||||
return "data";
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.IO;
|
||||
using SharpCompress.Readers;
|
||||
|
||||
namespace SharpCompress.Common.Lzw;
|
||||
|
||||
public class LzwVolume : Volume
|
||||
{
|
||||
public LzwVolume(Stream stream, ReaderOptions? options, int index)
|
||||
: base(stream, options, index) { }
|
||||
|
||||
public LzwVolume(FileInfo fileInfo, ReaderOptions options)
|
||||
: base(fileInfo.OpenRead(), options) => options.LeaveStreamOpen = false;
|
||||
|
||||
public override bool IsFirstVolume => true;
|
||||
|
||||
public override bool IsMultiVolume => false;
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using SharpCompress.Common.Rar.Headers;
|
||||
@@ -12,7 +10,7 @@ internal class CryptKey3 : ICryptKey
|
||||
|
||||
private string _password;
|
||||
|
||||
public CryptKey3(string password) => _password = password ?? "";
|
||||
public CryptKey3(string? password) => _password = password ?? "";
|
||||
|
||||
public ICryptoTransform Transformer(byte[] salt)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common.Rar;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using SharpCompress.Common.Rar;
|
||||
using SharpCompress.IO;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public partial class RarHeaderFactory
|
||||
if (_isRar5 && _cryptInfo != null)
|
||||
{
|
||||
await _cryptInfo.ReadInitVAsync(new AsyncMarkingBinaryReader(stream));
|
||||
var _headerKey = new CryptKey5(Options.Password!, _cryptInfo);
|
||||
var _headerKey = new CryptKey5(Options.Password.NotNull(), _cryptInfo);
|
||||
|
||||
reader = await AsyncRarCryptoBinaryReader.Create(
|
||||
stream,
|
||||
@@ -189,7 +189,7 @@ public partial class RarHeaderFactory
|
||||
Options.Password,
|
||||
fh.Rar5CryptoInfo.NotNull()
|
||||
)
|
||||
: new CryptKey3(Options.Password)
|
||||
: new CryptKey3(Options.Password.NotNull())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public partial class RarHeaderFactory
|
||||
if (_isRar5 && _cryptInfo != null)
|
||||
{
|
||||
_cryptInfo.ReadInitV(new MarkingBinaryReader(stream));
|
||||
var _headerKey = new CryptKey5(Options.Password!, _cryptInfo);
|
||||
var _headerKey = new CryptKey5(Options.Password.NotNull(), _cryptInfo);
|
||||
|
||||
reader = RarCryptoBinaryReader.Create(stream, _headerKey, _cryptInfo.Salt);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -18,7 +16,7 @@ internal partial class ArchiveDatabase
|
||||
internal List<long> _packSizes = new();
|
||||
internal List<uint?> _packCrCs = new();
|
||||
internal List<CFolder> _folders = new();
|
||||
internal List<int> _numUnpackStreamsVector;
|
||||
internal List<int>? _numUnpackStreamsVector;
|
||||
internal List<CFileItem> _files = new();
|
||||
|
||||
internal List<long> _packStreamStartPositions = new();
|
||||
@@ -47,7 +45,7 @@ internal partial class ArchiveDatabase
|
||||
_packSizes.Count == 0
|
||||
&& _packCrCs.Count == 0
|
||||
&& _folders.Count == 0
|
||||
&& _numUnpackStreamsVector.Count == 0
|
||||
&& (_numUnpackStreamsVector?.Count ?? 0) == 0
|
||||
&& _files.Count == 0;
|
||||
|
||||
private void FillStartPos()
|
||||
@@ -94,7 +92,7 @@ internal partial class ArchiveDatabase
|
||||
|
||||
_folderStartFileIndex.Add(i); // check it
|
||||
|
||||
if (_numUnpackStreamsVector![folderIndex] != 0)
|
||||
if (_numUnpackStreamsVector.NotNull()[folderIndex] != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#nullable disable
|
||||
|
||||
namespace SharpCompress.Common.SevenZip;
|
||||
|
||||
internal class CCoderInfo
|
||||
{
|
||||
internal CMethodId _methodId;
|
||||
internal byte[] _props;
|
||||
internal byte[]? _props;
|
||||
internal int _numInStreams;
|
||||
internal int _numOutStreams;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Common.SevenZip;
|
||||
@@ -10,7 +8,7 @@ internal class CFileItem
|
||||
public uint? Attrib { get; internal set; }
|
||||
public uint? ExtendedAttrib { get; internal set; }
|
||||
public uint? Crc { get; internal set; }
|
||||
public string Name { get; internal set; }
|
||||
public string? Name { get; internal set; }
|
||||
|
||||
public bool HasStream { get; internal set; }
|
||||
public bool IsDir { get; internal set; }
|
||||
|
||||
@@ -34,7 +34,7 @@ internal class SevenZipFilePart : FilePart
|
||||
internal CFileItem Header { get; }
|
||||
internal CFolder? Folder { get; }
|
||||
|
||||
internal override string FilePartName => Header.Name;
|
||||
internal override string? FilePartName => Header.Name;
|
||||
|
||||
internal override Stream? GetRawStream() => null;
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -78,11 +76,12 @@ public sealed partial class ADCStream
|
||||
var toCopy = count;
|
||||
var copied = 0;
|
||||
|
||||
while (_outPosition + toCopy >= _outBuffer.Length)
|
||||
var outBuf = _outBuffer.NotNull();
|
||||
while (_outPosition + toCopy >= outBuf.Length)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var piece = _outBuffer.Length - _outPosition;
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, piece);
|
||||
var piece = outBuf.Length - _outPosition;
|
||||
Array.Copy(outBuf, _outPosition, buffer, inPosition, piece);
|
||||
inPosition += piece;
|
||||
copied += piece;
|
||||
_position += piece;
|
||||
@@ -97,9 +96,10 @@ public sealed partial class ADCStream
|
||||
{
|
||||
return copied;
|
||||
}
|
||||
outBuf = _outBuffer;
|
||||
}
|
||||
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, toCopy);
|
||||
Array.Copy(outBuf, _outPosition, buffer, inPosition, toCopy);
|
||||
_outPosition += toCopy;
|
||||
_position += toCopy;
|
||||
copied += toCopy;
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -56,7 +54,7 @@ public sealed partial class ADCStream : Stream
|
||||
/// <summary>
|
||||
/// Buffer with currently used chunk of decompressed data
|
||||
/// </summary>
|
||||
private byte[] _outBuffer;
|
||||
private byte[]? _outBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Position in buffer of decompressed data
|
||||
@@ -139,10 +137,11 @@ public sealed partial class ADCStream : Stream
|
||||
var toCopy = count;
|
||||
var copied = 0;
|
||||
|
||||
while (_outPosition + toCopy >= _outBuffer.Length)
|
||||
while (_outPosition + toCopy >= _outBuffer.NotNull().Length)
|
||||
{
|
||||
var piece = _outBuffer.Length - _outPosition;
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, piece);
|
||||
var outBuf = _outBuffer.NotNull();
|
||||
var piece = outBuf.Length - _outPosition;
|
||||
Array.Copy(outBuf, _outPosition, buffer, inPosition, piece);
|
||||
inPosition += piece;
|
||||
copied += piece;
|
||||
_position += piece;
|
||||
@@ -155,7 +154,7 @@ public sealed partial class ADCStream : Stream
|
||||
}
|
||||
}
|
||||
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, toCopy);
|
||||
Array.Copy(_outBuffer.NotNull(), _outPosition, buffer, inPosition, toCopy);
|
||||
_outPosition += toCopy;
|
||||
_position += toCopy;
|
||||
copied += toCopy;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
@@ -11,8 +9,8 @@ internal sealed class BinTree : InWindow
|
||||
private uint _cyclicBufferSize;
|
||||
private uint _matchMaxLen;
|
||||
|
||||
private uint[] _son;
|
||||
private uint[] _hash;
|
||||
private uint[]? _son;
|
||||
private uint[]? _hash;
|
||||
|
||||
private uint _cutValue = 0xFF;
|
||||
private uint _hashMask;
|
||||
@@ -56,9 +54,10 @@ internal sealed class BinTree : InWindow
|
||||
public new void Init()
|
||||
{
|
||||
base.Init();
|
||||
var hash = _hash.NotNull();
|
||||
for (uint i = 0; i < _hashSizeSum; i++)
|
||||
{
|
||||
_hash[i] = K_EMPTY_HASH_VALUE;
|
||||
hash[i] = K_EMPTY_HASH_VALUE;
|
||||
}
|
||||
_cyclicBufferPos = 0;
|
||||
ReduceOffsets(-1);
|
||||
@@ -141,6 +140,8 @@ internal sealed class BinTree : InWindow
|
||||
|
||||
public uint GetMatches(uint[] distances)
|
||||
{
|
||||
var son = _son.NotNull();
|
||||
var hash = _hash.NotNull();
|
||||
uint lenLimit;
|
||||
if (_pos + _matchMaxLen <= _streamPos)
|
||||
{
|
||||
@@ -164,26 +165,27 @@ internal sealed class BinTree : InWindow
|
||||
hash2Value = 0,
|
||||
hash3Value = 0;
|
||||
|
||||
var bufferBase = _bufferBase.NotNull();
|
||||
if (_hashArray)
|
||||
{
|
||||
var temp = Crc.TABLE[_bufferBase[cur]] ^ _bufferBase[cur + 1];
|
||||
var temp = Crc.TABLE[bufferBase[cur]] ^ bufferBase[cur + 1];
|
||||
hash2Value = temp & (K_HASH2_SIZE - 1);
|
||||
temp ^= ((uint)(_bufferBase[cur + 2]) << 8);
|
||||
temp ^= ((uint)(bufferBase[cur + 2]) << 8);
|
||||
hash3Value = temp & (K_HASH3_SIZE - 1);
|
||||
hashValue = (temp ^ (Crc.TABLE[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
hashValue = (temp ^ (Crc.TABLE[bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashValue = _bufferBase[cur] ^ ((uint)(_bufferBase[cur + 1]) << 8);
|
||||
hashValue = bufferBase[cur] ^ ((uint)(bufferBase[cur + 1]) << 8);
|
||||
}
|
||||
|
||||
var curMatch = _hash[_kFixHashSize + hashValue];
|
||||
var curMatch = hash[_kFixHashSize + hashValue];
|
||||
if (_hashArray)
|
||||
{
|
||||
var curMatch2 = _hash[hash2Value];
|
||||
var curMatch3 = _hash[K_HASH3_OFFSET + hash3Value];
|
||||
_hash[hash2Value] = _pos;
|
||||
_hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
var curMatch2 = hash[hash2Value];
|
||||
var curMatch3 = hash[K_HASH3_OFFSET + hash3Value];
|
||||
hash[hash2Value] = _pos;
|
||||
hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
if (curMatch2 > matchMinPos)
|
||||
{
|
||||
if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])
|
||||
@@ -212,7 +214,7 @@ internal sealed class BinTree : InWindow
|
||||
}
|
||||
}
|
||||
|
||||
_hash[_kFixHashSize + hashValue] = _pos;
|
||||
hash[_kFixHashSize + hashValue] = _pos;
|
||||
|
||||
var ptr0 = (_cyclicBufferPos << 1) + 1;
|
||||
var ptr1 = (_cyclicBufferPos << 1);
|
||||
@@ -242,7 +244,7 @@ internal sealed class BinTree : InWindow
|
||||
{
|
||||
if (curMatch <= matchMinPos || count-- == 0)
|
||||
{
|
||||
_son[ptr0] = _son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
son[ptr0] = son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
break;
|
||||
}
|
||||
var delta = _pos - curMatch;
|
||||
@@ -270,24 +272,24 @@ internal sealed class BinTree : InWindow
|
||||
distances[offset++] = delta - 1;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
_son[ptr1] = _son[cyclicPos];
|
||||
_son[ptr0] = _son[cyclicPos + 1];
|
||||
son[ptr1] = son[cyclicPos];
|
||||
son[ptr0] = son[cyclicPos + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
|
||||
{
|
||||
_son[ptr1] = curMatch;
|
||||
son[ptr1] = curMatch;
|
||||
ptr1 = cyclicPos + 1;
|
||||
curMatch = _son[ptr1];
|
||||
curMatch = son[ptr1];
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
_son[ptr0] = curMatch;
|
||||
son[ptr0] = curMatch;
|
||||
ptr0 = cyclicPos;
|
||||
curMatch = _son[ptr0];
|
||||
curMatch = son[ptr0];
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
@@ -297,6 +299,8 @@ internal sealed class BinTree : InWindow
|
||||
|
||||
public void Skip(uint num)
|
||||
{
|
||||
var son = _son.NotNull();
|
||||
var hash = _hash.NotNull();
|
||||
do
|
||||
{
|
||||
uint lenLimit;
|
||||
@@ -323,10 +327,10 @@ internal sealed class BinTree : InWindow
|
||||
{
|
||||
var temp = Crc.TABLE[_bufferBase[cur]] ^ _bufferBase[cur + 1];
|
||||
var hash2Value = temp & (K_HASH2_SIZE - 1);
|
||||
_hash[hash2Value] = _pos;
|
||||
hash[hash2Value] = _pos;
|
||||
temp ^= ((uint)(_bufferBase[cur + 2]) << 8);
|
||||
var hash3Value = temp & (K_HASH3_SIZE - 1);
|
||||
_hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
hashValue = (temp ^ (Crc.TABLE[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
@@ -334,8 +338,8 @@ internal sealed class BinTree : InWindow
|
||||
hashValue = _bufferBase[cur] ^ ((uint)(_bufferBase[cur + 1]) << 8);
|
||||
}
|
||||
|
||||
var curMatch = _hash[_kFixHashSize + hashValue];
|
||||
_hash[_kFixHashSize + hashValue] = _pos;
|
||||
var curMatch = hash[_kFixHashSize + hashValue];
|
||||
hash[_kFixHashSize + hashValue] = _pos;
|
||||
|
||||
var ptr0 = (_cyclicBufferPos << 1) + 1;
|
||||
var ptr1 = (_cyclicBufferPos << 1);
|
||||
@@ -349,7 +353,7 @@ internal sealed class BinTree : InWindow
|
||||
{
|
||||
if (curMatch <= matchMinPos || count-- == 0)
|
||||
{
|
||||
_son[ptr0] = _son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
son[ptr0] = son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -374,23 +378,23 @@ internal sealed class BinTree : InWindow
|
||||
}
|
||||
if (len == lenLimit)
|
||||
{
|
||||
_son[ptr1] = _son[cyclicPos];
|
||||
_son[ptr0] = _son[cyclicPos + 1];
|
||||
son[ptr1] = son[cyclicPos];
|
||||
son[ptr0] = son[cyclicPos + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
|
||||
{
|
||||
_son[ptr1] = curMatch;
|
||||
son[ptr1] = curMatch;
|
||||
ptr1 = cyclicPos + 1;
|
||||
curMatch = _son[ptr1];
|
||||
curMatch = son[ptr1];
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
_son[ptr0] = curMatch;
|
||||
son[ptr0] = curMatch;
|
||||
ptr0 = cyclicPos;
|
||||
curMatch = _son[ptr0];
|
||||
curMatch = son[ptr0];
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
@@ -418,8 +422,8 @@ internal sealed class BinTree : InWindow
|
||||
private void Normalize()
|
||||
{
|
||||
var subValue = _pos - _cyclicBufferSize;
|
||||
NormalizeLinks(_son, _cyclicBufferSize * 2, subValue);
|
||||
NormalizeLinks(_hash, _hashSizeSum, subValue);
|
||||
NormalizeLinks(_son.NotNull(), _cyclicBufferSize * 2, subValue);
|
||||
NormalizeLinks(_hash.NotNull(), _hashSizeSum, subValue);
|
||||
ReduceOffsets((int)subValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -25,6 +23,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
)
|
||||
{
|
||||
return await _lowCoder[posState]
|
||||
.NotNull()
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -35,6 +34,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
)
|
||||
{
|
||||
symbol += await _midCoder[posState]
|
||||
.NotNull()
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -108,7 +108,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
byte prevByte,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
await _coders[GetState(pos, prevByte)]
|
||||
await _coders
|
||||
.NotNull()[GetState(pos, prevByte)]
|
||||
.DecodeNormalAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
@@ -119,7 +120,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
byte matchByte,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
await _coders[GetState(pos, prevByte)]
|
||||
await _coders
|
||||
.NotNull()[GetState(pos, prevByte)]
|
||||
.DecodeWithMatchByteAsync(rangeDecoder, matchByte, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -137,26 +139,26 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
await _outWindow.InitAsync(outStream);
|
||||
await _outWindow.NotNull().InitAsync(outStream);
|
||||
if (outSize > 0)
|
||||
{
|
||||
_outWindow.SetLimit(outSize);
|
||||
_outWindow.NotNull().SetLimit(outSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
_outWindow.SetLimit(long.MaxValue - _outWindow.Total);
|
||||
_outWindow.NotNull().SetLimit(long.MaxValue - _outWindow.NotNull().Total);
|
||||
}
|
||||
|
||||
var rangeDecoder = new RangeCoder.Decoder();
|
||||
await rangeDecoder.InitAsync(inStream, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await CodeAsync(_dictionarySize, _outWindow, rangeDecoder, cancellationToken)
|
||||
await CodeAsync(_dictionarySize, _outWindow.NotNull(), rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await _outWindow.ReleaseStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
await _outWindow.NotNull().ReleaseStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
rangeDecoder.ReleaseStream();
|
||||
|
||||
await _outWindow.DisposeAsync().ConfigureAwait(false);
|
||||
await _outWindow.NotNull().DisposeAsync().ConfigureAwait(false);
|
||||
_outWindow = null;
|
||||
}
|
||||
|
||||
@@ -339,6 +341,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
await _outWindow.TrainAsync(stream);
|
||||
await _outWindow.NotNull().TrainAsync(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
@@ -15,8 +13,12 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
{
|
||||
private BitDecoder _choice = new();
|
||||
private BitDecoder _choice2 = new();
|
||||
private readonly BitTreeDecoder[] _lowCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX];
|
||||
private readonly BitTreeDecoder[] _midCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX];
|
||||
private readonly BitTreeDecoder?[] _lowCoder = new BitTreeDecoder?[
|
||||
Base.K_NUM_POS_STATES_MAX
|
||||
];
|
||||
private readonly BitTreeDecoder?[] _midCoder = new BitTreeDecoder?[
|
||||
Base.K_NUM_POS_STATES_MAX
|
||||
];
|
||||
private BitTreeDecoder _highCoder = new(Base.K_NUM_HIGH_LEN_BITS);
|
||||
private uint _numPosStates;
|
||||
|
||||
@@ -35,8 +37,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
_choice.Init();
|
||||
for (uint posState = 0; posState < _numPosStates; posState++)
|
||||
{
|
||||
_lowCoder[posState].Init();
|
||||
_midCoder[posState].Init();
|
||||
_lowCoder[posState].NotNull().Init();
|
||||
_midCoder[posState].NotNull().Init();
|
||||
}
|
||||
_choice2.Init();
|
||||
_highCoder.Init();
|
||||
@@ -46,12 +48,12 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
{
|
||||
if (_choice.Decode(rangeDecoder) == 0)
|
||||
{
|
||||
return _lowCoder[posState].Decode(rangeDecoder);
|
||||
return _lowCoder[posState].NotNull().Decode(rangeDecoder);
|
||||
}
|
||||
var symbol = Base.K_NUM_LOW_LEN_SYMBOLS;
|
||||
if (_choice2.Decode(rangeDecoder) == 0)
|
||||
{
|
||||
symbol += _midCoder[posState].Decode(rangeDecoder);
|
||||
symbol += _midCoder[posState].NotNull().Decode(rangeDecoder);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,7 +112,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
}
|
||||
}
|
||||
|
||||
private Decoder2[] _coders;
|
||||
private Decoder2[]? _coders;
|
||||
private int _numPrevBits;
|
||||
private int _numPosBits;
|
||||
private uint _posMask;
|
||||
@@ -134,10 +136,11 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var coders = _coders.NotNull();
|
||||
var numStates = (uint)1 << (_numPrevBits + _numPosBits);
|
||||
for (uint i = 0; i < numStates; i++)
|
||||
{
|
||||
_coders[i].Init();
|
||||
coders[i].Init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,17 +148,18 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
((pos & _posMask) << _numPrevBits) + (uint)(prevByte >> (8 - _numPrevBits));
|
||||
|
||||
public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte) =>
|
||||
_coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder);
|
||||
_coders.NotNull()[GetState(pos, prevByte)].DecodeNormal(rangeDecoder);
|
||||
|
||||
public byte DecodeWithMatchByte(
|
||||
RangeCoder.Decoder rangeDecoder,
|
||||
uint pos,
|
||||
byte prevByte,
|
||||
byte matchByte
|
||||
) => _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte);
|
||||
) =>
|
||||
_coders.NotNull()[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte);
|
||||
}
|
||||
|
||||
private OutWindow _outWindow;
|
||||
private OutWindow? _outWindow;
|
||||
|
||||
private readonly BitDecoder[] _isMatchDecoders = new BitDecoder[
|
||||
Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX
|
||||
@@ -285,32 +289,32 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
Stream outStream,
|
||||
long inSize,
|
||||
long outSize,
|
||||
ICodeProgress progress
|
||||
ICodeProgress? progress
|
||||
)
|
||||
{
|
||||
if (_outWindow is null)
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
_outWindow.Init(outStream);
|
||||
_outWindow.NotNull().Init(outStream);
|
||||
if (outSize > 0)
|
||||
{
|
||||
_outWindow.SetLimit(outSize);
|
||||
_outWindow.NotNull().SetLimit(outSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
_outWindow.SetLimit(long.MaxValue - _outWindow.Total);
|
||||
_outWindow.NotNull().SetLimit(long.MaxValue - _outWindow.NotNull().Total);
|
||||
}
|
||||
|
||||
var rangeDecoder = new RangeCoder.Decoder();
|
||||
rangeDecoder.Init(inStream);
|
||||
|
||||
Code(_dictionarySize, _outWindow, rangeDecoder);
|
||||
Code(_dictionarySize, _outWindow.NotNull(), rangeDecoder);
|
||||
|
||||
_outWindow.ReleaseStream();
|
||||
_outWindow.NotNull().ReleaseStream();
|
||||
rangeDecoder.ReleaseStream();
|
||||
|
||||
_outWindow.Dispose();
|
||||
_outWindow.NotNull().Dispose();
|
||||
_outWindow = null;
|
||||
}
|
||||
|
||||
@@ -473,6 +477,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
_outWindow.Train(stream);
|
||||
_outWindow.NotNull().Train(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public partial class LzmaStream
|
||||
_decoder.SetDecoderProperties(Properties);
|
||||
}
|
||||
|
||||
await _rangeDecoder.InitAsync(_inputStream, cancellationToken);
|
||||
await _rangeDecoder.InitAsync(_inputStream.NotNull(), cancellationToken);
|
||||
}
|
||||
else if (control > 0x02)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -17,7 +15,7 @@ internal partial class Encoder
|
||||
{
|
||||
var b = (byte)(temp + (_low >> 32));
|
||||
var buffer = new[] { b };
|
||||
await _stream.WriteAsync(buffer, 0, 1, cancellationToken).ConfigureAwait(false);
|
||||
await Stream.WriteAsync(buffer, 0, 1, cancellationToken).ConfigureAwait(false);
|
||||
temp = 0xFF;
|
||||
} while (--_cacheSize != 0);
|
||||
_cache = (byte)(((uint)_low) >> 24);
|
||||
@@ -72,7 +70,7 @@ internal partial class Encoder
|
||||
}
|
||||
|
||||
public async ValueTask FlushStreamAsync(CancellationToken cancellationToken = default) =>
|
||||
await _stream.FlushAsync(cancellationToken).ConfigureAwait(false);
|
||||
await Stream.FlushAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal partial class Decoder
|
||||
@@ -103,7 +101,7 @@ internal partial class Decoder
|
||||
while (_range < K_TOP_VALUE)
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
var read = await _stream
|
||||
var read = await Stream
|
||||
.ReadAsync(buffer, 0, 1, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
@@ -121,7 +119,7 @@ internal partial class Decoder
|
||||
if (_range < K_TOP_VALUE)
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
var read = await _stream
|
||||
var read = await Stream
|
||||
.ReadAsync(buffer, 0, 1, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
@@ -152,7 +150,7 @@ internal partial class Decoder
|
||||
|
||||
if (range < K_TOP_VALUE)
|
||||
{
|
||||
var read = await _stream
|
||||
var read = await Stream
|
||||
.ReadAsync(buffer, 0, 1, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -9,7 +7,7 @@ internal partial class Encoder
|
||||
{
|
||||
public const uint K_TOP_VALUE = (1 << 24);
|
||||
|
||||
private Stream _stream;
|
||||
private Stream? _stream;
|
||||
|
||||
public ulong _low;
|
||||
public uint _range;
|
||||
@@ -22,6 +20,8 @@ internal partial class Encoder
|
||||
|
||||
public void ReleaseStream() => _stream = null;
|
||||
|
||||
private Stream Stream => _stream.NotNull();
|
||||
|
||||
public void Init()
|
||||
{
|
||||
//StartPosition = Stream.Position;
|
||||
@@ -40,9 +40,9 @@ internal partial class Encoder
|
||||
}
|
||||
}
|
||||
|
||||
public void FlushStream() => _stream.Flush();
|
||||
public void FlushStream() => Stream.Flush();
|
||||
|
||||
public void CloseStream() => _stream.Dispose();
|
||||
public void CloseStream() => Stream.Dispose();
|
||||
|
||||
public void ShiftLow()
|
||||
{
|
||||
@@ -51,7 +51,7 @@ internal partial class Encoder
|
||||
var temp = _cache;
|
||||
do
|
||||
{
|
||||
_stream.WriteByte((byte)(temp + (_low >> 32)));
|
||||
Stream.WriteByte((byte)(temp + (_low >> 32)));
|
||||
temp = 0xFF;
|
||||
} while (--_cacheSize != 0);
|
||||
_cache = (byte)(((uint)_low) >> 24);
|
||||
@@ -86,7 +86,7 @@ internal partial class Decoder
|
||||
public uint _range;
|
||||
public uint _code;
|
||||
|
||||
public Stream _stream;
|
||||
public Stream? _stream;
|
||||
public long _total;
|
||||
|
||||
public void Init(Stream stream)
|
||||
@@ -97,7 +97,7 @@ internal partial class Decoder
|
||||
_range = 0xFFFFFFFF;
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
_code = (_code << 8) | (byte)_stream.ReadByte();
|
||||
_code = (_code << 8) | (byte)stream.ReadByte();
|
||||
}
|
||||
_total = 5;
|
||||
}
|
||||
@@ -106,11 +106,13 @@ internal partial class Decoder
|
||||
// Stream.ReleaseStream();
|
||||
_stream = null;
|
||||
|
||||
private Stream Stream => _stream.NotNull();
|
||||
|
||||
public void Normalize()
|
||||
{
|
||||
while (_range < K_TOP_VALUE)
|
||||
{
|
||||
_code = (_code << 8) | (byte)_stream.ReadByte();
|
||||
_code = (_code << 8) | (byte)Stream.ReadByte();
|
||||
_range <<= 8;
|
||||
_total++;
|
||||
}
|
||||
@@ -121,7 +123,7 @@ internal partial class Decoder
|
||||
{
|
||||
if (_range < K_TOP_VALUE)
|
||||
{
|
||||
_code = (_code << 8) | (byte)_stream.ReadByte();
|
||||
_code = (_code << 8) | (byte)Stream.ReadByte();
|
||||
_range <<= 8;
|
||||
_total++;
|
||||
}
|
||||
@@ -150,7 +152,7 @@ internal partial class Decoder
|
||||
|
||||
if (range < K_TOP_VALUE)
|
||||
{
|
||||
code = (code << 8) | (byte)_stream.ReadByte();
|
||||
code = (code << 8) | (byte)Stream.ReadByte();
|
||||
range <<= 8;
|
||||
_total++;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -15,9 +13,9 @@ public class PpmdStream : Stream
|
||||
private readonly PpmdProperties _properties;
|
||||
private readonly Stream _stream;
|
||||
private readonly bool _compress;
|
||||
private Model _model;
|
||||
private ModelPpm _modelH;
|
||||
private Decoder _decoder;
|
||||
private Model? _model;
|
||||
private ModelPpm? _modelH;
|
||||
private Decoder? _decoder;
|
||||
private long _position;
|
||||
private bool _isDisposed;
|
||||
|
||||
@@ -178,7 +176,7 @@ public class PpmdStream : Stream
|
||||
{
|
||||
if (_compress)
|
||||
{
|
||||
_model.EncodeBlock(_stream, new MemoryStream(), true);
|
||||
_model.NotNull().EncodeBlock(_stream, new MemoryStream(), true);
|
||||
}
|
||||
}
|
||||
base.Dispose(isDisposing);
|
||||
@@ -201,12 +199,12 @@ public class PpmdStream : Stream
|
||||
var size = 0;
|
||||
if (_properties.Version == PpmdVersion.I1)
|
||||
{
|
||||
size = _model.DecodeBlock(_stream, buffer, offset, count);
|
||||
size = _model.NotNull().DecodeBlock(_stream, buffer, offset, count);
|
||||
}
|
||||
if (_properties.Version == PpmdVersion.H)
|
||||
{
|
||||
int c;
|
||||
while (size < count && (c = _modelH.DecodeChar()) >= 0)
|
||||
while (size < count && (c = _modelH.NotNull().DecodeChar()) >= 0)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
size++;
|
||||
@@ -215,7 +213,7 @@ public class PpmdStream : Stream
|
||||
if (_properties.Version == PpmdVersion.H7Z)
|
||||
{
|
||||
int c;
|
||||
while (size < count && (c = _modelH.DecodeChar(_decoder)) >= 0)
|
||||
while (size < count && (c = _modelH.NotNull().DecodeChar(_decoder.NotNull())) >= 0)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
size++;
|
||||
@@ -247,6 +245,7 @@ public class PpmdStream : Stream
|
||||
if (_properties.Version == PpmdVersion.I1)
|
||||
{
|
||||
size = await _model
|
||||
.NotNull()
|
||||
.DecodeBlockAsync(_stream, buffer, offset, count, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -255,7 +254,12 @@ public class PpmdStream : Stream
|
||||
int c;
|
||||
while (
|
||||
size < count
|
||||
&& (c = await _modelH.DecodeCharAsync(cancellationToken).ConfigureAwait(false)) >= 0
|
||||
&& (
|
||||
c = await _modelH
|
||||
.NotNull()
|
||||
.DecodeCharAsync(cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
@@ -269,7 +273,8 @@ public class PpmdStream : Stream
|
||||
size < count
|
||||
&& (
|
||||
c = await _modelH
|
||||
.DecodeCharAsync(_decoder, cancellationToken)
|
||||
.NotNull()
|
||||
.DecodeCharAsync(_decoder.NotNull(), cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
@@ -304,6 +309,7 @@ public class PpmdStream : Stream
|
||||
// Need to use a temporary buffer since DecodeBlockAsync works with byte[]
|
||||
var tempBuffer = new byte[count];
|
||||
size = await _model
|
||||
.NotNull()
|
||||
.DecodeBlockAsync(_stream, tempBuffer, 0, count, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
tempBuffer.AsMemory(0, size).CopyTo(buffer);
|
||||
@@ -313,7 +319,12 @@ public class PpmdStream : Stream
|
||||
int c;
|
||||
while (
|
||||
size < count
|
||||
&& (c = await _modelH.DecodeCharAsync(cancellationToken).ConfigureAwait(false)) >= 0
|
||||
&& (
|
||||
c = await _modelH
|
||||
.NotNull()
|
||||
.DecodeCharAsync(cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
{
|
||||
buffer.Span[offset++] = (byte)c;
|
||||
@@ -327,7 +338,8 @@ public class PpmdStream : Stream
|
||||
size < count
|
||||
&& (
|
||||
c = await _modelH
|
||||
.DecodeCharAsync(_decoder, cancellationToken)
|
||||
.NotNull()
|
||||
.DecodeCharAsync(_decoder.NotNull(), cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
@@ -345,7 +357,7 @@ public class PpmdStream : Stream
|
||||
{
|
||||
if (_compress)
|
||||
{
|
||||
_model.EncodeBlock(_stream, new MemoryStream(buffer, offset, count), false);
|
||||
_model.NotNull().EncodeBlock(_stream, new MemoryStream(buffer, offset, count), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
@@ -47,7 +45,7 @@ internal partial class RarStream
|
||||
if (tmpCount > 0)
|
||||
{
|
||||
var toCopy = tmpCount < count ? tmpCount : count;
|
||||
Buffer.BlockCopy(tmpBuffer, tmpOffset, buffer, offset, toCopy);
|
||||
Buffer.BlockCopy(tmpBuffer.NotNull(), tmpOffset, buffer, offset, toCopy);
|
||||
tmpOffset += toCopy;
|
||||
tmpCount -= toCopy;
|
||||
offset += toCopy;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
@@ -15,11 +13,11 @@ internal partial class RarStream : Stream
|
||||
|
||||
private bool fetch;
|
||||
|
||||
private byte[] tmpBuffer = ArrayPool<byte>.Shared.Rent(65536);
|
||||
private byte[]? tmpBuffer = ArrayPool<byte>.Shared.Rent(65536);
|
||||
private int tmpOffset;
|
||||
private int tmpCount;
|
||||
|
||||
private byte[] outBuffer;
|
||||
private byte[]? outBuffer;
|
||||
private int outOffset;
|
||||
private int outCount;
|
||||
private int outTotal;
|
||||
@@ -47,8 +45,11 @@ internal partial class RarStream : Stream
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(this.tmpBuffer);
|
||||
this.tmpBuffer = null;
|
||||
if (this.tmpBuffer is not null)
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(this.tmpBuffer);
|
||||
this.tmpBuffer = null;
|
||||
}
|
||||
readStream.Dispose();
|
||||
}
|
||||
isDisposed = true;
|
||||
@@ -79,7 +80,7 @@ internal partial class RarStream : Stream
|
||||
if (tmpCount > 0)
|
||||
{
|
||||
var toCopy = tmpCount < count ? tmpCount : count;
|
||||
Buffer.BlockCopy(tmpBuffer, tmpOffset, buffer, offset, toCopy);
|
||||
Buffer.BlockCopy(tmpBuffer.NotNull(), tmpOffset, buffer, offset, toCopy);
|
||||
tmpOffset += toCopy;
|
||||
tmpCount -= toCopy;
|
||||
offset += toCopy;
|
||||
@@ -119,7 +120,7 @@ internal partial class RarStream : Stream
|
||||
if (outCount > 0)
|
||||
{
|
||||
var toCopy = outCount < count ? outCount : count;
|
||||
Buffer.BlockCopy(buffer, offset, outBuffer, outOffset, toCopy);
|
||||
Buffer.BlockCopy(buffer, offset, outBuffer.NotNull(), outOffset, toCopy);
|
||||
outOffset += toCopy;
|
||||
outCount -= toCopy;
|
||||
offset += toCopy;
|
||||
@@ -129,7 +130,7 @@ internal partial class RarStream : Stream
|
||||
if (count > 0)
|
||||
{
|
||||
EnsureBufferCapacity(count);
|
||||
Buffer.BlockCopy(buffer, offset, tmpBuffer, tmpCount, count);
|
||||
Buffer.BlockCopy(buffer, offset, tmpBuffer.NotNull(), tmpCount, count);
|
||||
tmpCount += count;
|
||||
tmpOffset = 0;
|
||||
unpack.Suspended = true;
|
||||
@@ -142,15 +143,16 @@ internal partial class RarStream : Stream
|
||||
|
||||
private void EnsureBufferCapacity(int count)
|
||||
{
|
||||
if (this.tmpBuffer.Length < this.tmpCount + count)
|
||||
var buffer = this.tmpBuffer.NotNull();
|
||||
if (buffer.Length < this.tmpCount + count)
|
||||
{
|
||||
var newLength =
|
||||
this.tmpBuffer.Length * 2 > this.tmpCount + count
|
||||
? this.tmpBuffer.Length * 2
|
||||
buffer.Length * 2 > this.tmpCount + count
|
||||
? buffer.Length * 2
|
||||
: this.tmpCount + count;
|
||||
var newBuffer = ArrayPool<byte>.Shared.Rent(newLength);
|
||||
Buffer.BlockCopy(this.tmpBuffer, 0, newBuffer, 0, this.tmpCount);
|
||||
var oldBuffer = this.tmpBuffer;
|
||||
Buffer.BlockCopy(buffer, 0, newBuffer, 0, this.tmpCount);
|
||||
var oldBuffer = buffer;
|
||||
this.tmpBuffer = newBuffer;
|
||||
ArrayPool<byte>.Shared.Return(oldBuffer);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Compressors.Xz;
|
||||
@@ -10,7 +8,7 @@ public static class Crc32
|
||||
public const uint DefaultPolynomial = 0xedb88320u;
|
||||
public const uint DefaultSeed = 0xffffffffu;
|
||||
|
||||
private static uint[] defaultTable;
|
||||
private static uint[]? defaultTable;
|
||||
|
||||
public static uint Compute(byte[] buffer) => Compute(DefaultSeed, buffer);
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Compressors.Xz;
|
||||
@@ -9,7 +7,7 @@ public static class Crc64
|
||||
{
|
||||
public const ulong DefaultSeed = 0x0;
|
||||
|
||||
internal static ulong[] Table;
|
||||
internal static ulong[]? Table;
|
||||
|
||||
public const ulong Iso3309Polynomial = 0xD800000000000000;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -36,7 +34,7 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
|
||||
private void AssertBlockCheckTypeIsSupported()
|
||||
{
|
||||
switch (Header.BlockCheckType)
|
||||
switch (Header.NotNull().BlockCheckType)
|
||||
{
|
||||
case CheckType.NONE:
|
||||
case CheckType.CRC32:
|
||||
@@ -49,11 +47,11 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
}
|
||||
|
||||
private readonly Stream _baseStream;
|
||||
public XZHeader Header { get; private set; }
|
||||
public XZIndex Index { get; private set; }
|
||||
public XZFooter Footer { get; private set; }
|
||||
public XZHeader? Header { get; private set; }
|
||||
public XZIndex? Index { get; private set; }
|
||||
public XZFooter? Footer { get; private set; }
|
||||
public bool HeaderIsRead { get; private set; }
|
||||
private XZBlock _currentBlock;
|
||||
private XZBlock? _currentBlock;
|
||||
|
||||
private bool _endOfStream;
|
||||
|
||||
@@ -113,7 +111,7 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
|
||||
var remaining = count - bytesRead;
|
||||
var newOffset = offset + bytesRead;
|
||||
var justRead = _currentBlock.Read(buffer, newOffset, remaining);
|
||||
var justRead = _currentBlock.NotNull().Read(buffer, newOffset, remaining);
|
||||
if (justRead < remaining)
|
||||
{
|
||||
NextBlock();
|
||||
@@ -130,5 +128,9 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
}
|
||||
|
||||
private void NextBlock() =>
|
||||
_currentBlock = new XZBlock(BaseStream, Header.BlockCheckType, Header.BlockCheckSize);
|
||||
_currentBlock = new XZBlock(
|
||||
BaseStream,
|
||||
Header.NotNull().BlockCheckType,
|
||||
Header.NotNull().BlockCheckSize
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
@@ -15,7 +13,7 @@ public sealed class Crc32Stream : Stream
|
||||
public const uint DEFAULT_POLYNOMIAL = 0xedb88320u;
|
||||
public const uint DEFAULT_SEED = 0xffffffffu;
|
||||
|
||||
private static uint[] _defaultTable;
|
||||
private static uint[]? _defaultTable;
|
||||
|
||||
public Crc32Stream(Stream stream)
|
||||
: this(stream, DEFAULT_POLYNOMIAL, DEFAULT_SEED) { }
|
||||
|
||||
@@ -18,7 +18,6 @@ public abstract class Factory : IFactory
|
||||
RegisterFactory(new RarFactory());
|
||||
RegisterFactory(new TarFactory()); //put tar before most
|
||||
RegisterFactory(new GZipFactory());
|
||||
RegisterFactory(new LzwFactory());
|
||||
RegisterFactory(new ArcFactory());
|
||||
RegisterFactory(new ArjFactory());
|
||||
RegisterFactory(new AceFactory());
|
||||
|
||||
@@ -93,9 +93,11 @@ public class GZipFactory
|
||||
/// <inheritdoc/>
|
||||
public IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
@@ -164,8 +166,13 @@ public class GZipFactory
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IAsyncWriter OpenAsyncWriter(Stream stream, WriterOptions writerOptions)
|
||||
public IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
WriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
if (writerOptions.CompressionType != CompressionType.GZip)
|
||||
{
|
||||
throw new InvalidFormatException("GZip archives only support GZip compression type.");
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Archives.Tar;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors.Lzw;
|
||||
using SharpCompress.IO;
|
||||
using SharpCompress.Readers;
|
||||
using SharpCompress.Readers.Lzw;
|
||||
using SharpCompress.Readers.Tar;
|
||||
|
||||
namespace SharpCompress.Factories;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the foundation factory of LZW archive.
|
||||
/// </summary>
|
||||
public class LzwFactory : Factory, IReaderFactory
|
||||
{
|
||||
#region IFactory
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string Name => "Lzw";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ArchiveType? KnownArchiveType => ArchiveType.Lzw;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<string> GetSupportedExtensions()
|
||||
{
|
||||
yield return "z";
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool IsArchive(Stream stream, string? password = null) =>
|
||||
LzwStream.IsLzwStream(stream);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ValueTask<bool> IsArchiveAsync(
|
||||
Stream stream,
|
||||
string? password = null,
|
||||
CancellationToken cancellationToken = default
|
||||
) => LzwStream.IsLzwStreamAsync(stream, cancellationToken);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IReaderFactory
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override bool TryOpenReader(
|
||||
SharpCompressStream sharpCompressStream,
|
||||
ReaderOptions options,
|
||||
out IReader? reader
|
||||
)
|
||||
{
|
||||
reader = null;
|
||||
|
||||
if (LzwStream.IsLzwStream(sharpCompressStream))
|
||||
{
|
||||
sharpCompressStream.Rewind();
|
||||
using (var testStream = new LzwStream(sharpCompressStream) { IsStreamOwner = false })
|
||||
{
|
||||
if (TarArchive.IsTarFile(testStream))
|
||||
{
|
||||
sharpCompressStream.StopRecording();
|
||||
reader = new TarReader(sharpCompressStream, options, CompressionType.Lzw);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sharpCompressStream.StopRecording();
|
||||
reader = OpenReader(sharpCompressStream, options);
|
||||
return true;
|
||||
}
|
||||
sharpCompressStream.Rewind();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReader OpenReader(Stream stream, ReaderOptions? options) =>
|
||||
LzwReader.OpenReader(stream, options);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ValueTask<IAsyncReader> OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? options,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return new(LzwReader.OpenAsyncReader(stream, options));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -90,9 +90,11 @@ public class RarFactory : Factory, IArchiveFactory, IMultiArchiveFactory, IReade
|
||||
/// <inheritdoc/>
|
||||
public IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SevenZipFactory : Factory, IArchiveFactory, IMultiArchiveFactory
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IAsyncArchive OpenAsyncArchive(Stream stream, ReaderOptions? readerOptions = null) =>
|
||||
SevenZipArchive.OpenAsyncArchive(stream, readerOptions);
|
||||
SevenZipArchive.OpenAsyncArchive(stream, readerOptions, CancellationToken.None);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IArchive OpenArchive(FileInfo fileInfo, ReaderOptions? readerOptions = null) =>
|
||||
@@ -58,7 +58,7 @@ public class SevenZipFactory : Factory, IArchiveFactory, IMultiArchiveFactory
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IAsyncArchive OpenAsyncArchive(FileInfo fileInfo, ReaderOptions? readerOptions = null) =>
|
||||
SevenZipArchive.OpenAsyncArchive(fileInfo, readerOptions);
|
||||
SevenZipArchive.OpenAsyncArchive(fileInfo, readerOptions, CancellationToken.None);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -74,7 +74,7 @@ public class SevenZipFactory : Factory, IArchiveFactory, IMultiArchiveFactory
|
||||
public IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
) => SevenZipArchive.OpenAsyncArchive(streams, readerOptions);
|
||||
) => SevenZipArchive.OpenAsyncArchive(streams, readerOptions, CancellationToken.None);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IArchive OpenArchive(
|
||||
@@ -85,8 +85,9 @@ public class SevenZipFactory : Factory, IArchiveFactory, IMultiArchiveFactory
|
||||
/// <inheritdoc/>
|
||||
public IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
) => SevenZipArchive.OpenAsyncArchive(fileInfos, readerOptions);
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
) => SevenZipArchive.OpenAsyncArchive(fileInfos, readerOptions, cancellationToken);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -144,9 +144,11 @@ public class TarFactory
|
||||
/// <inheritdoc/>
|
||||
public IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
@@ -218,8 +220,13 @@ public class TarFactory
|
||||
new TarWriter(stream, new TarWriterOptions(writerOptions));
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IAsyncWriter OpenAsyncWriter(Stream stream, WriterOptions writerOptions)
|
||||
public IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
WriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,9 +153,11 @@ public class ZipFactory
|
||||
/// <inheritdoc/>
|
||||
public IAsyncArchive OpenAsyncArchive(
|
||||
IReadOnlyList<FileInfo> fileInfos,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncArchive)OpenArchive(fileInfos, readerOptions);
|
||||
}
|
||||
|
||||
@@ -187,8 +189,13 @@ public class ZipFactory
|
||||
new ZipWriter(stream, new ZipWriterOptions(writerOptions));
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IAsyncWriter OpenAsyncWriter(Stream stream, WriterOptions writerOptions)
|
||||
public IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
WriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -43,7 +41,7 @@ internal sealed class LazyReadOnlyCollection<T> : ICollection<T>
|
||||
|
||||
#region IEnumerator Members
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
object? IEnumerator.Current => Current;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Readers.Ace;
|
||||
@@ -33,14 +34,24 @@ public partial class AceReader
|
||||
return new MultiVolumeAceReader(streams, options ?? new ReaderOptions());
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
@@ -55,9 +66,11 @@ public partial class AceReader
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,7 +13,7 @@ namespace SharpCompress.Readers.Ace;
|
||||
internal class MultiVolumeAceReader : AceReader
|
||||
{
|
||||
private readonly IEnumerator<Stream> streams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
|
||||
internal MultiVolumeAceReader(IEnumerable<Stream> streams, ReaderOptions options)
|
||||
: base(options) => this.streams = streams.GetEnumerator();
|
||||
@@ -54,13 +52,13 @@ internal class MultiVolumeAceReader : AceReader
|
||||
{
|
||||
private readonly MultiVolumeAceReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamEnumerator(
|
||||
MultiVolumeAceReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -72,7 +70,12 @@ internal class MultiVolumeAceReader : AceReader
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => this;
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
@@ -82,7 +85,7 @@ internal class MultiVolumeAceReader : AceReader
|
||||
{
|
||||
if (isFirst)
|
||||
{
|
||||
Current = reader.Entry.Parts.First();
|
||||
_current = reader.Entry.Parts.First();
|
||||
isFirst = false; //first stream already to go
|
||||
return true;
|
||||
}
|
||||
@@ -93,7 +96,7 @@ internal class MultiVolumeAceReader : AceReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
reader.LoadStreamForReading(tempStream);
|
||||
reader.LoadStreamForReading(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
@@ -107,7 +110,7 @@ internal class MultiVolumeAceReader : AceReader
|
||||
reader.LoadStreamForReading(nextReadableStreams.Current);
|
||||
}
|
||||
|
||||
Current = reader.Entry.Parts.First();
|
||||
_current = reader.Entry.Parts.First();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Readers.Arc;
|
||||
|
||||
public partial class ArcReader : IReaderOpenable
|
||||
{
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Readers.Arj;
|
||||
|
||||
public partial class ArjReader : IReaderOpenable
|
||||
{
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,7 +14,7 @@ namespace SharpCompress.Readers.Arj;
|
||||
internal class MultiVolumeArjReader : ArjReader
|
||||
{
|
||||
private readonly IEnumerator<Stream> streams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
|
||||
internal MultiVolumeArjReader(IEnumerable<Stream> streams, ReaderOptions options)
|
||||
: base(options) => this.streams = streams.GetEnumerator();
|
||||
@@ -55,13 +53,13 @@ internal class MultiVolumeArjReader : ArjReader
|
||||
{
|
||||
private readonly MultiVolumeArjReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamEnumerator(
|
||||
MultiVolumeArjReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -73,7 +71,12 @@ internal class MultiVolumeArjReader : ArjReader
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => this;
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
@@ -94,7 +97,7 @@ internal class MultiVolumeArjReader : ArjReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
reader.LoadStreamForReading(tempStream);
|
||||
reader.LoadStreamForReading(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace SharpCompress.Readers.GZip;
|
||||
|
||||
@@ -7,22 +8,34 @@ public partial class GZipReader
|
||||
: IReaderOpenable
|
||||
#endif
|
||||
{
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,17 +17,20 @@ public interface IReaderOpenable
|
||||
|
||||
public static abstract IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public static abstract IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public static abstract IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Lzw;
|
||||
|
||||
namespace SharpCompress.Readers.Lzw;
|
||||
|
||||
public partial class LzwReader
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns entries asynchronously for streams that only support async reads.
|
||||
/// </summary>
|
||||
protected override IAsyncEnumerable<LzwEntry> GetEntriesAsync(Stream stream) =>
|
||||
LzwEntry.GetEntriesAsync(stream, Options);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace SharpCompress.Readers.Lzw;
|
||||
|
||||
public partial class LzwReader
|
||||
#if NET8_0_OR_GREATER
|
||||
: IReaderOpenable
|
||||
#endif
|
||||
{
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
{
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
{
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
)
|
||||
{
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
public static IReader OpenReader(string filePath, ReaderOptions? readerOptions = null)
|
||||
{
|
||||
filePath.NotNullOrEmpty(nameof(filePath));
|
||||
return OpenReader(new FileInfo(filePath), readerOptions);
|
||||
}
|
||||
|
||||
public static IReader OpenReader(FileInfo fileInfo, ReaderOptions? readerOptions = null)
|
||||
{
|
||||
fileInfo.NotNull(nameof(fileInfo));
|
||||
return OpenReader(fileInfo.OpenRead(), readerOptions);
|
||||
}
|
||||
|
||||
public static IReader OpenReader(Stream stream, ReaderOptions? options = null)
|
||||
{
|
||||
stream.NotNull(nameof(stream));
|
||||
return new LzwReader(stream, options ?? new ReaderOptions());
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Lzw;
|
||||
|
||||
namespace SharpCompress.Readers.Lzw;
|
||||
|
||||
public partial class LzwReader : AbstractReader<LzwEntry, LzwVolume>
|
||||
{
|
||||
private LzwReader(Stream stream, ReaderOptions options)
|
||||
: base(options, ArchiveType.Lzw) => Volume = new LzwVolume(stream, options, 0);
|
||||
|
||||
public override LzwVolume Volume { get; }
|
||||
|
||||
protected override IEnumerable<LzwEntry> GetEntries(Stream stream) =>
|
||||
LzwEntry.GetEntries(stream, Options);
|
||||
|
||||
// GetEntriesAsync moved to LzwReader.Async.cs
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -26,13 +24,13 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
{
|
||||
private readonly MultiVolumeRarReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamAsyncEnumerator(
|
||||
MultiVolumeRarReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -40,7 +38,12 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
this.tempStream = tempStream;
|
||||
}
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> MoveNextAsync()
|
||||
{
|
||||
@@ -57,7 +60,7 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
await reader.LoadStreamForReadingAsync(tempStream);
|
||||
await reader.LoadStreamForReadingAsync(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -14,7 +12,7 @@ namespace SharpCompress.Readers.Rar;
|
||||
internal partial class MultiVolumeRarReader : RarReader
|
||||
{
|
||||
private readonly IEnumerator<Stream> streams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
|
||||
internal MultiVolumeRarReader(IEnumerable<Stream> streams, ReaderOptions options)
|
||||
: base(options) => this.streams = streams.GetEnumerator();
|
||||
@@ -55,13 +53,13 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
{
|
||||
private readonly MultiVolumeRarReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamEnumerator(
|
||||
MultiVolumeRarReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -73,7 +71,12 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => this;
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
@@ -94,7 +97,7 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
reader.LoadStreamForReading(tempStream);
|
||||
reader.LoadStreamForReading(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Readers.Rar;
|
||||
|
||||
public partial class RarReader : IReaderOpenable
|
||||
{
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public static partial class ReaderFactory
|
||||
}
|
||||
|
||||
throw new InvalidFormatException(
|
||||
"Cannot determine compressed stream type. Supported Reader Formats: Ace, Arc, Arj, Zip, GZip, BZip2, Tar, Rar, LZip, Lzw, XZ, ZStandard"
|
||||
"Cannot determine compressed stream type. Supported Reader Formats: Ace, Arc, Arj, Zip, GZip, BZip2, Tar, Rar, LZip, XZ, ZStandard"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Readers.Tar;
|
||||
@@ -8,22 +9,34 @@ public partial class TarReader
|
||||
: IReaderOpenable
|
||||
#endif
|
||||
{
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,40 @@
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Readers.Zip;
|
||||
|
||||
public partial class ZipReader : IReaderOpenable
|
||||
{
|
||||
public static IAsyncReader OpenAsyncReader(string path, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
string path,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
path.NotNullOrEmpty(nameof(path));
|
||||
return (IAsyncReader)OpenReader(new FileInfo(path), readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(Stream stream, ReaderOptions? readerOptions = null)
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(stream, readerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncReader OpenAsyncReader(
|
||||
FileInfo fileInfo,
|
||||
ReaderOptions? readerOptions = null
|
||||
ReaderOptions? readerOptions = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncReader)OpenReader(fileInfo, readerOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers.GZip;
|
||||
@@ -24,18 +25,33 @@ public partial class GZipWriter : IWriterOpenable<GZipWriterOptions>
|
||||
return new GZipWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(string path, GZipWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
string path,
|
||||
GZipWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(path, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(Stream stream, GZipWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
GZipWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(FileInfo fileInfo, GZipWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
FileInfo fileInfo,
|
||||
GZipWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Factories;
|
||||
|
||||
namespace SharpCompress.Writers;
|
||||
@@ -7,5 +8,9 @@ public interface IWriterFactory : IFactory
|
||||
{
|
||||
IWriter OpenWriter(Stream stream, WriterOptions writerOptions);
|
||||
|
||||
IAsyncWriter OpenAsyncWriter(Stream stream, WriterOptions writerOptions);
|
||||
IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
WriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,20 +18,24 @@ public interface IWriterOpenable<TWriterOptions>
|
||||
/// <param name="stream">The stream to write to.</param>
|
||||
/// <param name="archiveType">The archive type.</param>
|
||||
/// <param name="writerOptions">Writer options.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A task that returns an IWriter.</returns>
|
||||
public static abstract IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
TWriterOptions writerOptions
|
||||
TWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public static abstract IAsyncWriter OpenAsyncWriter(
|
||||
string filePath,
|
||||
TWriterOptions writerOptions
|
||||
TWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
public static abstract IAsyncWriter OpenAsyncWriter(
|
||||
FileInfo fileInfo,
|
||||
TWriterOptions writerOptions
|
||||
TWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers.Tar;
|
||||
@@ -24,18 +25,33 @@ public partial class TarWriter : IWriterOpenable<TarWriterOptions>
|
||||
return new TarWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(string path, TarWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
string path,
|
||||
TarWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(path, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(Stream stream, TarWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
TarWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(FileInfo fileInfo, TarWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
FileInfo fileInfo,
|
||||
TarWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers;
|
||||
@@ -30,24 +31,32 @@ public static class WriterFactory
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
string filePath,
|
||||
ArchiveType archiveType,
|
||||
WriterOptions writerOptions
|
||||
WriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
filePath.NotNullOrEmpty(nameof(filePath));
|
||||
return OpenAsyncWriter(new FileInfo(filePath), archiveType, writerOptions);
|
||||
return OpenAsyncWriter(
|
||||
new FileInfo(filePath),
|
||||
archiveType,
|
||||
writerOptions,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
FileInfo fileInfo,
|
||||
ArchiveType archiveType,
|
||||
WriterOptions writerOptions
|
||||
WriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
fileInfo.NotNull(nameof(fileInfo));
|
||||
return OpenAsyncWriter(
|
||||
fileInfo.Open(FileMode.Create, FileAccess.Write),
|
||||
archiveType,
|
||||
writerOptions
|
||||
writerOptions,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,11 +84,13 @@ public static class WriterFactory
|
||||
/// <param name="stream">The stream to write to.</param>
|
||||
/// <param name="archiveType">The archive type.</param>
|
||||
/// <param name="writerOptions">Writer options.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A task that returns an IWriter.</returns>
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
ArchiveType archiveType,
|
||||
WriterOptions writerOptions
|
||||
WriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
var factory = Factories
|
||||
@@ -88,7 +99,7 @@ public static class WriterFactory
|
||||
|
||||
if (factory != null)
|
||||
{
|
||||
return factory.OpenAsyncWriter(stream, writerOptions);
|
||||
return factory.OpenAsyncWriter(stream, writerOptions, cancellationToken);
|
||||
}
|
||||
|
||||
throw new NotSupportedException("Archive Type does not have a Writer: " + archiveType);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers.Zip;
|
||||
@@ -24,18 +25,33 @@ public partial class ZipWriter : IWriterOpenable<ZipWriterOptions>
|
||||
return new ZipWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(string path, ZipWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
string path,
|
||||
ZipWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(path, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(Stream stream, ZipWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
ZipWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(FileInfo fileInfo, ZipWriterOptions writerOptions)
|
||||
public static IAsyncWriter OpenAsyncWriter(
|
||||
FileInfo fileInfo,
|
||||
ZipWriterOptions writerOptions,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return (IAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,9 +216,9 @@
|
||||
"net10.0": {
|
||||
"Microsoft.NET.ILLink.Tasks": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.0, )",
|
||||
"resolved": "10.0.0",
|
||||
"contentHash": "kICGrGYEzCNI3wPzfEXcwNHgTvlvVn9yJDhSdRK+oZQy4jvYH529u7O0xf5ocQKzOMjfS07+3z9PKRIjrFMJDA=="
|
||||
"requested": "[10.0.2, )",
|
||||
"resolved": "10.0.2",
|
||||
"contentHash": "sXdDtMf2qcnbygw9OdE535c2lxSxrZP8gO4UhDJ0xiJbl1wIqXS1OTcTDFTIJPOFd6Mhcm8gPEthqWGUxBsTqw=="
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
@@ -264,9 +264,9 @@
|
||||
"net8.0": {
|
||||
"Microsoft.NET.ILLink.Tasks": {
|
||||
"type": "Direct",
|
||||
"requested": "[8.0.22, )",
|
||||
"resolved": "8.0.22",
|
||||
"contentHash": "MhcMithKEiyyNkD2ZfbDZPmcOdi0GheGfg8saEIIEfD/fol3iHmcV8TsZkD4ZYz5gdUuoX4YtlVySUU7Sxl9SQ=="
|
||||
"requested": "[8.0.23, )",
|
||||
"resolved": "8.0.23",
|
||||
"contentHash": "GqHiB1HbbODWPbY/lc5xLQH8siEEhNA0ptpJCC6X6adtAYNEzu5ZlqV3YHA3Gh7fuEwgA8XqVwMtH2KNtuQM1Q=="
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Readers;
|
||||
using SharpCompress.Readers.Lzw;
|
||||
using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Lzw;
|
||||
|
||||
public class LzwReaderAsyncTests : ReaderTests
|
||||
{
|
||||
public LzwReaderAsyncTests() => UseExtensionInsteadOfNameToVerify = true;
|
||||
|
||||
[Fact]
|
||||
public async System.Threading.Tasks.Task Lzw_Reader_Async()
|
||||
{
|
||||
await ReadAsync("Tar.tar.Z", CompressionType.Lzw);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async System.Threading.Tasks.Task Lzw_Reader_Plain_Z_File_Async()
|
||||
{
|
||||
// Test async reading of a plain .Z file (not tar-wrapped) using LzwReader directly
|
||||
using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "large_test.txt.Z"));
|
||||
using var reader = LzwReader.OpenReader(stream);
|
||||
|
||||
Assert.Equal(ArchiveType.Lzw, reader.ArchiveType);
|
||||
Assert.True(reader.MoveToNextEntry());
|
||||
|
||||
var entry = reader.Entry;
|
||||
Assert.NotNull(entry);
|
||||
Assert.Equal(CompressionType.Lzw, entry.CompressionType);
|
||||
|
||||
// When opened as FileStream, key should be derived from filename
|
||||
Assert.Equal("large_test.txt", entry.Key);
|
||||
|
||||
// Decompress asynchronously
|
||||
using var entryStream = reader.OpenEntryStream();
|
||||
using var ms = new MemoryStream();
|
||||
await entryStream.CopyToAsync(ms);
|
||||
|
||||
Assert.Equal(22300, ms.Length);
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
using SharpCompress.Readers;
|
||||
using SharpCompress.Readers.Lzw;
|
||||
using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Lzw;
|
||||
|
||||
public class LzwReaderTests : ReaderTests
|
||||
{
|
||||
public LzwReaderTests() => UseExtensionInsteadOfNameToVerify = true;
|
||||
|
||||
[Fact]
|
||||
public void Lzw_Reader_Generic() => Read("Tar.tar.Z", CompressionType.Lzw);
|
||||
|
||||
[Fact]
|
||||
public void Lzw_Reader_Generic2()
|
||||
{
|
||||
//read only as Lzw item
|
||||
using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.Z"));
|
||||
using var reader = LzwReader.OpenReader(SharpCompressStream.CreateNonDisposing(stream));
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
// LZW doesn't have CRC or Size in header like GZip, so we just check the entry exists
|
||||
Assert.NotNull(reader.Entry);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lzw_Reader_Factory_Detects_Tar_Wrapper()
|
||||
{
|
||||
// Note: Testing with Tar.tar.Z because:
|
||||
// 1. LzwStream only supports decompression, not compression
|
||||
// 2. This tests the important tar wrapper detection code path in LzwFactory.TryOpenReader
|
||||
// 3. Verifies that tar.Z files correctly return TarReader with CompressionType.Lzw
|
||||
using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.Z"));
|
||||
using var reader = ReaderFactory.OpenReader(
|
||||
stream,
|
||||
new ReaderOptions { LeaveStreamOpen = false }
|
||||
);
|
||||
|
||||
// Should detect as Tar archive with Lzw compression
|
||||
Assert.Equal(ArchiveType.Tar, reader.ArchiveType);
|
||||
Assert.True(reader.MoveToNextEntry());
|
||||
Assert.NotNull(reader.Entry);
|
||||
Assert.Equal(CompressionType.Lzw, reader.Entry.CompressionType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lzw_Reader_Plain_Z_File()
|
||||
{
|
||||
// Test with a plain .Z file (not tar-wrapped) using LzwReader directly
|
||||
using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "large_test.txt.Z"));
|
||||
using var reader = LzwReader.OpenReader(stream);
|
||||
|
||||
Assert.True(reader.MoveToNextEntry());
|
||||
var entry = reader.Entry;
|
||||
Assert.NotNull(entry);
|
||||
Assert.Equal(CompressionType.Lzw, entry.CompressionType);
|
||||
|
||||
// Entry key should be "large_test.txt" (stripped .Z extension) when opened via FileStream
|
||||
Assert.Equal("large_test.txt", entry.Key);
|
||||
|
||||
// Decompress and verify content
|
||||
using var entryStream = reader.OpenEntryStream();
|
||||
using var ms = new MemoryStream();
|
||||
entryStream.CopyTo(ms);
|
||||
var decompressed = System.Text.Encoding.UTF8.GetString(ms.ToArray());
|
||||
|
||||
Assert.Equal(22300, ms.Length);
|
||||
Assert.Contains("This is a test file for LZW compression testing", decompressed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lzw_Reader_Factory_Detects_Plain_Z_File()
|
||||
{
|
||||
// Test that ReaderFactory correctly identifies a plain .Z file (not tar-wrapped)
|
||||
using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "large_test.txt.Z"));
|
||||
using var reader = ReaderFactory.OpenReader(stream);
|
||||
|
||||
// Should detect as Lzw archive (not Tar)
|
||||
Assert.Equal(ArchiveType.Lzw, reader.ArchiveType);
|
||||
Assert.True(reader.MoveToNextEntry());
|
||||
Assert.NotNull(reader.Entry);
|
||||
Assert.Equal(CompressionType.Lzw, reader.Entry.CompressionType);
|
||||
|
||||
// When opened via ReaderFactory with a non-FileStream, key defaults to "data"
|
||||
Assert.NotNull(reader.Entry.Key);
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,8 @@ public abstract class ReaderTests : TestBase
|
||||
await using (
|
||||
var reader = await ReaderFactory.OpenAsyncReader(
|
||||
new AsyncOnlyStream(testStream),
|
||||
options
|
||||
options,
|
||||
cancellationToken
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
@@ -94,7 +94,8 @@ public class WriterTests : TestBase
|
||||
|
||||
await using var reader = await ReaderFactory.OpenAsyncReader(
|
||||
new AsyncOnlyStream(SharpCompressStream.CreateNonDisposing(stream)),
|
||||
readerOptions
|
||||
readerOptions,
|
||||
cancellationToken
|
||||
);
|
||||
await reader.WriteAllToDirectoryAsync(
|
||||
SCRATCH_FILES_PATH,
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user