本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipInputStream.CloseEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipInputStream.CloseEntry方法的具体用法?C# ZipInputStream.CloseEntry怎么用?C# ZipInputStream.CloseEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipInputStream
的用法示例。
在下文中一共展示了ZipInputStream.CloseEntry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnpackData
/// ------------------------------------------------------------------------------------
/// <summary>
/// Unzip a byte array and return unpacked data
/// </summary>
/// <param name="data">Byte array containing data to be unzipped</param>
/// <returns>unpacked data</returns>
/// ------------------------------------------------------------------------------------
public static byte[] UnpackData(byte[] data)
{
if (data == null)
return null;
try
{
MemoryStream memStream = new MemoryStream(data);
ZipInputStream zipStream = new ZipInputStream(memStream);
zipStream.GetNextEntry();
MemoryStream streamWriter = new MemoryStream();
int size = 2048;
byte[] dat = new byte[2048];
while (true)
{
size = zipStream.Read(dat, 0, dat.Length);
if (size > 0)
{
streamWriter.Write(dat, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
zipStream.CloseEntry();
示例2: Deserialize
/// <summary>
/// This deserializes an adpack from a file.
/// </summary>
/// <param name="s">The stream to read from.</param>
public void Deserialize(Stream s)
{
ZipInputStream zis = new ZipInputStream(s);
ZipEntry entry;
Metadata = new SortedList<string, string>();
Files = new SortedList<string, AdPackEntry>();
SortedList<String, byte[]> otherFiles = new SortedList<string, byte[]>();
while ((entry = zis.GetNextEntry()) != null)
{
if (entry.IsCrypted)
{
//MessageBox.Show("This adpack is encrypted, so it cannot be displayed. Please do not encrypt adpack files.");
throw new Exception("Adpack is encrypted!");
}
switch (entry.Name.ToLowerInvariant())
{
case "metadata.dat":
byte[] meta = new byte[entry.Size];
zis.Read(meta, 0, (int)entry.Size);
HandleMetadata(meta);
break;
case "filelist.dat":
byte[] fl = new byte[entry.Size];
zis.Read(fl, 0, (int)entry.Size);
HandleFileList(fl);
break;
default:
byte[] d = new byte[entry.Size];
zis.Read(d, 0, (int)entry.Size);
otherFiles[entry.Name] = d;
break;
}
zis.CloseEntry();
}
// check product id, because it's not just for bf2142
if (Metadata["product"].ToLowerInvariant() != Common.AppInfos[AppID].AppNameShort)
{
String correctApp = "";
if (Common.AppShortNames.ContainsKey(Metadata["product"].ToLowerInvariant())) {
correctApp = Common.AppInfos[Common.AppShortNames[Metadata["product"].ToLowerInvariant()]].AppName;
} else {
correctApp = "Unsupported (" + Metadata["product"].ToLowerInvariant() + ")";
}
throw new Exception("Adpack is not for " + Common.AppInfos[AppID].AppName + ", it is for " + correctApp + ".");
}
// iterate through the other files
foreach (KeyValuePair<String, byte[]> file in otherFiles)
{
if (Files.ContainsKey(file.Key))
{
// referenced data.
Files[file.Key].SetDDSData(file.Value);
}
}
List<String> RemovalList = new List<string>();
foreach (KeyValuePair<String, AdPackEntry> file in Files)
{
// check each has data attached.
if (file.Value.DDSData == null)
{
//MessageBox.Show("Warning: Missing DDS image file '" + file.Key + "'. The adpack file may be corrupt or encrypted.");
RemovalList.Add(file.Key);
}
}
foreach (String item in RemovalList)
{
Files.Remove(item);
}
}