Merge pull request #3037 from mono/system_io_compression_datetime
[mono.git] / mcs / class / System.IO.Compression / SharpCompress / Archive / Zip / ZipWritableArchiveEntry.cs
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using SharpCompress.Common;
5 using SharpCompress.IO;
6
7 namespace SharpCompress.Archive.Zip
8 {
9     internal class ZipWritableArchiveEntry : ZipArchiveEntry, IWritableArchiveEntry
10     {
11         private readonly string path;
12         private readonly long size;
13         private readonly bool closeStream;
14         private readonly Stream stream;
15         private bool isDisposed;
16
17         internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size,
18                                          DateTime? lastModified, bool closeStream)
19             : base(archive, null)
20         {
21             this.stream = stream;
22             this.path = path;
23             this.size = size;
24             this.LastModifiedTime = lastModified;
25             this.closeStream = closeStream;
26         }
27
28         public override uint Crc
29         {
30             get { return 0; }
31         }
32
33         public override string Key
34         {
35             get { return path; }
36         }
37
38         public override long CompressedSize
39         {
40             get { return 0; }
41         }
42
43         public override long Size
44         {
45             get { return size; }
46         }
47
48         public override DateTime? CreatedTime
49         {
50             get { return null; }
51         }
52
53         public override DateTime? LastAccessedTime
54         {
55             get { return null; }
56         }
57
58         public override DateTime? ArchivedTime
59         {
60             get { return null; }
61         }
62
63         public override bool IsEncrypted
64         {
65             get { return false; }
66         }
67
68         public override bool IsDirectory
69         {
70             get { return false; }
71         }
72
73         public override bool IsSplit
74         {
75             get { return false; }
76         }
77
78         internal override IEnumerable<FilePart> Parts
79         {
80             get { throw new NotImplementedException(); }
81         }
82
83         Stream IWritableArchiveEntry.Stream
84         {
85             get
86             {
87                 return stream;
88             }
89         }
90
91         public override Stream OpenEntryStream()
92         {
93             //ensure new stream is at the start, this could be reset
94             stream.Seek(0, SeekOrigin.Begin);
95             return new NonDisposingStream(stream);
96         }
97
98         internal override void Close()
99         {
100             if (closeStream && !isDisposed)
101             {
102                 stream.Dispose();
103                 isDisposed = true;
104             }
105         }
106     }
107 }