Merge pull request #1805 from martincostello/master
[mono.git] / mcs / class / System.IO.Compression / ZipArchiveEntry.cs
index 13f0dddad412a827df0bc9ea0eb00963f9225bd4..cd783b8eb0c84b33b3f5a7492afb2496b28afde6 100644 (file)
@@ -2,8 +2,8 @@
 // ZipArchiveEntry.cs
 //
 // Author:
-//        Joao Matos <joao.matos@xamarin.com>
-//        Martin Baulig <martin.baulig@xamarin.com>
+//       Joao Matos <joao.matos@xamarin.com>
+//       Martin Baulig <martin.baulig@xamarin.com>
 //
 // Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
 //
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+using SharpCompress.Archive;
+
 namespace System.IO.Compression
 {
        public class ZipArchiveEntry
        {
-               readonly Ionic.Zip.ZipEntry entry;
+               readonly SharpCompress.Archive.Zip.ZipArchiveEntry entry;
                private Stream openStream;
                private bool wasDeleted;
 
-               internal ZipArchiveEntry(ZipArchive archive, Ionic.Zip.ZipEntry entry)
+               internal ZipArchiveEntry(ZipArchive     archive, SharpCompress.Archive.Zip.ZipArchiveEntry entry)
                {
                        if (archive == null)
                                throw new ArgumentNullException("archive");
@@ -41,7 +43,7 @@ namespace System.IO.Compression
                        if (entry == null)
                                throw new ArgumentNullException("entry");
 
-                       this.Archive = archive;
+                       Archive = archive;
                        this.entry = entry;
                }
 
@@ -60,12 +62,12 @@ namespace System.IO.Compression
                }
 
                public string FullName {
-                       get { return entry.FileName; }
+                       get { return entry.Key; }
                }
 
                public DateTimeOffset LastWriteTime {
-                       get { return entry.LastModified; }
-                       set { entry.LastModified = value.DateTime; }
+                       get { return entry.LastModifiedTime.GetValueOrDefault(); }
+                       set { entry.LastModifiedTime = value.DateTime; }
                }
 
                public long Length {
@@ -73,30 +75,30 @@ namespace System.IO.Compression
                                if (Archive.Mode == ZipArchiveMode.Create)
                                        throw new InvalidOperationException("Property cannot be retrieved when the mode is set to Create");
 
-                               return entry.UncompressedSize;
+                               return entry.Size;
                        }
                }
 
                public string Name {
-                       get { return Path.GetFileName(entry.FileName); }
+                       get { return Path.GetFileName(entry.Key); }
                }
 
-               public void Delete ()
+               public void Delete()
                {
                        if (Archive.disposed)
                                throw new ObjectDisposedException("The zip archive for this entry has been disposed.");
 
-                       if (Archive.Mode != ZipArchiveMode.Update)
+                       if (Archive.Mode !=     ZipArchiveMode.Update)
                                throw new NotSupportedException("The zip archive for this entry was opened in a mode other than Update.");
 
                        if (openStream != null)
-                        throw new IOException("The entry is already open for reading or writing.");
+                               throw new IOException("The entry is already open for reading or writing.");
 
                        wasDeleted = true;
-                       Archive.zipFile.RemoveEntry(entry.FileName);
+                       Archive.zipFile.RemoveEntry(entry);
                }
 
-               public Stream Open ()
+               public Stream Open()
                {
                        if (Archive.disposed)
                                throw new ObjectDisposedException("The zip archive for this entry has been disposed.");
@@ -110,15 +112,9 @@ namespace System.IO.Compression
                        if (Archive.Mode == ZipArchiveMode.Create && openStream != null)
                                throw new IOException("The archive for this entry was opened with the Create mode, and this entry has already been written to.");
 
-                       var memoryStream = new MemoryStream();
-                       openStream = memoryStream;
-
-                       if (Archive.Mode == ZipArchiveMode.Read || Archive.Mode == ZipArchiveMode.Update)
-                               entry.Extract(memoryStream);
-
-                       memoryStream.Seek(0, SeekOrigin.Begin);
+                       openStream = entry.OpenEntryStream();
 
-                       return memoryStream;
+                       return openStream;
                }
        }
 }