I have an application where I have been using the following code:
using (ZipPackage zipPackage = ZipPackage.Open(stream, FileAccess.Read))
{
foreach (ZipPackageEntry file in zipPackage.ZipPackageEntries.ToList())
{
if (file.FileNameInZip.Equals("nsData.json"))
{
StreamReader streamReader = new StreamReader(file.OpenInputStream());
string jsonString = streamReader.ReadToEnd();
}
}
}
and it works as expected.
I have now tried to convert it to using ZipArchive instead, but I am having some problems.
I use the following code:
using (ZipArchive archive = new ZipArchive(stream,ZipArchiveMode.Read, false, null))
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
ZipArchiveEntry entry = archive.GetEntry("nsData.json");
if (entry != null)
{
Stream entryStream = entry.Open();
StreamReader reader = new StreamReader(entryStream);
string content = reader.ReadToEnd();
}
}
And when it comes to the last line it gives the following exception:
{Telerik.Windows.Zip.InvalidDataException: Invalid block length
ved Telerik.Windows.Zip.DeflateDecompressor.DecodeBits()
ved Telerik.Windows.Zip.DeflateDecompressor.DecodeUncompressedBlock(Boolean& endOfBlock)
ved Telerik.Windows.Zip.DeflateDecompressor.CheckDecodeState()
ved Telerik.Windows.Zip.DeflateDecompressor.Decode()
ved Telerik.Windows.Zip.DeflateDecompressor.Inflate(Byte[] bytes, Int32 offset, Int32 length)
ved Telerik.Windows.Zip.DeflateDecompressor.ProcessTransform(Boolean finalBlock)
ved Telerik.Windows.Zip.DeflateTransformBase.TransformBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[] outputBuffer, Int32 outputOffset)
ved Telerik.Windows.Zip.OperationStream.Read(Byte[] buffer, Int32 offset, Int32 count)
ved Telerik.Windows.Zip.CompressedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
ved System.IO.StreamReader.ReadBuffer()
ved System.IO.StreamReader.ReadToEnd()
ved NstPortalUCSL.ViewModel.ViewModelHandlers.DataSourceHandler.DataSouceHandler.<>c__DisplayClassb.<InitDataSources>b__8(Object sender, GetAllNstInstancesCompletedEventArgs args)
ved NstPortalUCSL.NstPortalWsSvc.NstPortalWsClient.OnGetAllNstInstancesCompleted(Object state)}
I would be wery thankfull if you could explain to me what I am doing wrong.
using (ZipPackage zipPackage = ZipPackage.Open(stream, FileAccess.Read))
{
foreach (ZipPackageEntry file in zipPackage.ZipPackageEntries.ToList())
{
if (file.FileNameInZip.Equals("nsData.json"))
{
StreamReader streamReader = new StreamReader(file.OpenInputStream());
string jsonString = streamReader.ReadToEnd();
}
}
}
and it works as expected.
I have now tried to convert it to using ZipArchive instead, but I am having some problems.
I use the following code:
using (ZipArchive archive = new ZipArchive(stream,ZipArchiveMode.Read, false, null))
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
ZipArchiveEntry entry = archive.GetEntry("nsData.json");
if (entry != null)
{
Stream entryStream = entry.Open();
StreamReader reader = new StreamReader(entryStream);
string content = reader.ReadToEnd();
}
}
And when it comes to the last line it gives the following exception:
{Telerik.Windows.Zip.InvalidDataException: Invalid block length
ved Telerik.Windows.Zip.DeflateDecompressor.DecodeBits()
ved Telerik.Windows.Zip.DeflateDecompressor.DecodeUncompressedBlock(Boolean& endOfBlock)
ved Telerik.Windows.Zip.DeflateDecompressor.CheckDecodeState()
ved Telerik.Windows.Zip.DeflateDecompressor.Decode()
ved Telerik.Windows.Zip.DeflateDecompressor.Inflate(Byte[] bytes, Int32 offset, Int32 length)
ved Telerik.Windows.Zip.DeflateDecompressor.ProcessTransform(Boolean finalBlock)
ved Telerik.Windows.Zip.DeflateTransformBase.TransformBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[] outputBuffer, Int32 outputOffset)
ved Telerik.Windows.Zip.OperationStream.Read(Byte[] buffer, Int32 offset, Int32 count)
ved Telerik.Windows.Zip.CompressedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
ved System.IO.StreamReader.ReadBuffer()
ved System.IO.StreamReader.ReadToEnd()
ved NstPortalUCSL.ViewModel.ViewModelHandlers.DataSourceHandler.DataSouceHandler.<>c__DisplayClassb.<InitDataSources>b__8(Object sender, GetAllNstInstancesCompletedEventArgs args)
ved NstPortalUCSL.NstPortalWsSvc.NstPortalWsClient.OnGetAllNstInstancesCompleted(Object state)}
I would be wery thankfull if you could explain to me what I am doing wrong.