@@ -128,18 +128,12 @@ public Bundle(string bundlePath, ILogger? logger = null)
128128 /// <summary>
129129 /// Throws an exception if the bundle is read-only.
130130 /// </summary>
131- private void EnsureWritable ( )
131+ protected void EnsureWritable ( )
132132 {
133- Logger . LogDebug ( "Checking if bundle is read-only" ) ;
134-
135133 if ( IsReadOnly )
136134 {
137- Logger . LogError ( "Bundle is read-only" ) ;
138-
139135 throw new InvalidOperationException ( "Bundle is read-only" ) ; ;
140136 }
141-
142- Logger . LogDebug ( "Bundle is writable" ) ;
143137 }
144138
145139 /// <summary>
@@ -367,8 +361,7 @@ public bool VerifyFileIntegrity(string entryName)
367361 {
368362 Logger . LogDebug ( "Reading file: {name} from the bundle" , entryName ) ;
369363
370- using var zip = OpenZipArchive ( ) ;
371- hash = ComputeSHA512Hash ( ReadEntry ( zip , entryName ) ) ;
364+ hash = ComputeSHA512Hash ( ReadEntry ( entryName ) ) ;
372365 }
373366 else
374367 {
@@ -492,8 +485,8 @@ public X509Certificate2 GetCertificate(string certificateHash)
492485 {
493486 Logger . LogDebug ( "Certificate with hash {hash} not found in cache" , certificateHash ) ;
494487 Logger . LogDebug ( "Reading certificate with hash {hash} from the bundle" , certificateHash ) ;
495- using var zip = OpenZipArchive ( ) ;
496- var certData = ReadEntry ( zip , certificateHash ) ;
488+
489+ var certData = ReadEntry ( certificateHash ) ;
497490
498491#if NET9_0_OR_GREATER
499492 certificate = X509CertificateLoader . LoadCertificate ( certData ) ;
@@ -558,8 +551,7 @@ public byte[] GetFileBytes(string entryName)
558551 {
559552 Logger . LogDebug ( "Reading file: {name} from the bundle" , entryName ) ;
560553
561- using var zip = OpenZipArchive ( ) ;
562- return ReadEntry ( zip , entryName ) ;
554+ return ReadEntry ( entryName ) ;
563555 }
564556 else
565557 {
@@ -655,20 +647,20 @@ public void Update()
655647 }
656648
657649 /// <summary>
658- /// Reads an entry from a <see cref="ZipArchive"/> and caches the entry data if the bundle is Read-only.
650+ /// Reads an entry from bundle and caches the entry data if the bundle is Read-only.
659651 /// </summary>
660- /// <param name="zip">The <see cref="ZipArchive"/> to read from.</param>
661652 /// <param name="entryName">The name of the entry to read.</param>
662653 /// <returns>A byte array containing the entry data.</returns>
663- protected byte [ ] ReadEntry ( ZipArchive zip , string entryName )
654+ protected byte [ ] ReadEntry ( string entryName )
664655 {
665- Ensure . Any . IsNotNull ( zip , nameof ( zip ) ) ;
666656 Ensure . String . IsNotNullOrEmpty ( entryName . Trim ( ) , nameof ( entryName ) ) ;
667657
668658 if ( ! _fileCache . TryGetValue ( entryName , out var data ) )
669659 {
670660 Logger . LogDebug ( "Entry {name} not found in cache" , entryName ) ;
671661 Logger . LogDebug ( "Reading entry: {name} from the bundle" , entryName ) ;
662+
663+ using var zip = OpenZipArchive ( ) ;
672664 var entry = zip . GetEntry ( entryName ) ?? throw new FileNotFoundException ( "Entry not found" , entryName ) ;
673665 using var stream = entry . Open ( ) ;
674666 data = ReadStream ( stream ) ;
0 commit comments