/********************************************************
* CLASS METHODS
*********************************************************/
/// <summary>
///
/// </summary>
/// <param name="zipPath"></param>
/// <param name="filenamesAndData"></param>
/// <returns></returns>
public static bool Zip(string zipPath, System.Collections.Generic.Dictionary<string, string> filenamesAndData)
{
var success = true;
var buffer = new byte[4096];
try
{
using (var stream = new ZipOutputStream(System.IO.File.Create(zipPath)))
{
foreach (var filename in filenamesAndData.Keys)
{
var file = filenamesAndData[filename].GetBytes();
var entry = stream.PutNextEntry(filename);
using (var ms = new System.IO.MemoryStream(file))
{
int sourceBytes;
do
{
sourceBytes = ms.Read(buffer, 0, buffer.Length);
stream.Write(buffer, 0, sourceBytes);
}
while (sourceBytes > 0);
}
}
stream.Flush();
stream.Close();
}
}
catch (System.Exception err)
{
System.Console.WriteLine("Compression.ZipData(): " + err.Message);
success = false;
}
return success;
}