PageRenderTime 97ms CodeModel.GetById 84ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Utilities/Compression/ZipConstants.cs

#
C# | 326 lines | 77 code | 57 blank | 192 comment | 0 complexity | cc39a95072dcbfec90cde7a2ec0c18e3 MD5 | raw file
  1// Based on Mike Krueger's SharpZipLib, Copyright (C) 2001 (GNU license).
  2// Authors of the original java version: Jochen Hoenicke, John Leuner
  3// See http://www.ISeeSharpCode.com for more information.
  4
  5using System.Text;
  6
  7namespace Delta.Utilities.Compression
  8{
  9	/// <summary>
 10	/// This class contains constants used for Zip format files
 11	/// </summary>
 12	public sealed class ZipConstants
 13	{
 14		#region Constants
 15		/// <summary>
 16		/// The version made by field for entries in the central header when
 17		/// created by this library
 18		/// </summary>
 19		/// <remarks>
 20		/// This is also the Zip version for the library when comparing against
 21		/// the version required to extract for an entry. See
 22		/// <see cref="Streams.ZipInputStream.CanDecompressEntry">
 23		/// ZipInputStream.CanDecompressEntry</see>.
 24		/// </remarks>
 25		public const int VersionMadeBy = 20;
 26
 27		/// <summary>
 28		/// The minimum version required to support strong encryption
 29		/// </summary>
 30		public const int VersionStrongEncryption = 50;
 31
 32		// The local entry header
 33
 34		/// <summary>
 35		/// Size of local entry header (excluding variable length fields at end)
 36		/// </summary>
 37		public const int LocalHeader = 30;
 38
 39		/// <summary>
 40		/// Signature for local entry header
 41		/// </summary>
 42		public const int LocalSignature = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
 43
 44		/// <summary>
 45		/// Offset of version to extract in local entry header
 46		/// </summary>		
 47		public const int LocalVersion = 4;
 48
 49		/// <summary>
 50		/// Offset of general purpose flags in local entry header
 51		/// </summary>
 52		public const int LocalFlag = 6;
 53
 54		/// <summary>
 55		/// Offset of compression method in local entry header
 56		/// </summary>
 57		public const int LocalHow = 8;
 58
 59		/// <summary>
 60		/// Offset of last mod file time + date in local entry header
 61		/// </summary>
 62		public const int LocalTime = 10;
 63
 64		/// <summary>
 65		/// Offset of crc-32 in local entry header
 66		/// </summary>
 67		public const int LocalCrc = 14;
 68
 69		/// <summary>
 70		/// Offset of compressed size in local entry header
 71		/// </summary>
 72		public const int LocalSize = 18;
 73
 74		/// <summary>
 75		/// Offset of uncompressed size in local entry header
 76		/// </summary>
 77		public const int LocalLength = 22;
 78
 79		/// <summary>
 80		/// Offset of file name length in local entry header
 81		/// </summary>
 82		public const int LocalName = 26;
 83
 84		/// <summary>
 85		/// Offset of extra field length in local entry header
 86		/// </summary>
 87		public const int LocalExtension = 28;
 88
 89		/// <summary>
 90		/// Signature for spanning entry
 91		/// </summary>
 92		public const int SpanningSig =
 93			'P' | ('K' << 8) | (7 << 16) | (8 << 24);
 94
 95		/// <summary>
 96		/// Signature for temporary spanning entry
 97		/// </summary>
 98		public const int SpanningTempSig =
 99			'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
100
101		/// <summary>
102		/// Signature for data descriptor
103		/// </summary>
104		/// <remarks>
105		/// This is only used where the length, Crc, or compressed size isn't
106		/// known when the entry is created and the output stream doesnt support
107		/// seeking. The local entry cannot be 'patched' with the correct values
108		/// in this case so the values are recorded after the data prefixed by
109		/// this header, as well as in the central directory.
110		/// </remarks>
111		public const int ExternSig =
112			'P' | ('K' << 8) | (7 << 16) | (8 << 24);
113
114		/// <summary>
115		/// Size of data descriptor
116		/// </summary>
117		public const int ExternHeader = 16;
118
119		/// <summary>
120		/// Offset of crc-32 in data descriptor
121		/// </summary>
122		public const int ExternCrc = 4;
123
124		/// <summary>
125		/// Offset of compressed size in data descriptor
126		/// </summary>
127		public const int ExternSize = 8;
128
129		/// <summary>
130		/// Offset of uncompressed length in data descriptor
131		/// </summary>
132		public const int ExternLength = 12;
133
134		/// <summary>
135		/// Signature for central header
136		/// </summary>
137		public const int CentralDirectorySig =
138			'P' | ('K' << 8) | (1 << 16) | (2 << 24);
139
140		/// <summary>
141		/// Signature for Zip64 central file header
142		/// </summary>
143		public const int CentralDirectorySig64 =
144			'P' | ('K' << 8) | (6 << 16) | (6 << 24);
145
146		/// <summary>
147		/// Central header digitial signature
148		/// </summary>
149		public const int CentralDigitalSig =
150			'P' | ('K' << 8) | (5 << 16) | (5 << 24);
151
152		/// <summary>
153		/// Size of central header entry
154		/// </summary>
155		public const int CentralHeader = 46;
156
157		/// <summary>
158		/// Offset of version made by in central file header
159		/// </summary>
160		public const int CentralVem = 4;
161
162		/// <summary>
163		/// Offset of version needed to extract in central file header
164		/// </summary>
165		public const int CentralVersion = 6;
166
167		/// <summary>
168		/// Offset of general purpose bit flag in central file header
169		/// </summary>
170		public const int CentralFlag = 8;
171
172		/// <summary>
173		/// Offset of compression method in central file header
174		/// </summary>
175		public const int CentralHow = 10;
176
177		/// <summary>
178		/// Offset of time/date in central file header
179		/// </summary>
180		public const int CentralTime = 12;
181
182		/// <summary>
183		/// Offset of crc-32 in central file header
184		/// </summary>
185		public const int CentralCrc = 16;
186
187		/// <summary>
188		/// Offset of compressed size in central file header
189		/// </summary>
190		public const int CentralSize = 20;
191
192		/// <summary>
193		/// Offset of uncompressed size in central file header
194		/// </summary>
195		public const int CentralLength = 24;
196
197		/// <summary>
198		/// Offset of file name length in central file header
199		/// </summary>
200		public const int CentralName = 28;
201
202		/// <summary>
203		/// Offset of extra field length in central file header
204		/// </summary>
205		public const int CentralExtension = 30;
206
207		/// <summary>
208		/// Offset of file comment length in central file header
209		/// </summary>
210		public const int CentralComment = 32;
211
212		/// <summary>
213		/// Offset of disk start number in central file header
214		/// </summary>
215		public const int CentralDiskStartNumber = 34;
216
217		/// <summary>
218		/// Offset of internal file attributes in central file header
219		/// </summary>
220		public const int CentralAttributes = 36;
221
222		/// <summary>
223		/// Offset of external file attributes in central file header
224		/// </summary>
225		public const int CentralExternalAttributes = 38;
226
227		/// <summary>
228		/// Offset of relative offset of local header in central file header
229		/// </summary>
230		public const int CentralOffset = 42;
231
232		// The entries at the end of central directory
233
234		/// <summary>
235		/// End of central directory record signature
236		/// </summary>
237		public const int EndSig =
238			'P' | ('K' << 8) | (5 << 16) | (6 << 24);
239
240		/// <summary>
241		/// Size of end of central record (excluding variable fields)
242		/// </summary>
243		public const int EndHeader = 22;
244
245		// The following two fields are missing in SUN JDK
246
247		/// <summary>
248		/// Offset of number of this disk
249		/// </summary>
250		public const int EndNumberOfDisk = 4;
251
252		/// <summary>
253		/// Offset of number of disk with start of central directory
254		/// </summary>
255		public const int EndNumberOfDiskCentralDirectory = 6;
256
257		/// <summary>
258		/// Offset of number of entries in the central directory of this disk
259		/// </summary>
260		public const int EndEntriesInCentralDirectory = 8;
261
262		/// <summary>
263		/// Offset of total number of entries in the central directory
264		/// </summary>
265		public const int EndTotalNumberOfEntriesInCentralDirectory = 10;
266
267		/// <summary>
268		/// Offset of size of central directory
269		/// </summary>
270		public const int EndSizeOfCentralDirectory = 12;
271
272		/// <summary>
273		/// Offset of offset of start of central directory with respect to
274		/// starting disk number
275		/// </summary>
276		public const int EndOffset = 16;
277
278		/// <summary>
279		/// Offset of ZIP file comment length
280		/// </summary>
281		public const int EndComment = 20;
282
283		/// <summary>
284		/// Size of cryptographic header stored before entry data
285		/// </summary>
286		public const int CryptoHeaderSize = 12;
287		#endregion
288
289		#region Public
290		#endregion
291
292		#region Convert methods
293		/// <summary>
294		/// Convert a portion of a byte array to a string.
295		/// </summary>		
296		/// <param name="data">
297		/// Data to convert to string
298		/// </param>
299		/// <param name="length">
300		/// Number of bytes to convert starting from index 0
301		/// </param>
302		/// <returns>
303		/// data[0]..data[length - 1] converted to a string
304		/// </returns>
305		public static string ConvertToString(byte[] data, int length)
306		{
307			return Encoding.ASCII.GetString(data, 0, length);
308		}
309
310		/// <summary>
311		/// Convert byte array to string
312		/// </summary>
313		/// <param name="data">
314		/// Byte array to convert
315		/// </param>
316		/// <returns>
317		/// <paramref name="data">data</paramref>converted to a string
318		/// </returns>
319		public static string ConvertToString(byte[] data)
320		{
321			return ConvertToString(data, data.Length);
322		}
323		#endregion
324	}
325}
326