5 // Joao Matos <joao.matos@xamarin.com>
6 // Martin Baulig <martin.baulig@xamarin.com>
8 // Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 using SharpCompress.Archive;
30 namespace System.IO.Compression
32 public class ZipArchiveEntry
34 readonly SharpCompress.Archive.Zip.ZipArchiveEntry entry;
35 private Stream openStream;
36 private bool wasDeleted;
38 internal ZipArchiveEntry(ZipArchive archive, SharpCompress.Archive.Zip.ZipArchiveEntry entry)
41 throw new ArgumentNullException("archive");
44 throw new ArgumentNullException("entry");
50 public ZipArchive Archive {
55 public long CompressedLength {
57 if (Archive.Mode == ZipArchiveMode.Create)
58 throw new InvalidOperationException("Property cannot be retrieved when the mode is set to Create");
60 return entry.CompressedSize;
64 public string FullName {
65 get { return entry.Key; }
68 public DateTimeOffset LastWriteTime {
69 get { return entry.LastModifiedTime.GetValueOrDefault(); }
70 set { entry.LastModifiedTime = value.DateTime; }
75 if (Archive.Mode == ZipArchiveMode.Create)
76 throw new InvalidOperationException("Property cannot be retrieved when the mode is set to Create");
83 get { return Path.GetFileName(entry.Key); }
89 throw new ObjectDisposedException("The zip archive for this entry has been disposed.");
91 if (Archive.Mode != ZipArchiveMode.Update)
92 throw new NotSupportedException("The zip archive for this entry was opened in a mode other than Update.");
94 if (openStream != null)
95 throw new IOException("The entry is already open for reading or writing.");
98 Archive.zipFile.RemoveEntry(entry);
103 if (Archive.disposed)
104 throw new ObjectDisposedException("The zip archive for this entry has been disposed.");
106 if (openStream != null && Archive.Mode == ZipArchiveMode.Update)
107 throw new IOException("The entry is already currently open for writing.");
110 throw new IOException("The entry has been deleted from the archive.");
112 if (Archive.Mode == ZipArchiveMode.Create && openStream != null)
113 throw new IOException("The archive for this entry was opened with the Create mode, and this entry has already been written to.");
115 openStream = entry.OpenEntryStream();