From 6c80b71775b70e7b2a48b755f401f4eac7d68154 Mon Sep 17 00:00:00 2001 From: yallie Date: Sun, 2 Dec 2012 22:14:12 +0400 Subject: [PATCH] Added XML comments for the code. --- Unzip.cs | 76 +++++++++++++++++++++++++++++++++++++++++++------ Unzip.csproj | 1 + UsageExample.cs | 4 +-- 3 files changed, 71 insertions(+), 10 deletions(-) diff --git a/Unzip.cs b/Unzip.cs index 18a9dbe..65456ff 100644 --- a/Unzip.cs +++ b/Unzip.cs @@ -1,8 +1,9 @@ -// Unzip class for .NET 3.5 +// Unzip class for .NET 3.5 Client Profile or Mono 2.10 // Written by Alexey Yakovlev using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.IO.Compression; using System.Linq; @@ -13,7 +14,7 @@ namespace Internals /// /// Unzip helper class. /// - public class Unzip : IDisposable + internal class Unzip : IDisposable { private const int EntrySignature = 0x02014B50; @@ -28,32 +29,66 @@ public class Unzip : IDisposable /// public class Entry { + /// + /// Gets or sets the name of a file or a directory. + /// public string Name { get; set; } + /// + /// Gets or sets the comment. + /// public string Comment { get; set; } + /// + /// Gets or sets the CRC32. + /// public int Crc32 { get; set; } + /// + /// Gets or sets the compressed size of the file. + /// public int CompressedSize { get; set; } + /// + /// Gets or sets the original size of the file. + /// public int OriginalSize { get; set; } - public int HeaderOffset { get; set; } - - public int DataOffset { get; set; } - + /// + /// Gets or sets a value indicating whether this is deflated. + /// public bool Deflated { get; set; } + /// + /// Gets a value indicating whether this is a directory. + /// public bool IsDirectory { get { return Name.EndsWith("/"); } } + /// + /// Gets a value indicating whether this is a file. + /// public bool IsFile { get { return !IsDirectory; } } + + [EditorBrowsable(EditorBrowsableState.Never)] + public int HeaderOffset { get; set; } + + [EditorBrowsable(EditorBrowsableState.Never)] + public int DataOffset { get; set; } } + /// + /// Initializes a new instance of the class. + /// + /// Name of the file. public Unzip(string fileName) : this(File.OpenRead(fileName)) { } + /// + /// Initializes a new instance of the class. + /// + /// The stream. public Unzip(Stream stream) { Stream = stream; @@ -64,6 +99,10 @@ public Unzip(Stream stream) private BinaryReader Reader { get; set; } + /// + /// Performs application-defined tasks associated with + /// freeing, releasing, or resetting unmanaged resources. + /// public void Dispose() { if (Stream != null) @@ -79,11 +118,15 @@ public void Dispose() } } + /// + /// Extracts the contents of the zip file to the given directory. + /// + /// Name of the directory. public void ExtractToDirectory(string directoryName) { foreach (var entry in Entries.Where(e => !e.IsDirectory)) { - // create target directory with file folder + // create target directory for the file var fileName = Path.Combine(directoryName, entry.Name); var dirName = Path.GetDirectoryName(fileName); Directory.CreateDirectory(dirName); @@ -96,19 +139,30 @@ public void ExtractToDirectory(string directoryName) } } + /// + /// Extracts the specified file name. + /// + /// Name of the file. + /// The output stream. public void Extract(string fileName, Stream outputStream) { var entry = Entries.Where(e => e.Name == fileName).First(); Extract(entry, outputStream); } + /// + /// Extracts the specified entry. + /// + /// Zip file entry to extract. + /// The stream to write the data to. + /// is thrown when the file header signature doesn't match. public void Extract(Entry entry, Stream outputStream) { // check file signature Stream.Seek(entry.HeaderOffset, SeekOrigin.Begin); if (Reader.ReadInt32() != FileSignature) { - throw new InvalidOperationException("File signature don't match."); + throw new InvalidOperationException("File signature doesn't match."); } // move to file data @@ -139,6 +193,9 @@ public void Extract(Entry entry, Stream outputStream) } } + /// + /// Gets the file names. + /// public IEnumerable FileNames { get @@ -149,6 +206,9 @@ public IEnumerable FileNames private Entry[] entries; + /// + /// Gets zip file entries. + /// public IEnumerable Entries { get diff --git a/Unzip.csproj b/Unzip.csproj index 6f5e0e1..2f5a2c9 100644 --- a/Unzip.csproj +++ b/Unzip.csproj @@ -23,6 +23,7 @@ prompt 4 true + bin\Debug\Unzip.XML AnyCPU diff --git a/UsageExample.cs b/UsageExample.cs index fac399a..10c7470 100644 --- a/UsageExample.cs +++ b/UsageExample.cs @@ -6,9 +6,9 @@ namespace Internals { - struct Program + internal struct Program { - static void Main(string[] args) + private static void Main(string[] args) { if (args.Length < 2) {