[sgen] Exclusive write on binary protocol file
[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 DateTime? lastModified;
14         private readonly bool closeStream;
15         private readonly Stream stream;
16         private bool isDisposed;
17
18         internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size,
19                                          DateTime? lastModified, bool closeStream)
20             : base(archive, null)
21         {
22             this.stream = stream;
23             this.path = path;
24             this.size = size;
25             this.lastModified = lastModified;
26             this.closeStream = closeStream;
27         }
28
29         public override uint Crc
30         {
31             get { return 0; }
32         }
33
34         public override string Key
35         {
36             get { return path; }
37         }
38
39         public override long CompressedSize
40         {
41             get { return 0; }
42         }
43
44         public override long Size
45         {
46             get { return size; }
47         }
48
49         public override DateTime? LastModifiedTime
50         {
51             get { return lastModified; }
52         }
53
54         public override DateTime? CreatedTime
55         {
56             get { return null; }
57         }
58
59         public override DateTime? LastAccessedTime
60         {
61             get { return null; }
62         }
63
64         public override DateTime? ArchivedTime
65         {
66             get { return null; }
67         }
68
69         public override bool IsEncrypted
70         {
71             get { return false; }
72         }
73
74         public override bool IsDirectory
75         {
76             get { return false; }
77         }
78
79         public override bool IsSplit
80         {
81             get { return false; }
82         }
83
84         internal override IEnumerable<FilePart> Parts
85         {
86             get { throw new NotImplementedException(); }
87         }
88
89         Stream IWritableArchiveEntry.Stream
90         {
91             get
92             {
93                 return stream;
94             }
95         }
96
97         public override Stream OpenEntryStream()
98         {
99             //ensure new stream is at the start, this could be reset
100             stream.Seek(0, SeekOrigin.Begin);
101             return new NonDisposingStream(stream);
102         }
103
104         internal override void Close()
105         {
106             if (closeStream && !isDisposed)
107             {
108                 stream.Dispose();
109                 isDisposed = true;
110             }
111         }
112     }
113 }