Hi all,
I'm using the following code to zip and unzip strings and set the comments into memory.
All works, except if I have chinese chars. Can you help me out? (At this time the comments are being returned as ???? )
/// <summary>
/// Zips the content.
/// </summary>
/// <param name="entryName">Name of the entry.</param>
/// <param name="body">The body.</param>
/// <param name="comment">The comment.</param>
/// <returns></returns>
public static string Zip(string entryName, string body, string comment)
{
MemoryStream outputMemStream = new MemoryStream();
ZipOutputStream zipStream = new ZipOutputStream(outputMemStream);
ZipEntry newEntry = new ZipEntry(entryName);
newEntry.IsUnicodeText = true;
newEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(newEntry);
StreamUtils.Copy(Utilities.GenerateStreamFromString(body), zipStream, new byte[4096]);
zipStream.SetComment(comment);
zipStream.SetLevel(3);
zipStream.CloseEntry();
zipStream.IsStreamOwner = false;
zipStream.Close();
outputMemStream.Position = 0;
return Convert.ToBase64String(outputMemStream.ToArray());
}
/// <summary>
/// Unzips the specified content.
/// </summary>
/// <param name="contentBase64">The content.</param>
/// <param name="entryName">Name of the entry.</param>
/// <param name="body">The body.</param>
/// <param name="comment">The comment.</param>
public static void Unzip(string contentBase64, out string entryName, out string body, out string comment)
{
Stream inStream = new MemoryStream(Convert.FromBase64String(contentBase64));
MemoryStream outputMemStream = new MemoryStream();
ZipOutputStream zipOut = new ZipOutputStream(outputMemStream);
zipOut.IsStreamOwner = false;
zipOut.SetLevel(3);
ZipFile zipFile = new ZipFile(inStream);
zipFile.IsStreamOwner = false;
comment = zipFile.ZipFileComment;
ZipEntry zipEntry = zipFile[0];
entryName = zipEntry.Name;
Stream zipStream = zipFile.GetInputStream(zipEntry);
body = Utilities.GenerateStringFromStream(zipStream);
zipOut.Close();
}