Zip a long text string and create a file
This seems like one of the simplest scenarios yet I cannot find a single example of this. All I want to do is take a large text buffer (an HTML page created via a T4 template) zip that and then save the zipped data as a file.
Is there any documentation that will help me do this?
Would something like
var fs = File.Create("Html.zip");
using (var outStream = new ZipOutputStream(fs))
{
outStream.PutNextEntry(new ZipEntry("test.html"));
using (StreamWriter sw = new StreamWriter(outStream, System.Text.Encoding.UTF8, 4096, true))
{
sw.Write(htmlData);
}
}
Work?
@piksel Would it be useful to stick something simple like this on the wiki?
@Numpsy Sure! I am restructuring the wiki examples now. You can just add it as a new page and link it from Zip-Samples
@Numpsy I added a slightly modified version of your example here: Zip-Samples > Create a Zip from a HTML string
I was just using the wordy StreamWriter constructor to avoid it disposing the ZipOutputStream, but maybe it doesn't matter when everything is disposed straight away anyway.