diff options
Diffstat (limited to '')
-rw-r--r-- | src/dtf/WixToolset.Dtf.Compression.Zip/ZipFileInfo.cs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/dtf/WixToolset.Dtf.Compression.Zip/ZipFileInfo.cs b/src/dtf/WixToolset.Dtf.Compression.Zip/ZipFileInfo.cs new file mode 100644 index 00000000..d865bbba --- /dev/null +++ b/src/dtf/WixToolset.Dtf.Compression.Zip/ZipFileInfo.cs | |||
@@ -0,0 +1,104 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.Dtf.Compression.Zip | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Runtime.Serialization; | ||
8 | |||
9 | /// <summary> | ||
10 | /// Object representing a compressed file within a zip package; provides operations for getting | ||
11 | /// the file properties and extracting the file. | ||
12 | /// </summary> | ||
13 | [Serializable] | ||
14 | public class ZipFileInfo : ArchiveFileInfo | ||
15 | { | ||
16 | private long compressedLength; | ||
17 | private ZipCompressionMethod compressionMethod; | ||
18 | |||
19 | /// <summary> | ||
20 | /// Creates a new ZipFileInfo object representing a file within a zip in a specified path. | ||
21 | /// </summary> | ||
22 | /// <param name="zipInfo">An object representing the zip archive containing the file.</param> | ||
23 | /// <param name="filePath">The path to the file within the zip archive. Usually, this is a simple file | ||
24 | /// name, but if the zip archive contains a directory structure this may include the directory.</param> | ||
25 | public ZipFileInfo(ZipInfo zipInfo, string filePath) | ||
26 | : base(zipInfo, filePath) | ||
27 | { | ||
28 | if (zipInfo == null) | ||
29 | { | ||
30 | throw new ArgumentNullException("zipInfo"); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | /// <summary> | ||
35 | /// Creates a new ZipFileInfo object with all parameters specified, | ||
36 | /// used internally when reading the metadata out of a zip archive. | ||
37 | /// </summary> | ||
38 | /// <param name="filePath">The internal path and name of the file in the zip archive.</param> | ||
39 | /// <param name="zipNumber">The zip archive number where the file starts.</param> | ||
40 | /// <param name="attributes">The stored attributes of the file.</param> | ||
41 | /// <param name="lastWriteTime">The stored last write time of the file.</param> | ||
42 | /// <param name="length">The uncompressed size of the file.</param> | ||
43 | /// <param name="compressedLength">The compressed size of the file.</param> | ||
44 | /// <param name="compressionMethod">Compression algorithm used for this file.</param> | ||
45 | internal ZipFileInfo( | ||
46 | string filePath, | ||
47 | int zipNumber, | ||
48 | FileAttributes attributes, | ||
49 | DateTime lastWriteTime, | ||
50 | long length, | ||
51 | long compressedLength, | ||
52 | ZipCompressionMethod compressionMethod) | ||
53 | : base(filePath, zipNumber, attributes, lastWriteTime, length) | ||
54 | { | ||
55 | this.compressedLength = compressedLength; | ||
56 | this.compressionMethod = compressionMethod; | ||
57 | } | ||
58 | |||
59 | /// <summary> | ||
60 | /// Initializes a new instance of the ZipFileInfo class with serialized data. | ||
61 | /// </summary> | ||
62 | /// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param> | ||
63 | /// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param> | ||
64 | protected ZipFileInfo(SerializationInfo info, StreamingContext context) | ||
65 | : base(info, context) | ||
66 | { | ||
67 | this.compressedLength = info.GetInt64("compressedLength"); | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Gets the compressed size of the file in bytes. | ||
72 | /// </summary> | ||
73 | public long CompressedLength | ||
74 | { | ||
75 | get | ||
76 | { | ||
77 | return this.compressedLength; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Gets the method used to compress this file. | ||
83 | /// </summary> | ||
84 | public ZipCompressionMethod CompressionMethod | ||
85 | { | ||
86 | get | ||
87 | { | ||
88 | return this.compressionMethod; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Sets the SerializationInfo with information about the archive. | ||
94 | /// </summary> | ||
95 | /// <param name="info">The SerializationInfo that holds the serialized object data.</param> | ||
96 | /// <param name="context">The StreamingContext that contains contextual information | ||
97 | /// about the source or destination.</param> | ||
98 | public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
99 | { | ||
100 | base.GetObjectData(info, context); | ||
101 | info.AddValue("compressedLength", this.compressedLength); | ||
102 | } | ||
103 | } | ||
104 | } | ||