I do not seem to be able to write text via StreamWriter to a to be newly created zip file (not gzip). I use SharpZipLib and do not quite comprehend how to get it to work. DJ Kraze helped me with streaming content from a zipped text file to StreamReader, I now try the opposite. I do not want to create a csv file first and then compress the finalized file but like to stream text directly to a to be created csv within the zip container. Is that possible? Below a snippet I use for getting a stream that I can use with StreamReader, it just gives an idea what I am looking for, just that this time I like to get a stream to be used with StreamWriter.
public static Stream GetZipInputFileStream(string fileName)
{
ZipInputStream zip = new ZipInputStream(File.OpenRead(fileName));
FileStream filestream =
new FileStream(fileName, FileMode.Open, FileAccess.Read);
ZipFile zipfile = new ZipFile(filestream);
ZipEntry item;
if ((item = zip.GetNextEntry()) != null)
{
return zipfile.GetInputStream(item);
}
else
{
return null;
}
}
Here is how I use it, which I essentially look for but the other way around (StreamWriter -> new csv file in new zip container):
using (StreamReader streamReader = Path.GetExtension(fileName).ToUpper().Equals(".ZIP") ? new StreamReader(FileOperations.GetZipInputFileStream(fileName)) : new StreamReader(fileName))
{