What could cause ICSharpCode.SharpZipLib to fail on Delete -> CommitUpdate with error 'Failed to copy bytes..."?

1

Using ICSharpCode.SharpZipLib to update a zip file by deleting a specific document from the zipped contents, using the following code:

protected async Task updateZip()
{
    var fragment = "resources/graphics.json";

    ZipFile zipFile = null;
    using (var memoryStream = new MemoryStream())
    {
        using (var stream = await resourceClient.GetBlob("files/pageengine/document.epl")) // .epl is a zip format.
        {
            await stream.CopyToAsync(memoryStream);
            memoryStream.Position = 0;
            zipFile = new ZipFile(memoryStream);
        }

        memoryStream.Position = 0;

        zipFile.BeginUpdate();
        if (zipFile.FindEntry(fragment, true) != -1) zipFile.Delete(fragment);
        zipFile.CommitUpdate(); // FAILS HERE
        zipFile.IsStreamOwner = false;
    }
    // Etc. to save zip file.
}

...we get the following error:

System.ApplicationException HResult=0x80131600 Message=Internal Server Error - {"Message":"An error has occurred.","ExceptionMessage":"Failed to copy bytes expected 33734 read 13013","ExceptionType":"ICSharpCode.SharpZipLib.Zip.ZipException","StackTrace":" at ICSharpCode.SharpZipLib.Zip.ZipFile.CopyEntryDataDirect(ZipUpdate update, Stream stream, Boolean updateCrc, Int64& destinationPosition, Int64& sourcePosition)\r\n at ICSharpCode.SharpZipLib.Zip.ZipFile.CopyEntryDirect(ZipFile workFile, ZipUpdate update, Int64& destinationPosition)\r\n at ICSharpCode.SharpZipLib.Zip.ZipFile.RunUpdates()\r\n at ICSharpCode.SharpZipLib.Zip.ZipFile.CommitUpdate()\r\n

We've tried memoryStream.Capacity = memoryStream.Length, but this doesn't help. Neither of the byte lengths in the error message matches either the stream Capacity or its Length.

What could be causing this issue?

(.NET 4.7; Latest Stable SharpZipLib from Nuget v0.86.0)

c#
.net
stream
sharpziplib
asked on Stack Overflow Jun 7, 2018 by Jude Fisher • edited Jun 7, 2018 by Jude Fisher

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0