Skip to content

Commit

Permalink
Closing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
A9G-Data-Droid committed Oct 27, 2023
1 parent c41f9dc commit e724878
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions netstandard20/ZipStorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace ZipStorer
/// </summary>
public class ZipStorer : IDisposable
{
// 64Kb, the size of the comment field in a ZIP file.
private const int SixtyFourK = 65535;

#region Public Properties
/// <summary>True if UTF8 encoding for filename and comments, false if default (CP 437)</summary>
Expand Down Expand Up @@ -323,10 +325,10 @@ public async Task AddDirectoryAsync(CompressionType method, string pathname, str
/// <remarks>This is a required step, unless automatic dispose is used</remarks>
public void Close()
{
if (_access != FileAccess.Read)
if (_access != FileAccess.Read && _files.Count > 0)
{
uint centralOffset = (uint)_zipFileStream.Position;
uint centralSize = 0;
long centralOffset = _zipFileStream.Position;
long centralSize = 0;

if (_centralDirImage != null)
_zipFileStream.Write(_centralDirImage, 0, _centralDirImage.Length);
Expand All @@ -335,7 +337,7 @@ public void Close()
{
long pos = _zipFileStream.Position;
WriteCentralDirRecord(fileEntry);
centralSize += (uint)(_zipFileStream.Position - pos);
centralSize += _zipFileStream.Position - pos;
}

if (_centralDirImage != null)
Expand Down Expand Up @@ -496,7 +498,7 @@ public async Task<bool> ExtractFileAsync(ZipFileEntry zfe, Stream stream)
}

// Buffered copy
byte[] buffer = new byte[65535];
byte[] buffer = new byte[SixtyFourK];
_zipFileStream.Seek(zfe.FileOffset, SeekOrigin.Begin);
long bytesPending = zfe.FileSize;

Expand Down Expand Up @@ -1039,7 +1041,8 @@ private bool ReadFileInfo()
return false;
}

_zipFileStream.Seek(-17, SeekOrigin.End);
var end = _zipFileStream.Seek(-17, SeekOrigin.End);

try
{
do
Expand Down Expand Up @@ -1102,7 +1105,7 @@ private bool ReadFileInfo()

return true;
}
} while (_zipFileStream.Position > 0);
} while (_zipFileStream.Position > end - SixtyFourK);
}
catch
{
Expand Down

0 comments on commit e724878

Please sign in to comment.