SharpZipLib icon indicating copy to clipboard operation
SharpZipLib copied to clipboard

Zip a long text string and create a file

Open The-Futurist opened this issue 6 years ago • 5 comments

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?

The-Futurist avatar Feb 08 '19 17:02 The-Futurist

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?

Numpsy avatar Feb 10 '19 13:02 Numpsy

@piksel Would it be useful to stick something simple like this on the wiki?

Numpsy avatar Aug 20 '19 21:08 Numpsy

@Numpsy Sure! I am restructuring the wiki examples now. You can just add it as a new page and link it from Zip-Samples

piksel avatar Aug 21 '19 16:08 piksel

@Numpsy I added a slightly modified version of your example here: Zip-Samples > Create a Zip from a HTML string

piksel avatar Aug 21 '19 18:08 piksel

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.

Numpsy avatar Aug 22 '19 09:08 Numpsy