From 38eec23e079ff26ac6ddeaff7fa971d5c123bce8 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 14 Jan 2026 16:38:57 +0000 Subject: [PATCH] rar byte[] better --- src/SharpCompress/Archives/Rar/RarArchive.cs | 14 ++++++++++++++ src/SharpCompress/Compressors/Rar/RarStream.cs | 2 +- .../Compressors/Rar/UnpackV1/Unpack.cs | 14 +++++--------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index d67dd15c..9bfde20b 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -48,6 +48,20 @@ public partial class RarArchive : AbstractArchive, I } } + public override async ValueTask DisposeAsync() + { + if (!_disposed) + { + if (UnpackV1.IsValueCreated && UnpackV1.Value is IDisposable unpackV1) + { + unpackV1.Dispose(); + } + + _disposed = true; + await base.DisposeAsync(); + } + } + protected override IEnumerable LoadEntries(IEnumerable volumes) => RarArchiveEntryFactory.GetEntries(this, volumes, ReaderOptions); diff --git a/src/SharpCompress/Compressors/Rar/RarStream.cs b/src/SharpCompress/Compressors/Rar/RarStream.cs index 7f258bc5..21c225c3 100644 --- a/src/SharpCompress/Compressors/Rar/RarStream.cs +++ b/src/SharpCompress/Compressors/Rar/RarStream.cs @@ -87,10 +87,10 @@ internal class RarStream : Stream, IStreamStack #endif ArrayPool.Shared.Return(this.tmpBuffer); this.tmpBuffer = null; + readStream.Dispose(); } isDisposed = true; base.Dispose(disposing); - readStream.Dispose(); } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs index 1518830a..4f2120a7 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs @@ -126,17 +126,13 @@ internal sealed partial class Unpack : BitInput, IRarUnpack private FileHeader fileHeader; - private void Init(byte[] window) + + private void Init() { - if (this.window is null && window is null) + if (this.window is null) { this.window = ArrayPool.Shared.Rent(PackDef.MAXWINSIZE); } - else if (window is not null) - { - this.window = window; - externalWindow = true; - } inAddr = 0; UnpInitData(false); } @@ -149,7 +145,7 @@ internal sealed partial class Unpack : BitInput, IRarUnpack this.writeStream = writeStream; if (!fileHeader.IsSolid) { - Init(null); + Init(); } suspended = false; DoUnpack(); @@ -168,7 +164,7 @@ internal sealed partial class Unpack : BitInput, IRarUnpack this.writeStream = writeStream; if (!fileHeader.IsSolid) { - Init(null); + Init(); } suspended = false; await DoUnpackAsync(cancellationToken).ConfigureAwait(false);