Reputation:
I have generated a zip using streamwriter in isolated storage named temp.zip and return its bytes in stream for extraction. Please find the code as below
stream = LoadZipFromLocalFolder(filename);
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var zipStream = new ZipInputStream(stream))
{
ZipEntry entry;
//EOF in header occuring on below line
while ((entry = zipStream.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(entry.Name);
string fileName = Path.GetFileName(entry.Name);
if (!string.IsNullOrEmpty(fileName))
{
if (!isoStore.DirectoryExists(directoryName))
{
isoStore.CreateDirectory(directoryName);
}
string fileFullPath = Path.Combine(directoryName, fileName);
Debug.WriteLine(fileFullPath);
using (var streamWriter = new BinaryWriter(new IsolatedStorageFileStream(fileFullPath, FileMode.Create, FileAccess.Write, FileShare.Write, isoStore)))
{
var buffer = new byte[2048];
int size;
while ((size = zipStream.Read(buffer, 0, buffer.Length)) > 0)
{
streamWriter.Write(buffer, 0, size);
}
streamWriter.Close();
streamWriter.Dispose();
}
}
}
}
}
When I created temp.zip, it has ReadWrite,Share permissions and also I tried to unzip manually, then its getting extracted properly without causing any error, but in code its showing error EOF in HEADER.
Please help..
Thanks
Upvotes: 4
Views: 14493
Reputation: 174
I tried the answer above by user user2561128
and it did not solve the problem for me.
Instead I opted for installing the NuGet System.IO.Compression.ZipFile
v4.3.0 and with the following code it worked.
ZipFile.ExtractToDirectory(zipArchive, destinationFolder, overwriteFiles:true);
It also looks like somebody has found the same problem in a fork of npoi with this GitHub issue.
Upvotes: 2
Reputation:
I solved the EOF in header by using just a simple code as follows :
Stream.Position =0;
Hope it helps to some one.
Thanks.
Upvotes: 11