您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->X3BLOG 单用户1.0 build80707(ACCESS)源代码>>SharpZipLib/Zip/ZipFile.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:X3BLOG 单用户1.0 build80707(ACCESS)源代码


当前文件路径:x3blogAccessBuild80707/SharpZipLib/Zip/ZipFile.cs 文件类型
普通视图
		            
1// ZipFile.cs 2// 3// Copyright (C) 2001 Mike Krueger 4// Copyright (C) 2004 John Reilly 5// 6// This file was translated from java, it was part of the GNU Classpath 7// Copyright (C) 2001 Free Software Foundation, Inc. 8// 9// This program is free software; you can redistribute it and/or 10// modify it under the terms of the GNU General Public License 11// as published by the Free Software Foundation; either version 2 12// of the License, or (at your option) any later version. 13// 14// This program is distributed in the hope that it will be useful, 15// but WITHOUT ANY WARRANTY; without even the implied warranty of 16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17// GNU General Public License for more details. 18// 19// You should have received a copy of the GNU General Public License 20// along with this program; if not, write to the Free Software 21// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22// 23// Linking this library statically or dynamically with other modules is 24// making a combined work based on this library. Thus, the terms and 25// conditions of the GNU General Public License cover the whole 26// combination. 27// 28// As a special exception, the copyright holders of this library give you 29// permission to link this library with independent modules to produce an 30// executable, regardless of the license terms of these independent 31// modules, and to copy and distribute the resulting executable under 32// terms of your choice, provided that you also meet, for each linked 33// independent module, the terms and conditions of the license of that 34// module. An independent module is a module which is not derived from 35// or based on this library. If you modify this library, you may extend 36// this exception to your version of the library, but you are not 37// obligated to do so. If you do not wish to do so, delete this 38// exception statement from your version. 39 40using System; 41using System.Security.Cryptography; 42using System.Collections; 43using System.IO; 44using System.Text; 45 46using ICSharpCode.SharpZipLib.Checksums; 47using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 48using ICSharpCode.SharpZipLib.Zip.Compression; 49using ICSharpCode.SharpZipLib.Encryption; 50 51namespace ICSharpCode.SharpZipLib.Zip 52{ 53 54 /// <summary> 55 /// Arguments used with KeysRequiredEvent 56 /// </summary> 57 public class KeysRequiredEventArgs : EventArgs 58 { 59 string fileName; 60 61 /// <summary> 62 /// Get the name of the file for which keys are required. 63 /// </summary> 64 public string FileName 65 { 66 get { return fileName; } 67 } 68 69 byte[] key; 70 71 /// <summary> 72 /// Get/set the key value 73 /// </summary> 74 public byte[] Key 75 { 76 get { return key; } 77 set { key = value; } 78 } 79 80 /// <summary> 81 /// Initialise a new instance of <see cref="KeysRequiredEventArgs"></see> 82 /// </summary> 83 /// <param name="name">The name of the file for which keys are required.</param> 84 public KeysRequiredEventArgs(string name) 85 { 86 fileName = name; 87 } 88 89 /// <summary> 90 /// Initialise a new instance of <see cref="KeysRequiredEventArgs"></see> 91 /// </summary> 92 /// <param name="name">The name of the file for which keys are required.</param> 93 /// <param name="keyValue">The current key value.</param> 94 public KeysRequiredEventArgs(string name, byte[] keyValue) 95 { 96 fileName = name; 97 key = keyValue; 98 } 99 } 100 101 /// <summary> 102 /// This class represents a Zip archive. You can ask for the contained 103 /// entries, or get an input stream for a file entry. The entry is 104 /// automatically decompressed. 105 /// 106 /// This class is thread safe: You can open input streams for arbitrary 107 /// entries in different threads. 108 /// <br/> 109 /// <br/>Author of the original java version : Jochen Hoenicke 110 /// </summary> 111 /// <example> 112 /// <code> 113 /// using System; 114 /// using System.Text; 115 /// using System.Collections; 116 /// using System.IO; 117 /// 118 /// using ICSharpCode.SharpZipLib.Zip; 119 /// 120 /// class MainClass 121 /// { 122 /// static public void Main(string[] args) 123 /// { 124 /// ZipFile zFile = new ZipFile(args[0]); 125 /// Console.WriteLine("Listing of : " + zFile.Name); 126 /// Console.WriteLine(""); 127 /// Console.WriteLine("Raw Size Size Date Time Name"); 128 /// Console.WriteLine("-------- -------- -------- ------ ---------"); 129 /// foreach (ZipEntry e in zFile) { 130 /// DateTime d = e.DateTime; 131 /// Console.WriteLine("{0, -10}{1, -10}{2} {3} {4}", e.Size, e.CompressedSize, 132 /// d.ToString("dd-MM-yy"), d.ToString("t"), 133 /// e.Name); 134 /// } 135 /// } 136 /// } 137 /// </code> 138 /// </example> 139 public class ZipFile : IEnumerable 140 { 141 string name; 142 string comment; 143 Stream baseStream; 144 bool isStreamOwner = true; 145 long offsetOfFirstEntry = 0; 146 ZipEntry[] entries; 147 148 KeyHandling 211 212 /// <summary> 213 /// Opens a Zip file with the given name for reading. 214 /// </summary> 215 /// <exception cref="IOException"> 216 /// An i/o error occurs 217 /// </exception> 218 /// <exception cref="ZipException"> 219 /// The file doesn't contain a valid zip archive. 220 /// </exception> 221 public ZipFile(string name) 222 { 223 this.name = name; 224 this.baseStream = File.OpenRead(name); 225 try { 226 ReadEntries(); 227 } 228 catch { 229 Close(); 230 throw; 231 } 232 } 233 234 /// <summary> 235 /// Opens a Zip file reading the given FileStream 236 /// </summary> 237 /// <exception cref="IOException"> 238 /// An i/o error occurs. 239 /// </exception> 240 /// <exception cref="ZipException"> 241 /// The file doesn't contain a valid zip archive. 242 /// </exception> 243 public ZipFile(FileStream file) 244 { 245 this.baseStream = file; 246 this.name = file.Name; 247 try { 248 ReadEntries(); 249 } 250 catch { 251 Close(); 252 throw; 253 } 254 } 255 256 /// <summary> 257 /// Opens a Zip file reading the given Stream 258 /// </summary> 259 /// <exception cref="IOException"> 260 /// An i/o error occurs 261 /// </exception> 262 /// <exception cref="ZipException"> 263 /// The file doesn't contain a valid zip archive.<br/> 264 /// The stream provided cannot seek 265 /// </exception> 266 public ZipFile(Stream baseStream) 267 { 268 this.baseStream = baseStream; 269 this.name = null; 270 try { 271 ReadEntries(); 272 } 273 catch { 274 Close(); 275 throw; 276 } 277 } 278 279 280 /// <summary> 281 /// Get/set a flag indicating if the underlying stream is owned by the ZipFile instance. 282 /// If the flag is true then the stream will be closed when <see cref="Close">Close</see> is called. 283 /// </summary> 284 /// <remarks> 285 /// The default value is true in all cases. 286 /// </remarks> 287 bool IsStreamOwner 288 { 289 get { return isStreamOwner; } 290 set { isStreamOwner = value; } 291 } 292 293 /// <summary> 294 /// Read an unsigned short in little endian byte order. 295 /// </summary> 296 /// <returns>Returns the value read.</returns> 297