Permalink
Browse files

minor

  • Loading branch information...
1 parent e67ed03 commit fd0b39e7324a1c37db1653e2a6cfadc290dcd806 @DanielDar DanielDar committed Feb 12, 2013
Showing with 9,683 additions and 9,683 deletions.
  1. +6 −6 Raven.Abstractions/MEF/PartMetadata.cs
  2. +34 −34 Raven.Abstractions/Replication/ReplicationDocument.cs
  3. +25 −25 Raven.Client.Lightweight/Linq/ReflectionExtensions.cs
  4. +88 −88 Raven.Client.Lightweight/Linq/TypeSystem.cs
  5. +67 −67 Raven.Client.Silverlight/DotNetZip/Adler.cs
  6. +9 −9 Raven.Client.Silverlight/DotNetZip/BlockState.cs
  7. +78 −78 Raven.Client.Silverlight/DotNetZip/CompressionLevel.cs
  8. +16 −16 Raven.Client.Silverlight/DotNetZip/CompressionMode.cs
  9. +29 −29 Raven.Client.Silverlight/DotNetZip/CompressionStrategy.cs
  10. +270 −270 Raven.Client.Silverlight/DotNetZip/CrcCalculatorStream.cs
  11. +8 −8 Raven.Client.Silverlight/DotNetZip/DeflateFlavor.cs
  12. +1,868 −1,868 Raven.Client.Silverlight/DotNetZip/DeflateManager.cs
  13. +723 −723 Raven.Client.Silverlight/DotNetZip/DeflateStream.cs
  14. +43 −43 Raven.Client.Silverlight/DotNetZip/FlushType.cs
  15. +435 −435 Raven.Client.Silverlight/DotNetZip/InfTree.cs
  16. +735 −735 Raven.Client.Silverlight/DotNetZip/InflateBlocks.cs
  17. +658 −658 Raven.Client.Silverlight/DotNetZip/InflateCodes.cs
  18. +395 −395 Raven.Client.Silverlight/DotNetZip/InflateManager.cs
  19. +24 −24 Raven.Client.Silverlight/DotNetZip/InternalConstants.cs
  20. +11 −11 Raven.Client.Silverlight/DotNetZip/InternalInflateConstants.cs
  21. +1,135 −1,135 Raven.Client.Silverlight/DotNetZip/ParallelDeflateOutputStream.cs
  22. +72 −72 Raven.Client.Silverlight/DotNetZip/SharedUtils.cs
  23. +74 −74 Raven.Client.Silverlight/DotNetZip/StaticTree.cs
  24. +422 −422 Raven.Client.Silverlight/DotNetZip/Tree.cs
  25. +28 −28 Raven.Client.Silverlight/DotNetZip/WorkItem.cs
  26. +624 −624 Raven.Client.Silverlight/DotNetZip/ZlibBaseStream.cs
  27. +716 −716 Raven.Client.Silverlight/DotNetZip/ZlibCodec.cs
  28. +128 −128 Raven.Client.Silverlight/DotNetZip/ZlibConstants.cs
  29. +95 −95 Raven.Client.Silverlight/DotNetZip/ZlibException.cs
  30. +682 −682 Raven.Client.Silverlight/DotNetZip/ZlibStream.cs
  31. +3 −3 Raven.Client.Silverlight/DotNetZip/ZlibStreamFlavor.cs
  32. +44 −44 Raven.Client.Silverlight/MissingFromSilverlight/Stopwatch.cs
  33. +29 −29 Raven.Database/Linq/PrivateExtensions/MetadataExtensions.cs
  34. +34 −34 Raven.Database/Plugins/Builtins/FilterRavenInternalDocumentsReadTrigger.cs
  35. +75 −75 Raven.Studio/Features/Documents/TemplateColorProvider.cs
View
12 Raven.Abstractions/MEF/PartMetadata.cs
@@ -1,7 +1,7 @@
-namespace Raven.Abstractions.MEF
-{
- public class PartMetadata : IPartMetadata
- {
- public int Order { get; set; }
- }
+namespace Raven.Abstractions.MEF
+{
+ public class PartMetadata : IPartMetadata
+ {
+ public int Order { get; set; }
+ }
}
View
68 Raven.Abstractions/Replication/ReplicationDocument.cs
@@ -1,35 +1,35 @@
-//-----------------------------------------------------------------------
-// <copyright file="ReplicationDocument.cs" company="Hibernating Rhinos LTD">
-// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-using System.Collections.Generic;
-
-namespace Raven.Abstractions.Replication
-{
- /// <summary>
- /// This class represent the list of replication destinations for the server
- /// </summary>
- public class ReplicationDocument
- {
- /// <summary>
- /// Gets or sets the list of replication destinations.
- /// </summary>
- public List<ReplicationDestination> Destinations { get; set; }
-
- /// <summary>
- /// Gets or sets the id.
- /// </summary>
- /// <value>The id.</value>
- public string Id { get; set; }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ReplicationDocument"/> class.
- /// </summary>
- public ReplicationDocument()
- {
- Id = "Raven/Replication/Destinations";
- Destinations = new List<ReplicationDestination>();
- }
- }
+//-----------------------------------------------------------------------
+// <copyright file="ReplicationDocument.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+using System.Collections.Generic;
+
+namespace Raven.Abstractions.Replication
+{
+ /// <summary>
+ /// This class represent the list of replication destinations for the server
+ /// </summary>
+ public class ReplicationDocument
+ {
+ /// <summary>
+ /// Gets or sets the list of replication destinations.
+ /// </summary>
+ public List<ReplicationDestination> Destinations { get; set; }
+
+ /// <summary>
+ /// Gets or sets the id.
+ /// </summary>
+ /// <value>The id.</value>
+ public string Id { get; set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ReplicationDocument"/> class.
+ /// </summary>
+ public ReplicationDocument()
+ {
+ Id = "Raven/Replication/Destinations";
+ Destinations = new List<ReplicationDestination>();
+ }
+ }
}
View
50 Raven.Client.Lightweight/Linq/ReflectionExtensions.cs
@@ -1,26 +1,26 @@
-//-----------------------------------------------------------------------
-// <copyright file="ReflectionExtensions.cs" company="Hibernating Rhinos LTD">
-// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-using System;
-using System.Reflection;
-
-namespace Raven.Client.Linq
-{
- internal static class ReflectionExtensions
- {
- public static Type GetMemberType(this MemberInfo member)
- {
- switch (member.MemberType)
- {
- case MemberTypes.Field:
- return ((FieldInfo)member).FieldType;
- case MemberTypes.Property:
- return ((PropertyInfo)member).PropertyType;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
- }
+//-----------------------------------------------------------------------
+// <copyright file="ReflectionExtensions.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+using System;
+using System.Reflection;
+
+namespace Raven.Client.Linq
+{
+ internal static class ReflectionExtensions
+ {
+ public static Type GetMemberType(this MemberInfo member)
+ {
+ switch (member.MemberType)
+ {
+ case MemberTypes.Field:
+ return ((FieldInfo)member).FieldType;
+ case MemberTypes.Property:
+ return ((PropertyInfo)member).PropertyType;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+ }
}
View
176 Raven.Client.Lightweight/Linq/TypeSystem.cs
@@ -1,88 +1,88 @@
-//-----------------------------------------------------------------------
-// <copyright file="TypeSystem.cs" company="Hibernating Rhinos LTD">
-// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace Raven.Client.Linq
-{
- internal static class TypeSystem
- {
- private static Type FindIEnumerable(Type seqType)
- {
- if (seqType == null || seqType == typeof(string))
- return null;
- if (seqType.IsArray)
- return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
- if (seqType.IsGenericType)
- {
- foreach (Type arg in seqType.GetGenericArguments())
- {
- Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
- if (ienum.IsAssignableFrom(seqType))
- return ienum;
- }
- }
- Type[] ifaces = seqType.GetInterfaces();
- if (ifaces != null && ifaces.Length > 0)
- {
- foreach (Type iface in ifaces)
- {
- Type ienum = FindIEnumerable(iface);
- if (ienum != null)
- return ienum;
- }
- }
- if (seqType.BaseType != null && seqType.BaseType != typeof(object))
- return FindIEnumerable(seqType.BaseType);
- return null;
- }
-
- internal static Type GetSequenceType(Type elementType)
- {
- return typeof(IEnumerable<>).MakeGenericType(elementType);
- }
-
- internal static Type GetElementType(Type seqType)
- {
- Type ienum = FindIEnumerable(seqType);
- if (ienum == null)
- return seqType;
- return ienum.GetGenericArguments()[0];
- }
-
- internal static bool IsNullableType(Type type)
- {
- return type != null && type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
- }
-
- internal static bool IsNullAssignable(Type type)
- {
- return !type.IsValueType || IsNullableType(type);
- }
-
- internal static Type GetNonNullableType(Type type)
- {
- if (IsNullableType(type))
- return type.GetGenericArguments()[0];
- return type;
- }
-
- internal static Type GetMemberType(MemberInfo mi)
- {
- FieldInfo fi = mi as FieldInfo;
- if (fi != null)
- return fi.FieldType;
- PropertyInfo pi = mi as PropertyInfo;
- if (pi != null)
- return pi.PropertyType;
- EventInfo ei = mi as EventInfo;
- if (ei != null)
- return ei.EventHandlerType;
- return null;
- }
- }
-}
+//-----------------------------------------------------------------------
+// <copyright file="TypeSystem.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace Raven.Client.Linq
+{
+ internal static class TypeSystem
+ {
+ private static Type FindIEnumerable(Type seqType)
+ {
+ if (seqType == null || seqType == typeof(string))
+ return null;
+ if (seqType.IsArray)
+ return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
+ if (seqType.IsGenericType)
+ {
+ foreach (Type arg in seqType.GetGenericArguments())
+ {
+ Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
+ if (ienum.IsAssignableFrom(seqType))
+ return ienum;
+ }
+ }
+ Type[] ifaces = seqType.GetInterfaces();
+ if (ifaces != null && ifaces.Length > 0)
+ {
+ foreach (Type iface in ifaces)
+ {
+ Type ienum = FindIEnumerable(iface);
+ if (ienum != null)
+ return ienum;
+ }
+ }
+ if (seqType.BaseType != null && seqType.BaseType != typeof(object))
+ return FindIEnumerable(seqType.BaseType);
+ return null;
+ }
+
+ internal static Type GetSequenceType(Type elementType)
+ {
+ return typeof(IEnumerable<>).MakeGenericType(elementType);
+ }
+
+ internal static Type GetElementType(Type seqType)
+ {
+ Type ienum = FindIEnumerable(seqType);
+ if (ienum == null)
+ return seqType;
+ return ienum.GetGenericArguments()[0];
+ }
+
+ internal static bool IsNullableType(Type type)
+ {
+ return type != null && type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
+ }
+
+ internal static bool IsNullAssignable(Type type)
+ {
+ return !type.IsValueType || IsNullableType(type);
+ }
+
+ internal static Type GetNonNullableType(Type type)
+ {
+ if (IsNullableType(type))
+ return type.GetGenericArguments()[0];
+ return type;
+ }
+
+ internal static Type GetMemberType(MemberInfo mi)
+ {
+ FieldInfo fi = mi as FieldInfo;
+ if (fi != null)
+ return fi.FieldType;
+ PropertyInfo pi = mi as PropertyInfo;
+ if (pi != null)
+ return pi.PropertyType;
+ EventInfo ei = mi as EventInfo;
+ if (ei != null)
+ return ei.EventHandlerType;
+ return null;
+ }
+ }
+}
View
134 Raven.Client.Silverlight/DotNetZip/Adler.cs
@@ -1,68 +1,68 @@
-namespace Ionic.Zlib
-{
- /// <summary>
- /// Computes an Adler-32 checksum.
- /// </summary>
- /// <remarks>
- /// The Adler checksum is similar to a CRC checksum, but faster to compute, though less
- /// reliable. It is used in producing RFC1950 compressed streams. The Adler checksum
- /// is a required part of the "ZLIB" standard. Applications will almost never need to
- /// use this class directly.
- /// </remarks>
- internal sealed class Adler
- {
- // largest prime smaller than 65536
- private static readonly int BASE = 65521;
- // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
- private static readonly int NMAX = 5552;
-
- static internal uint Adler32(uint adler, byte[] buf, int index, int len)
- {
- if (buf == null)
- return 1;
-
- int s1 = (int) (adler & 0xffff);
- int s2 = (int) ((adler >> 16) & 0xffff);
-
- while (len > 0)
- {
- int k = len < NMAX ? len : NMAX;
- len -= k;
- while (k >= 16)
- {
- //s1 += (buf[index++] & 0xff); s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- s1 += buf[index++]; s2 += s1;
- k -= 16;
- }
- if (k != 0)
- {
- do
- {
- s1 += buf[index++];
- s2 += s1;
- }
- while (--k != 0);
- }
- s1 %= BASE;
- s2 %= BASE;
- }
- return (uint)((s2 << 16) | s1);
- }
-
- }
+namespace Ionic.Zlib
+{
+ /// <summary>
+ /// Computes an Adler-32 checksum.
+ /// </summary>
+ /// <remarks>
+ /// The Adler checksum is similar to a CRC checksum, but faster to compute, though less
+ /// reliable. It is used in producing RFC1950 compressed streams. The Adler checksum
+ /// is a required part of the "ZLIB" standard. Applications will almost never need to
+ /// use this class directly.
+ /// </remarks>
+ internal sealed class Adler
+ {
+ // largest prime smaller than 65536
+ private static readonly int BASE = 65521;
+ // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
+ private static readonly int NMAX = 5552;
+
+ static internal uint Adler32(uint adler, byte[] buf, int index, int len)
+ {
+ if (buf == null)
+ return 1;
+
+ int s1 = (int) (adler & 0xffff);
+ int s2 = (int) ((adler >> 16) & 0xffff);
+
+ while (len > 0)
+ {
+ int k = len < NMAX ? len : NMAX;
+ len -= k;
+ while (k >= 16)
+ {
+ //s1 += (buf[index++] & 0xff); s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ s1 += buf[index++]; s2 += s1;
+ k -= 16;
+ }
+ if (k != 0)
+ {
+ do
+ {
+ s1 += buf[index++];
+ s2 += s1;
+ }
+ while (--k != 0);
+ }
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+ return (uint)((s2 << 16) | s1);
+ }
+
+ }
}
View
18 Raven.Client.Silverlight/DotNetZip/BlockState.cs
@@ -1,10 +1,10 @@
-namespace Ionic.Zlib
-{
- internal enum BlockState
- {
- NeedMore = 0, // block not completed, need more input or more output
- BlockDone, // block flush performed
- FinishStarted, // finish started, need only more output at next deflate
- FinishDone // finish done, accept no more input or output
- }
+namespace Ionic.Zlib
+{
+ internal enum BlockState
+ {
+ NeedMore = 0, // block not completed, need more input or more output
+ BlockDone, // block flush performed
+ FinishStarted, // finish started, need only more output at next deflate
+ FinishDone // finish done, accept no more input or output
+ }
}
View
156 Raven.Client.Silverlight/DotNetZip/CompressionLevel.cs
@@ -1,79 +1,79 @@
-namespace Ionic.Zlib
-{
- /// <summary>
- /// The compression level to be used when using a DeflateStream or ZlibStream with CompressionMode.Compress.
- /// </summary>
- public enum CompressionLevel
- {
- /// <summary>
- /// None means that the data will be simply stored, with no change at all.
- /// If you are producing ZIPs for use on Mac OSX, be aware that archives produced with CompressionLevel.None
- /// cannot be opened with the default zip reader. Use a different CompressionLevel.
- /// </summary>
- None= 0,
- /// <summary>
- /// Same as None.
- /// </summary>
- Level0 = 0,
-
- /// <summary>
- /// The fastest but least effective compression.
- /// </summary>
- BestSpeed = 1,
-
- /// <summary>
- /// A synonym for BestSpeed.
- /// </summary>
- Level1 = 1,
-
- /// <summary>
- /// A little slower, but better, than level 1.
- /// </summary>
- Level2 = 2,
-
- /// <summary>
- /// A little slower, but better, than level 2.
- /// </summary>
- Level3 = 3,
-
- /// <summary>
- /// A little slower, but better, than level 3.
- /// </summary>
- Level4 = 4,
-
- /// <summary>
- /// A little slower than level 4, but with better compression.
- /// </summary>
- Level5 = 5,
-
- /// <summary>
- /// The default compression level, with a good balance of speed and compression efficiency.
- /// </summary>
- Default = 6,
- /// <summary>
- /// A synonym for Default.
- /// </summary>
- Level6 = 6,
-
- /// <summary>
- /// Pretty good compression!
- /// </summary>
- Level7 = 7,
-
- /// <summary>
- /// Better compression than Level7!
- /// </summary>
- Level8 = 8,
-
- /// <summary>
- /// The "best" compression, where best means greatest reduction in size of the input data stream.
- /// This is also the slowest compression.
- /// </summary>
- BestCompression = 9,
-
- /// <summary>
- /// A synonym for BestCompression.
- /// </summary>
- Level9 = 9,
- }
+namespace Ionic.Zlib
+{
+ /// <summary>
+ /// The compression level to be used when using a DeflateStream or ZlibStream with CompressionMode.Compress.
+ /// </summary>
+ public enum CompressionLevel
+ {
+ /// <summary>
+ /// None means that the data will be simply stored, with no change at all.
+ /// If you are producing ZIPs for use on Mac OSX, be aware that archives produced with CompressionLevel.None
+ /// cannot be opened with the default zip reader. Use a different CompressionLevel.
+ /// </summary>
+ None= 0,
+ /// <summary>
+ /// Same as None.
+ /// </summary>
+ Level0 = 0,
+
+ /// <summary>
+ /// The fastest but least effective compression.
+ /// </summary>
+ BestSpeed = 1,
+
+ /// <summary>
+ /// A synonym for BestSpeed.
+ /// </summary>
+ Level1 = 1,
+
+ /// <summary>
+ /// A little slower, but better, than level 1.
+ /// </summary>
+ Level2 = 2,
+
+ /// <summary>
+ /// A little slower, but better, than level 2.
+ /// </summary>
+ Level3 = 3,
+
+ /// <summary>
+ /// A little slower, but better, than level 3.
+ /// </summary>
+ Level4 = 4,
+
+ /// <summary>
+ /// A little slower than level 4, but with better compression.
+ /// </summary>
+ Level5 = 5,
+
+ /// <summary>
+ /// The default compression level, with a good balance of speed and compression efficiency.
+ /// </summary>
+ Default = 6,
+ /// <summary>
+ /// A synonym for Default.
+ /// </summary>
+ Level6 = 6,
+
+ /// <summary>
+ /// Pretty good compression!
+ /// </summary>
+ Level7 = 7,
+
+ /// <summary>
+ /// Better compression than Level7!
+ /// </summary>
+ Level8 = 8,
+
+ /// <summary>
+ /// The "best" compression, where best means greatest reduction in size of the input data stream.
+ /// This is also the slowest compression.
+ /// </summary>
+ BestCompression = 9,
+
+ /// <summary>
+ /// A synonym for BestCompression.
+ /// </summary>
+ Level9 = 9,
+ }
}
View
32 Raven.Client.Silverlight/DotNetZip/CompressionMode.cs
@@ -1,17 +1,17 @@
-namespace Ionic.Zlib
-{
- /// <summary>
- /// An enum to specify the direction of transcoding - whether to compress or decompress.
- /// </summary>
- public enum CompressionMode
- {
- /// <summary>
- /// Used to specify that the stream should compress the data.
- /// </summary>
- Compress= 0,
- /// <summary>
- /// Used to specify that the stream should decompress the data.
- /// </summary>
- Decompress = 1,
- }
+namespace Ionic.Zlib
+{
+ /// <summary>
+ /// An enum to specify the direction of transcoding - whether to compress or decompress.
+ /// </summary>
+ public enum CompressionMode
+ {
+ /// <summary>
+ /// Used to specify that the stream should compress the data.
+ /// </summary>
+ Compress= 0,
+ /// <summary>
+ /// Used to specify that the stream should decompress the data.
+ /// </summary>
+ Decompress = 1,
+ }
}
View
58 Raven.Client.Silverlight/DotNetZip/CompressionStrategy.cs
@@ -1,30 +1,30 @@
-namespace Ionic.Zlib
-{
- /// <summary>
- /// Describes options for how the compression algorithm is executed. Different strategies
- /// work better on different sorts of data. The strategy parameter can affect the compression
- /// ratio and the speed of compression but not the correctness of the compresssion.
- /// </summary>
- public enum CompressionStrategy
- {
- /// <summary>
- /// The default strategy is probably the best for normal data.
- /// </summary>
- Default = 0,
-
- /// <summary>
- /// The <c>Filtered</c> strategy is intended to be used most effectively with data produced by a
- /// filter or predictor. By this definition, filtered data consists mostly of small
- /// values with a somewhat random distribution. In this case, the compression algorithm
- /// is tuned to compress them better. The effect of <c>Filtered</c> is to force more Huffman
- /// coding and less string matching; it is a half-step between <c>Default</c> and <c>HuffmanOnly</c>.
- /// </summary>
- Filtered = 1,
-
- /// <summary>
- /// Using <c>HuffmanOnly</c> will force the compressor to do Huffman encoding only, with no
- /// string matching.
- /// </summary>
- HuffmanOnly = 2,
- }
+namespace Ionic.Zlib
+{
+ /// <summary>
+ /// Describes options for how the compression algorithm is executed. Different strategies
+ /// work better on different sorts of data. The strategy parameter can affect the compression
+ /// ratio and the speed of compression but not the correctness of the compresssion.
+ /// </summary>
+ public enum CompressionStrategy
+ {
+ /// <summary>
+ /// The default strategy is probably the best for normal data.
+ /// </summary>
+ Default = 0,
+
+ /// <summary>
+ /// The <c>Filtered</c> strategy is intended to be used most effectively with data produced by a
+ /// filter or predictor. By this definition, filtered data consists mostly of small
+ /// values with a somewhat random distribution. In this case, the compression algorithm
+ /// is tuned to compress them better. The effect of <c>Filtered</c> is to force more Huffman
+ /// coding and less string matching; it is a half-step between <c>Default</c> and <c>HuffmanOnly</c>.
+ /// </summary>
+ Filtered = 1,
+
+ /// <summary>
+ /// Using <c>HuffmanOnly</c> will force the compressor to do Huffman encoding only, with no
+ /// string matching.
+ /// </summary>
+ HuffmanOnly = 2,
+ }
}
View
540 Raven.Client.Silverlight/DotNetZip/CrcCalculatorStream.cs
@@ -1,271 +1,271 @@
-using System;
-
-namespace Ionic.Zlib
-{
- /// <summary>
- /// A Stream that calculates a CRC32 (a checksum) on all bytes read,
- /// or on all bytes written.
- /// </summary>
- ///
- /// <remarks>
- /// <para>
- /// This class can be used to verify the CRC of a ZipEntry when
- /// reading from a stream, or to calculate a CRC when writing to a
- /// stream. The stream should be used to either read, or write, but
- /// not both. If you intermix reads and writes, the results are not
- /// defined.
- /// </para>
- ///
- /// <para>
- /// This class is intended primarily for use internally by the
- /// DotNetZip library.
- /// </para>
- /// </remarks>
- public class CrcCalculatorStream : System.IO.Stream, System.IDisposable
- {
- private static readonly Int64 UnsetLengthLimit = -99;
-
- internal System.IO.Stream _innerStream;
- private CRC32 _Crc32;
- private Int64 _lengthLimit = -99;
- private bool _leaveOpen;
-
- /// <summary>
- /// Gets the total number of bytes run through the CRC32 calculator.
- /// </summary>
- ///
- /// <remarks>
- /// This is either the total number of bytes read, or the total number of bytes
- /// written, depending on the direction of this stream.
- /// </remarks>
- public Int64 TotalBytesSlurped
- {
- get { return _Crc32.TotalBytesRead; }
- }
-
-
- /// <summary>
- /// The default constructor.
- /// </summary>
- /// <remarks>
- /// Instances returned from this constructor will leave the underlying stream
- /// open upon Close().
- /// </remarks>
- /// <param name="stream">The underlying stream</param>
- public CrcCalculatorStream(System.IO.Stream stream)
- : this(true, CrcCalculatorStream.UnsetLengthLimit, stream)
- {
- }
-
-
- /// <summary>
- /// The constructor allows the caller to specify how to handle the underlying
- /// stream at close.
- /// </summary>
- /// <param name="stream">The underlying stream</param>
- /// <param name="leaveOpen">true to leave the underlying stream
- /// open upon close of the CrcCalculatorStream.; false otherwise.</param>
- public CrcCalculatorStream(System.IO.Stream stream, bool leaveOpen)
- : this(leaveOpen, CrcCalculatorStream.UnsetLengthLimit, stream)
- {
- }
-
-
- /// <summary>
- /// A constructor allowing the specification of the length of the stream to read.
- /// </summary>
- /// <remarks>
- /// Instances returned from this constructor will leave the underlying stream open
- /// upon Close().
- /// </remarks>
- /// <param name="stream">The underlying stream</param>
- /// <param name="length">The length of the stream to slurp</param>
- public CrcCalculatorStream(System.IO.Stream stream, Int64 length)
- : this(true, length, stream)
- {
- if (length < 0)
- throw new ArgumentException("length");
- }
-
- /// <summary>
- /// A constructor allowing the specification of the length of the stream to
- /// read, as well as whether to keep the underlying stream open upon Close().
- /// </summary>
- /// <param name="stream">The underlying stream</param>
- /// <param name="length">The length of the stream to slurp</param>
- /// <param name="leaveOpen">true to leave the underlying stream
- /// open upon close of the CrcCalculatorStream.; false otherwise.</param>
- public CrcCalculatorStream(System.IO.Stream stream, Int64 length, bool leaveOpen)
- : this(leaveOpen, length, stream)
- {
- if (length < 0)
- throw new ArgumentException("length");
- }
-
-
- // This ctor is private - no validation is done here. This is to allow the use
- // of a (specific) negative value for the _lengthLimit, to indicate that there
- // is no length set. So we validate the length limit in those ctors that use an
- // explicit param, otherwise we don't validate, because it could be our special
- // value.
- private CrcCalculatorStream(bool leaveOpen, Int64 length, System.IO.Stream stream)
- : base()
- {
- _innerStream = stream;
- _Crc32 = new CRC32();
- _lengthLimit = length;
- _leaveOpen = leaveOpen;
- }
-
- /// <summary>
- /// Provides the current CRC for all blocks slurped in.
- /// </summary>
- public Int32 Crc
- {
- get { return _Crc32.Crc32Result; }
- }
-
- /// <summary>
- /// Indicates whether the underlying stream will be left open when the
- /// CrcCalculatorStream is Closed.
- /// </summary>
- public bool LeaveOpen
- {
- get { return _leaveOpen; }
- set { _leaveOpen = value; }
- }
-
- /// <summary>
- /// Read from the stream
- /// </summary>
- /// <param name="buffer">the buffer to read</param>
- /// <param name="offset">the offset at which to start</param>
- /// <param name="count">the number of bytes to read</param>
- /// <returns>the number of bytes actually read</returns>
- public override int Read(byte[] buffer, int offset, int count)
- {
- int bytesToRead = count;
-
- // Need to limit the # of bytes returned, if the stream is intended to have
- // a definite length. This is especially useful when returning a stream for
- // the uncompressed data directly to the application. The app won't
- // necessarily read only the UncompressedSize number of bytes. For example
- // wrapping the stream returned from OpenReader() into a StreadReader() and
- // calling ReadToEnd() on it, We can "over-read" the zip data and get a
- // corrupt string. The length limits that, prevents that problem.
-
- if (_lengthLimit != CrcCalculatorStream.UnsetLengthLimit)
- {
- if (_Crc32.TotalBytesRead >= _lengthLimit) return 0; // EOF
- Int64 bytesRemaining = _lengthLimit - _Crc32.TotalBytesRead;
- if (bytesRemaining < count) bytesToRead = (int)bytesRemaining;
- }
- int n = _innerStream.Read(buffer, offset, bytesToRead);
- if (n > 0) _Crc32.SlurpBlock(buffer, offset, n);
- return n;
- }
-
- /// <summary>
- /// Write to the stream.
- /// </summary>
- /// <param name="buffer">the buffer from which to write</param>
- /// <param name="offset">the offset at which to start writing</param>
- /// <param name="count">the number of bytes to write</param>
- public override void Write(byte[] buffer, int offset, int count)
- {
- if (count > 0) _Crc32.SlurpBlock(buffer, offset, count);
- _innerStream.Write(buffer, offset, count);
- }
-
- /// <summary>
- /// Indicates whether the stream supports reading.
- /// </summary>
- public override bool CanRead
- {
- get { return _innerStream.CanRead; }
- }
-
- /// <summary>
- /// Indicates whether the stream supports seeking.
- /// </summary>
- public override bool CanSeek
- {
- get { return _innerStream.CanSeek; }
- }
-
- /// <summary>
- /// Indicates whether the stream supports writing.
- /// </summary>
- public override bool CanWrite
- {
- get { return _innerStream.CanWrite; }
- }
-
- /// <summary>
- /// Flush the stream.
- /// </summary>
- public override void Flush()
- {
- _innerStream.Flush();
- }
-
- /// <summary>
- /// Not implemented.
- /// </summary>
- public override long Length
- {
- get
- {
- if (_lengthLimit == CrcCalculatorStream.UnsetLengthLimit)
- return _innerStream.Length;
- else return _lengthLimit;
- }
- }
-
- /// <summary>
- /// Not implemented.
- /// </summary>
- public override long Position
- {
- get { return _Crc32.TotalBytesRead; }
- set { throw new NotImplementedException(); }
- }
-
- /// <summary>
- /// Not implemented.
- /// </summary>
- /// <param name="offset">N/A</param>
- /// <param name="origin">N/A</param>
- /// <returns>N/A</returns>
- public override long Seek(long offset, System.IO.SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Not implemented.
- /// </summary>
- /// <param name="value">N/A</param>
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
-
- void IDisposable.Dispose()
- {
- Close();
- }
-
- /// <summary>
- /// Closes the stream.
- /// </summary>
- public override void Close()
- {
- base.Close();
- if (!_leaveOpen)
- _innerStream.Close();
- }
-
- }
+using System;
+
+namespace Ionic.Zlib
+{
+ /// <summary>
+ /// A Stream that calculates a CRC32 (a checksum) on all bytes read,
+ /// or on all bytes written.
+ /// </summary>
+ ///
+ /// <remarks>
+ /// <para>
+ /// This class can be used to verify the CRC of a ZipEntry when
+ /// reading from a stream, or to calculate a CRC when writing to a
+ /// stream. The stream should be used to either read, or write, but
+ /// not both. If you intermix reads and writes, the results are not
+ /// defined.
+ /// </para>
+ ///
+ /// <para>
+ /// This class is intended primarily for use internally by the
+ /// DotNetZip library.
+ /// </para>
+ /// </remarks>
+ public class CrcCalculatorStream : System.IO.Stream, System.IDisposable
+ {
+ private static readonly Int64 UnsetLengthLimit = -99;
+
+ internal System.IO.Stream _innerStream;
+ private CRC32 _Crc32;
+ private Int64 _lengthLimit = -99;
+ private bool _leaveOpen;
+
+ /// <summary>
+ /// Gets the total number of bytes run through the CRC32 calculator.
+ /// </summary>
+ ///
+ /// <remarks>
+ /// This is either the total number of bytes read, or the total number of bytes
+ /// written, depending on the direction of this stream.
+ /// </remarks>
+ public Int64 TotalBytesSlurped
+ {
+ get { return _Crc32.TotalBytesRead; }
+ }
+
+
+ /// <summary>
+ /// The default constructor.
+ /// </summary>
+ /// <remarks>
+ /// Instances returned from this constructor will leave the underlying stream
+ /// open upon Close().
+ /// </remarks>
+ /// <param name="stream">The underlying stream</param>
+ public CrcCalculatorStream(System.IO.Stream stream)
+ : this(true, CrcCalculatorStream.UnsetLengthLimit, stream)
+ {
+ }
+
+
+ /// <summary>
+ /// The constructor allows the caller to specify how to handle the underlying
+ /// stream at close.
+ /// </summary>
+ /// <param name="stream">The underlying stream</param>
+ /// <param name="leaveOpen">true to leave the underlying stream
+ /// open upon close of the CrcCalculatorStream.; false otherwise.</param>
+ public CrcCalculatorStream(System.IO.Stream stream, bool leaveOpen)
+ : this(leaveOpen, CrcCalculatorStream.UnsetLengthLimit, stream)
+ {
+ }
+
+
+ /// <summary>
+ /// A constructor allowing the specification of the length of the stream to read.
+ /// </summary>
+ /// <remarks>
+ /// Instances returned from this constructor will leave the underlying stream open
+ /// upon Close().
+ /// </remarks>
+ /// <param name="stream">The underlying stream</param>
+ /// <param name="length">The length of the stream to slurp</param>
+ public CrcCalculatorStream(System.IO.Stream stream, Int64 length)
+ : this(true, length, stream)
+ {
+ if (length < 0)
+ throw new ArgumentException("length");
+ }
+
+ /// <summary>
+ /// A constructor allowing the specification of the length of the stream to
+ /// read, as well as whether to keep the underlying stream open upon Close().
+ /// </summary>
+ /// <param name="stream">The underlying stream</param>
+ /// <param name="length">The length of the stream to slurp</param>
+ /// <param name="leaveOpen">true to leave the underlying stream
+ /// open upon close of the CrcCalculatorStream.; false otherwise.</param>
+ public CrcCalculatorStream(System.IO.Stream stream, Int64 length, bool leaveOpen)
+ : this(leaveOpen, length, stream)
+ {
+ if (length < 0)
+ throw new ArgumentException("length");
+ }
+
+
+ // This ctor is private - no validation is done here. This is to allow the use
+ // of a (specific) negative value for the _lengthLimit, to indicate that there
+ // is no length set. So we validate the length limit in those ctors that use an
+ // explicit param, otherwise we don't validate, because it could be our special
+ // value.
+ private CrcCalculatorStream(bool leaveOpen, Int64 length, System.IO.Stream stream)
+ : base()
+ {
+ _innerStream = stream;
+ _Crc32 = new CRC32();
+ _lengthLimit = length;
+ _leaveOpen = leaveOpen;
+ }
+
+ /// <summary>
+ /// Provides the current CRC for all blocks slurped in.
+ /// </summary>
+ public Int32 Crc
+ {
+ get { return _Crc32.Crc32Result; }
+ }
+
+ /// <summary>
+ /// Indicates whether the underlying stream will be left open when the
+ /// CrcCalculatorStream is Closed.
+ /// </summary>
+ public bool LeaveOpen
+ {
+ get { return _leaveOpen; }
+ set { _leaveOpen = value; }
+ }
+
+ /// <summary>
+ /// Read from the stream
+ /// </summary>
+ /// <param name="buffer">the buffer to read</param>
+ /// <param name="offset">the offset at which to start</param>
+ /// <param name="count">the number of bytes to read</param>
+ /// <returns>the number of bytes actually read</returns>
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ int bytesToRead = count;
+
+ // Need to limit the # of bytes returned, if the stream is intended to have
+ // a definite length. This is especially useful when returning a stream for
+ // the uncompressed data directly to the application. The app won't
+ // necessarily read only the UncompressedSize number of bytes. For example
+ // wrapping the stream returned from OpenReader() into a StreadReader() and
+ // calling ReadToEnd() on it, We can "over-read" the zip data and get a
+ // corrupt string. The length limits that, prevents that problem.
+
+ if (_lengthLimit != CrcCalculatorStream.UnsetLengthLimit)
+ {
+ if (_Crc32.TotalBytesRead >= _lengthLimit) return 0; // EOF
+ Int64 bytesRemaining = _lengthLimit - _Crc32.TotalBytesRead;
+ if (bytesRemaining < count) bytesToRead = (int)bytesRemaining;
+ }
+ int n = _innerStream.Read(buffer, offset, bytesToRead);
+ if (n > 0) _Crc32.SlurpBlock(buffer, offset, n);
+ return n;
+ }
+
+ /// <summary>
+ /// Write to the stream.
+ /// </summary>
+ /// <param name="buffer">the buffer from which to write</param>
+ /// <param name="offset">the offset at which to start writing</param>
+ /// <param name="count">the number of bytes to write</param>
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ if (count > 0) _Crc32.SlurpBlock(buffer, offset, count);
+ _innerStream.Write(buffer, offset, count);
+ }
+
+ /// <summary>
+ /// Indicates whether the stream supports reading.
+ /// </summary>
+ public override bool CanRead
+ {
+ get { return _innerStream.CanRead; }
+ }
+
+ /// <summary>
+ /// Indicates whether the stream supports seeking.
+ /// </summary>
+ public override bool CanSeek
+ {
+ get { return _innerStream.CanSeek; }
+ }
+
+ /// <summary>
+ /// Indicates whether the stream supports writing.
+ /// </summary>
+ public override bool CanWrite
+ {
+ get { return _innerStream.CanWrite; }
+ }
+
+ /// <summary>
+ /// Flush the stream.
+ /// </summary>
+ public override void Flush()
+ {
+ _innerStream.Flush();
+ }
+
+ /// <summary>
+ /// Not implemented.
+ /// </summary>
+ public override long Length
+ {
+ get
+ {
+ if (_lengthLimit == CrcCalculatorStream.UnsetLengthLimit)
+ return _innerStream.Length;
+ else return _lengthLimit;
+ }
+ }
+
+ /// <summary>
+ /// Not implemented.
+ /// </summary>
+ public override long Position
+ {
+ get { return _Crc32.TotalBytesRead; }
+ set { throw new NotImplementedException(); }
+ }
+
+ /// <summary>
+ /// Not implemented.
+ /// </summary>
+ /// <param name="offset">N/A</param>
+ /// <param name="origin">N/A</param>
+ /// <returns>N/A</returns>
+ public override long Seek(long offset, System.IO.SeekOrigin origin)
+ {
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Not implemented.
+ /// </summary>
+ /// <param name="value">N/A</param>
+ public override void SetLength(long value)
+ {
+ throw new NotImplementedException();
+ }
+
+
+ void IDisposable.Dispose()
+ {
+ Close();
+ }
+
+ /// <summary>
+ /// Closes the stream.
+ /// </summary>
+ public override void Close()
+ {
+ base.Close();
+ if (!_leaveOpen)
+ _innerStream.Close();
+ }
+
+ }
}
View
16 Raven.Client.Silverlight/DotNetZip/DeflateFlavor.cs
@@ -1,9 +1,9 @@
-namespace Ionic.Zlib
-{
- internal enum DeflateFlavor
- {
- Store,
- Fast,
- Slow
- }
+namespace Ionic.Zlib
+{
+ internal enum DeflateFlavor
+ {
+ Store,
+ Fast,
+ Slow
+ }
}
View
3,736 Raven.Client.Silverlight/DotNetZip/DeflateManager.cs
1,868 additions, 1,868 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
1,446 Raven.Client.Silverlight/DotNetZip/DeflateStream.cs
@@ -1,723 +1,723 @@
-// DeflateStream.cs
-// ------------------------------------------------------------------
-//
-// Copyright (c) 2009-2010 Dino Chiesa.
-// All rights reserved.
-//
-// This code module is part of DotNetZip, a zipfile class library.
-//
-// ------------------------------------------------------------------
-//
-// This code is licensed under the Microsoft Public License.
-// See the file License.txt for the license details.
-// More info on: http://dotnetzip.codeplex.com
-//
-// ------------------------------------------------------------------
-//
-// last saved (in emacs):
-// Time-stamp: <2010-February-05 08:49:04>
-//
-// ------------------------------------------------------------------
-//
-// This module defines the DeflateStream class, which can be used as a replacement for
-// the System.IO.Compression.DeflateStream class in the .NET BCL.
-//
-// ------------------------------------------------------------------
-
-
-using System;
-
-namespace Ionic.Zlib
-{
- /// <summary>
- /// A class for compressing and decompressing streams using the Deflate algorithm.
- /// </summary>
- ///
- /// <remarks>
- ///
- /// <para>
- /// The DeflateStream is a <see
- /// href="http://en.wikipedia.org/wiki/Decorator_pattern">Decorator</see> on a <see
- /// cref="System.IO.Stream"/>. It adds DEFLATE compression or decompression to any
- /// stream.
- /// </para>
- ///
- /// <para>
- /// Using this stream, applications can compress or decompress data via stream
- /// <c>Read</c> and <c>Write</c> operations. Either compresssion or decompression
- /// can occur through either reading or writing. The compression format used is
- /// DEFLATE, which is documented in <see
- /// href="http://www.ietf.org/rfc/rfc1951.txt">IETF RFC 1951</see>, "DEFLATE
- /// Compressed Data Format Specification version 1.3.".
- /// </para>
- ///
- /// <para>
- /// This class is similar to <see cref="ZlibStream"/>, except that
- /// <c>ZlibStream</c> adds the <see href="http://www.ietf.org/rfc/rfc1950.txt">RFC
- /// 1950 - ZLIB</see> framing bytes to a compressed stream when compressing, or
- /// expects the RFC1950 framing bytes when decompressing. The <c>DeflateStream</c>
- /// does not.
- /// </para>
- ///
- /// </remarks>
- ///
- /// <seealso cref="ZlibStream" />
- /// <seealso cref="GZipStream" />
- public class DeflateStream : System.IO.Stream
- {
- internal ZlibBaseStream _baseStream;
- internal System.IO.Stream _innerStream;
- bool _disposed;
-
- /// <summary>
- /// Create a DeflateStream using the specified CompressionMode.
- /// </summary>
- ///
- /// <remarks>
- /// When mode is <c>CompressionMode.Compress</c>, the DeflateStream will use
- /// the default compression level. The "captive" stream will be closed when
- /// the DeflateStream is closed.
- /// </remarks>
- ///
- /// <example>
- /// This example uses a DeflateStream to compress data from a file, and writes
- /// the compressed data to another file.
- /// <code>
- /// using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
- /// {
- /// using (var raw = System.IO.File.Create(fileToCompress + ".deflated"))
- /// {
- /// using (Stream compressor = new DeflateStream(raw, CompressionMode.Compress))
- /// {
- /// byte[] buffer = new byte[WORKING_BUFFER_SIZE];
- /// int n;
- /// while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
- /// {
- /// compressor.Write(buffer, 0, n);
- /// }
- /// }
- /// }
- /// }
- /// </code>
- ///
- /// <code lang="VB">
- /// Using input As Stream = File.OpenRead(fileToCompress)
- /// Using raw As FileStream = File.Create(fileToCompress &amp; ".deflated")
- /// Using compressor As Stream = New DeflateStream(raw, CompressionMode.Compress)
- /// Dim buffer As Byte() = New Byte(4096) {}
- /// Dim n As Integer = -1
- /// Do While (n &lt;&gt; 0)
- /// If (n &gt; 0) Then
- /// compressor.Write(buffer, 0, n)
- /// End If
- /// n = input.Read(buffer, 0, buffer.Length)
- /// Loop
- /// End Using
- /// End Using
- /// End Using
- /// </code>
- /// </example>
- /// <param name="stream">The stream which will be read or written.</param>
- /// <param name="mode">Indicates whether the DeflateStream will compress or decompress.</param>
- public DeflateStream(System.IO.Stream stream, CompressionMode mode)
- : this(stream, mode, CompressionLevel.Default, false)
- {
- }
-
- /// <summary>
- /// Create a DeflateStream using the specified CompressionMode and the specified CompressionLevel.
- /// </summary>
- ///
- /// <remarks>
- ///
- /// <para>
- /// When mode is <c>CompressionMode.Decompress</c>, the level parameter is
- /// ignored. The "captive" stream will be closed when the DeflateStream is
- /// closed.
- /// </para>
- ///
- /// </remarks>
- ///
- /// <example>
- ///
- /// This example uses a DeflateStream to compress data from a file, and writes
- /// the compressed data to another file.
- ///
- /// <code>
- /// using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
- /// {
- /// using (var raw = System.IO.File.Create(fileToCompress + ".deflated"))
- /// {
- /// using (Stream compressor = new DeflateStream(raw,
- /// CompressionMode.Compress,
- /// CompressionLevel.BestCompression))
- /// {
- /// byte[] buffer = new byte[WORKING_BUFFER_SIZE];
- /// int n= -1;
- /// while (n != 0)
- /// {
- /// if (n &gt; 0)
- /// compressor.Write(buffer, 0, n);
- /// n= input.Read(buffer, 0, buffer.Length);
- /// }
- /// }
- /// }
- /// }
- /// </code>
- ///
- /// <code lang="VB">
- /// Using input As Stream = File.OpenRead(fileToCompress)
- /// Using raw As FileStream = File.Create(fileToCompress &amp; ".deflated")
- /// Using compressor As Stream = New DeflateStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression)
- /// Dim buffer As Byte() = New Byte(4096) {}
- /// Dim n As Integer = -1
- /// Do While (n &lt;&gt; 0)
- /// If (n &gt; 0) Then
- /// compressor.Write(buffer, 0, n)
- /// End If
- /// n = input.Read(buffer, 0, buffer.Length)
- /// Loop
- /// End Using
- /// End Using
- /// End Using
- /// </code>
- /// </example>
- /// <param name="stream">The stream to be read or written while deflating or inflating.</param>
- /// <param name="mode">Indicates whether the <c>DeflateStream</c> will compress or decompress.</param>
- /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
- public DeflateStream(System.IO.Stream stream, CompressionMode mode, CompressionLevel level)
- : this(stream, mode, level, false)
- {
- }
-
- /// <summary>
- /// Create a <c>DeflateStream</c> using the specified
- /// <c>CompressionMode</c>, and explicitly specify whether the
- /// stream should be left open after Deflation or Inflation.
- /// </summary>
- ///
- /// <remarks>
- ///
- /// <para>
- /// This constructor allows the application to request that the captive stream
- /// remain open after the deflation or inflation occurs. By default, after
- /// <c>Close()</c> is called on the stream, the captive stream is also
- /// closed. In some cases this is not desired, for example if the stream is a
- /// memory stream that will be re-read after compression. Specify true for
- /// the <paramref name="leaveOpen"/> parameter to leave the stream open.
- /// </para>
- ///
- /// <para>
- /// The <c>DeflateStream</c> will use the default compression level.
- /// </para>
- ///
- /// <para>
- /// See the other overloads of this constructor for example code.
- /// </para>
- /// </remarks>
- ///
- /// <param name="stream">
- /// The stream which will be read or written. This is called the
- /// "captive" stream in other places in this documentation.
- /// </param>
- ///
- /// <param name="mode">
- /// Indicates whether the <c>DeflateStream</c> will compress or decompress.
- /// </param>
- ///
- /// <param name="leaveOpen">true if the application would like the stream to
- /// remain open after inflation/deflation.</param>
- public DeflateStream(System.IO.Stream stream, CompressionMode mode, bool leaveOpen)
- : this(stream, mode, CompressionLevel.Default, leaveOpen)
- {
- }
-
- /// <summary>
- /// Create a <c>DeflateStream</c> using the specified <c>CompressionMode</c>
- /// and the specified <c>CompressionLevel</c>, and explicitly specify whether
- /// the stream should be left open after Deflation or Inflation.
- /// </summary>
- ///
- /// <remarks>
- ///
- /// <para>
- /// When mode is <c>CompressionMode.Decompress</c>, the level parameter is ignored.
- /// </para>
- ///
- /// <para>
- /// This constructor allows the application to request that the captive stream
- /// remain open after the deflation or inflation occurs. By default, after
- /// <c>Close()</c> is called on the stream, the captive stream is also
- /// closed. In some cases this is not desired, for example if the stream is a
- /// <see cref="System.IO.MemoryStream"/> that will be re-read after
- /// compression. Specify true for the <paramref name="leaveOpen"/> parameter
- /// to leave the stream open.
- /// </para>
- ///
- /// </remarks>
- ///
- /// <example>
- ///
- /// This example shows how to use a <c>DeflateStream</c> to compress data from
- /// a file, and store the compressed data into another file.
- ///
- /// <code>
- /// using (var output = System.IO.File.Create(fileToCompress + ".deflated"))
- /// {
- /// using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
- /// {
- /// using (Stream compressor = new DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, true))
- /// {
- /// byte[] buffer = new byte[WORKING_BUFFER_SIZE];
- /// int n= -1;
- /// while (n != 0)
- /// {
- /// if (n &gt; 0)
- /// compressor.Write(buffer, 0, n);
- /// n= input.Read(buffer, 0, buffer.Length);
- /// }
- /// }
- /// }
- /// // can write additional data to the output stream here
- /// }
- /// </code>
- ///
- /// <code lang="VB">
- /// Using output As FileStream = File.Create(fileToCompress &amp; ".deflated")
- /// Using input As Stream = File.OpenRead(fileToCompress)
- /// Using compressor As Stream = New DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, True)
- /// Dim buffer As Byte() = New Byte(4096) {}
- /// Dim n As Integer = -1
- /// Do While (n &lt;&gt; 0)
- /// If (n &gt; 0) Then
- /// compressor.Write(buffer, 0, n)
- /// End If
- /// n = input.Read(buffer, 0, buffer.Length)
- /// Loop
- /// End Using
- /// End Using
- /// ' can write additional data to the output stream here.
- /// End Using
- /// </code>
- /// </example>
- /// <param name="stream">The stream which will be read or written.</param>
- /// <param name="mode">Indicates whether the DeflateStream will compress or decompress.</param>
- /// <param name="leaveOpen">true if the application would like the stream to remain open after inflation/deflation.</param>
- /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
- public DeflateStream(System.IO.Stream stream, CompressionMode mode, CompressionLevel level, bool leaveOpen)
- {
- _innerStream = stream;
- _baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.DEFLATE, leaveOpen);
- }
-
- #region Zlib properties
-
- /// <summary>
- /// This property sets the flush behavior on the stream.
- /// </summary>
- /// <remarks> See the ZLIB documentation for the meaning of the flush behavior.
- /// </remarks>
- virtual public FlushType FlushMode
- {
- get { return (this._baseStream._flushMode); }
- set
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- this._baseStream._flushMode = value;
- }
- }
-
- /// <summary>
- /// The size of the working buffer for the compression codec.
- /// </summary>
- ///
- /// <remarks>
- /// <para>
- /// The working buffer is used for all stream operations. The default size is
- /// 1024 bytes. The minimum size is 128 bytes. You may get better performance
- /// with a larger buffer. Then again, you might not. You would have to test
- /// it.
- /// </para>
- ///
- /// <para>
- /// Set this before the first call to <c>Read()</c> or <c>Write()</c> on the
- /// stream. If you try to set it afterwards, it will throw.
- /// </para>
- /// </remarks>
- public int BufferSize
- {
- get
- {
- return this._baseStream._bufferSize;
- }
- set
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- if (this._baseStream._workingBuffer != null)
- throw new ZlibException("The working buffer is already set.");
- if (value < ZlibConstants.WorkingBufferSizeMin)
- throw new ZlibException(String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value, ZlibConstants.WorkingBufferSizeMin));
- this._baseStream._bufferSize = value;
- }
- }
-
- /// <summary>
- /// The ZLIB strategy to be used during compression.
- /// </summary>
- ///
- /// <remarks>
- /// By tweaking this parameter, you may be able to optimize the compression for
- /// data with particular characteristics.
- /// </remarks>
- public CompressionStrategy Strategy
- {
- get
- {
- return this._baseStream.Strategy;
- }
- set
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- this._baseStream.Strategy = value;
- }
- }
-
- /// <summary> Returns the total number of bytes input so far.</summary>
- virtual public long TotalIn
- {
- get
- {
- return this._baseStream._z.TotalBytesIn;
- }
- }
-
- /// <summary> Returns the total number of bytes output so far.</summary>
- virtual public long TotalOut
- {
- get
- {
- return this._baseStream._z.TotalBytesOut;
- }
- }
-
- #endregion
-
- #region System.IO.Stream methods
- /// <summary>
- /// Dispose the stream.
- /// </summary>
- /// <remarks>
- /// This may or may not result in a <c>Close()</c> call on the captive stream.
- /// See the constructors that have a <c>leaveOpen</c> parameter for more information.
- /// </remarks>
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (!_disposed)
- {
- if (disposing && (this._baseStream != null))
- this._baseStream.Close();
- _disposed = true;
- }
- }
- finally
- {
- base.Dispose(disposing);
- }
- }
-
-
-
- /// <summary>
- /// Indicates whether the stream can be read.
- /// </summary>
- /// <remarks>
- /// The return value depends on whether the captive stream supports reading.
- /// </remarks>
- public override bool CanRead
- {
- get
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- return _baseStream._stream.CanRead;
- }
- }
-
- /// <summary>
- /// Indicates whether the stream supports Seek operations.
- /// </summary>
- /// <remarks>
- /// Always returns false.
- /// </remarks>
- public override bool CanSeek
- {
- get { return false; }
- }
-
-
- /// <summary>
- /// Indicates whether the stream can be written.
- /// </summary>
- /// <remarks>
- /// The return value depends on whether the captive stream supports writing.
- /// </remarks>
- public override bool CanWrite
- {
- get
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- return _baseStream._stream.CanWrite;
- }
- }
-
- /// <summary>
- /// Flush the stream.
- /// </summary>
- public override void Flush()
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- _baseStream.Flush();
- }
-
- /// <summary>
- /// Reading this property always throws a <see cref="NotImplementedException"/>.
- /// </summary>
- public override long Length
- {
- get { throw new NotImplementedException(); }
- }
-
- /// <summary>
- /// The position of the stream pointer.
- /// </summary>
- ///
- /// <remarks>
- /// Setting this property always throws a <see
- /// cref="NotImplementedException"/>. Reading will return the total bytes
- /// written out, if used in writing, or the total bytes read in, if used in
- /// reading. The count may refer to compressed bytes or uncompressed bytes,
- /// depending on how you've used the stream.
- /// </remarks>
- public override long Position
- {
- get
- {
- if (this._baseStream._streamMode == Ionic.Zlib.ZlibBaseStream.StreamMode.Writer)
- return this._baseStream._z.TotalBytesOut;
- if (this._baseStream._streamMode == Ionic.Zlib.ZlibBaseStream.StreamMode.Reader)
- return this._baseStream._z.TotalBytesIn;
- return 0;
- }
- set { throw new NotImplementedException(); }
- }
-
- /// <summary>
- /// Read data from the stream.
- /// </summary>
- /// <remarks>
- ///
- /// <para>
- /// If you wish to use the <c>DeflateStream</c> to compress data while
- /// reading, you can create a <c>DeflateStream</c> with
- /// <c>CompressionMode.Compress</c>, providing an uncompressed data stream.
- /// Then call Read() on that <c>DeflateStream</c>, and the data read will be
- /// compressed as you read. If you wish to use the <c>DeflateStream</c> to
- /// decompress data while reading, you can create a <c>DeflateStream</c> with
- /// <c>CompressionMode.Decompress</c>, providing a readable compressed data
- /// stream. Then call Read() on that <c>DeflateStream</c>, and the data read
- /// will be decompressed as you read.
- /// </para>
- ///
- /// <para>
- /// A <c>DeflateStream</c> can be used for <c>Read()</c> or <c>Write()</c>, but not both.
- /// </para>
- ///
- /// </remarks>
- /// <param name="buffer">The buffer into which the read data should be placed.</param>
- /// <param name="offset">the offset within that data array to put the first byte read.</param>
- /// <param name="count">the number of bytes to read.</param>
- /// <returns>the number of bytes actually read</returns>
- public override int Read(byte[] buffer, int offset, int count)
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- return _baseStream.Read(buffer, offset, count);
- }
-
-
- /// <summary>
- /// Calling this method always throws a <see cref="NotImplementedException"/>.
- /// </summary>
- /// <param name="offset">this is irrelevant, since it will always throw!</param>
- /// <param name="origin">this is irrelevant, since it will always throw!</param>
- /// <returns>irrelevant!</returns>
- public override long Seek(long offset, System.IO.SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Calling this method always throws a <see cref="NotImplementedException"/>.
- /// </summary>
- /// <param name="value">this is irrelevant, since it will always throw!</param>
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Write data to the stream.
- /// </summary>
- /// <remarks>
- ///
- /// <para>
- /// If you wish to use the <c>DeflateStream</c> to compress data while
- /// writing, you can create a <c>DeflateStream</c> with
- /// <c>CompressionMode.Compress</c>, and a writable output stream. Then call
- /// <c>Write()</c> on that <c>DeflateStream</c>, providing uncompressed data
- /// as input. The data sent to the output stream will be the compressed form
- /// of the data written. If you wish to use the <c>DeflateStream</c> to
- /// decompress data while writing, you can create a <c>DeflateStream</c> with
- /// <c>CompressionMode.Decompress</c>, and a writable output stream. Then
- /// call <c>Write()</c> on that stream, providing previously compressed
- /// data. The data sent to the output stream will be the decompressed form of
- /// the data written.
- /// </para>
- ///
- /// <para>
- /// A <c>DeflateStream</c> can be used for <c>Read()</c> or <c>Write()</c>,
- /// but not both.
- /// </para>
- ///
- /// </remarks>
- ///
- /// <param name="buffer">The buffer holding data to write to the stream.</param>
- /// <param name="offset">the offset within that data array to find the first byte to write.</param>
- /// <param name="count">the number of bytes to write.</param>
- public override void Write(byte[] buffer, int offset, int count)
- {
- if (_disposed) throw new ObjectDisposedException("DeflateStream");
- _baseStream.Write(buffer, offset, count);
- }
- #endregion
-
-
-
-
- /// <summary>
- /// Compress a string into a byte array using DEFLATE (RFC 1951).
- /// </summary>
- ///
- /// <remarks>
- /// Uncompress it with <see cref="DeflateStream.UncompressString(byte[])"/>.
- /// </remarks>
- ///
- /// <seealso cref="DeflateStream.UncompressString(byte[])">DeflateStream.UncompressString(byte[])</seealso>
- /// <seealso cref="DeflateStream.CompressBuffer(byte[])">DeflateStream.CompressBuffer(byte[])</seealso>
- /// <seealso cref="GZipStream.CompressString(string)">GZipStream.CompressString(string)</seealso>
- /// <seealso cref="ZlibStream.CompressString(string)">ZlibStream.CompressString(string)</seealso>
- ///
- /// <param name="s">
- /// A string to compress. The string will first be encoded
- /// using UTF8, then compressed.
- /// </param>
- ///
- /// <returns>The string in compressed form</returns>
- public static byte[] CompressString(String s)
- {
- using (var ms = new System.IO.MemoryStream())
- {
- System.IO.Stream compressor =
- new DeflateStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
- ZlibBaseStream.CompressString(s, compressor);
- return ms.ToArray();
- }
- }
-
-
- /// <summary>
- /// Compress a byte array into a new byte array using DEFLATE.
- /// </summary>
- ///
- /// <remarks>
- /// Uncompress it with <see cref="DeflateStream.UncompressBuffer(byte[])"/>.
- /// </remarks>
- ///
- /// <seealso cref="DeflateStream.CompressString(string)">DeflateStream.CompressString(string)</seealso>
- /// <seealso cref="DeflateStream.UncompressBuffer(byte[])">DeflateStream.UncompressBuffer(byte[])</seealso>
- /// <seealso cref="GZipStream.CompressBuffer(byte[])">GZipStream.CompressBuffer(byte[])</seealso>
- /// <seealso cref="ZlibStream.CompressBuffer(byte[])">ZlibStream.CompressBuffer(byte[])</seealso>
- ///
- /// <param name="b">
- /// A buffer to compress.
- /// </param>
- ///
- /// <returns>The data in compressed form</returns>
- public static byte[] CompressBuffer(byte[] b)
- {
- using (var ms = new System.IO.MemoryStream())
- {
- System.IO.Stream compressor =
- new DeflateStream( ms, CompressionMode.Compress, CompressionLevel.BestCompression );
-
- ZlibBaseStream.CompressBuffer(b, compressor);
- return ms.ToArray();
- }
- }
-
-
- /// <summary>
- /// Uncompress a DEFLATE'd byte array into a single string.
- /// </summary>
- ///
- /// <seealso cref="DeflateStream.CompressString(String)">DeflateStream.CompressString(String)</seealso>
- /// <seealso cref="DeflateStream.UncompressBuffer(byte[])">DeflateStream.UncompressBuffer(byte[])</seealso>
- /// <seealso cref="GZipStream.UncompressString(byte[])">GZipStream.UncompressString(byte[])</seealso>
- /// <seealso cref="ZlibStream.UncompressString(byte[])">ZlibStream.UncompressString(byte[])</seealso>
- ///
- /// <param name="compressed">
- /// A buffer containing DEFLATE-compressed data.
- /// </param>
- ///
- /// <returns>The uncompressed string</returns>
- public static String UncompressString(byte[] compressed)
- {
- using (var input = new System.IO.MemoryStream(compressed))
- {
- System.IO.Stream decompressor =
- new DeflateStream(input, CompressionMode.Decompress);
-
- return ZlibBaseStream.UncompressString(compressed, decompressor);
- }
- }
-
-
- /// <summary>
- /// Uncompress a DEFLATE'd byte array into a byte array.
- /// </summary>
- ///
- /// <seealso cref="DeflateStream.CompressBuffer(byte[])">DeflateStream.CompressBuffer(byte[])</seealso>
- /// <seealso cref="DeflateStream.UncompressString(byte[])">DeflateStream.UncompressString(byte[])</seealso>
- /// <seealso cref="GZipStream.UncompressBuffer(byte[])">GZipStream.UncompressBuffer(byte[])</seealso>
- /// <seealso cref="ZlibStream.UncompressBuffer(byte[])">ZlibStream.UncompressBuffer(byte[])</seealso>
- ///
- /// <param name="compressed">
- /// A buffer containing data that has been compressed with DEFLATE.
- /// </param>
- ///
- /// <returns>The data in uncompressed form</returns>
- public static byte[] UncompressBuffer(byte[] compressed)
- {
- using (var input = new System.IO.MemoryStream(compressed))
- {
- System.IO.Stream decompressor =
- new DeflateStream( input, CompressionMode.Decompress );
-
- return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
- }
- }
-
- }
-
-}
-
+// DeflateStream.cs
+// ------------------------------------------------------------------
+//
+// Copyright (c) 2009-2010 Dino Chiesa.
+// All rights reserved.
+//
+// This code module is part of DotNetZip, a zipfile class library.
+//
+// ------------------------------------------------------------------
+//
+// This code is licensed under the Microsoft Public License.
+// See the file License.txt for the license details.
+// More info on: http://dotnetzip.codeplex.com
+//
+// ------------------------------------------------------------------
+//
+// last saved (in emacs):
+// Time-stamp: <2010-February-05 08:49:04>
+//
+// ------------------------------------------------------------------
+//
+// This module defines the DeflateStream class, which can be used as a replacement for
+// the System.IO.Compression.DeflateStream class in the .NET BCL.
+//
+// ------------------------------------------------------------------
+
+
+using System;
+
+namespace Ionic.Zlib
+{
+ /// <summary>
+ /// A class for compressing and decompressing streams using the Deflate algorithm.
+ /// </summary>
+ ///
+ /// <remarks>
+ ///
+ /// <para>
+ /// The DeflateStream is a <see
+ /// href="http://en.wikipedia.org/wiki/Decorator_pattern">Decorator</see> on a <see
+ /// cref="System.IO.Stream"/>. It adds DEFLATE compression or decompression to any
+ /// stream.
+ /// </para>
+ ///
+ /// <para>
+ /// Using this stream, applications can compress or decompress data via stream
+ /// <c>Read</c> and <c>Write</c> operations. Either compresssion or decompression
+ /// can occur through either reading or writing. The compression format used is
+ /// DEFLATE, which is documented in <see
+ /// href="http://www.ietf.org/rfc/rfc1951.txt">IETF RFC 1951</see>, "DEFLATE
+ /// Compressed Data Format Specification version 1.3.".
+ /// </para>
+ ///
+ /// <para>
+ /// This class is similar to <see cref="ZlibStream"/>, except that
+ /// <c>ZlibStream</c> adds the <see href="http://www.ietf.org/rfc/rfc1950.txt">RFC
+ /// 1950 - ZLIB</see> framing bytes to a compressed stream when compressing, or
+ /// expects the RFC1950 framing bytes when decompressing. The <c>DeflateStream</c>
+ /// does not.
+ /// </para>
+ ///
+ /// </remarks>
+ ///
+ /// <seealso cref="ZlibStream" />
+ /// <seealso cref="GZipStream" />
+ public class DeflateStream : System.IO.Stream
+ {
+ internal ZlibBaseStream _baseStream;
+ internal System.IO.Stream _innerStream;
+ bool _disposed;
+
+ /// <summary>
+ /// Create a DeflateStream using the specified CompressionMode.
+ /// </summary>
+ ///
+ /// <remarks>
+ /// When mode is <c>CompressionMode.Compress</c>, the DeflateStream will use
+ /// the default compression level. The "captive" stream will be closed when
+ /// the DeflateStream is closed.
+ /// </remarks>
+ ///
+ /// <example>
+ /// This example uses a DeflateStream to compress data from a file, and writes
+ /// the compressed data to another file.
+ /// <code>
+ /// using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ /// {
+ /// using (var raw = System.IO.File.Create(fileToCompress + ".deflated"))
+ /// {
+ /// using (Stream compressor = new DeflateStream(raw, CompressionMode.Compress))
+ /// {
+ /// byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ /// int n;
+ /// while ((n= input.Read(buffer, 0, buffer.Length)) != 0)
+ /// {
+ /// compressor.Write(buffer, 0, n);
+ /// }
+ /// }
+ /// }
+ /// }
+ /// </code>
+ ///
+ /// <code lang="VB">
+ /// Using input As Stream = File.OpenRead(fileToCompress)
+ /// Using raw As FileStream = File.Create(fileToCompress &amp; ".deflated")
+ /// Using compressor As Stream = New DeflateStream(raw, CompressionMode.Compress)
+ /// Dim buffer As Byte() = New Byte(4096) {}
+ /// Dim n As Integer = -1
+ /// Do While (n &lt;&gt; 0)
+ /// If (n &gt; 0) Then
+ /// compressor.Write(buffer, 0, n)
+ /// End If
+ /// n = input.Read(buffer, 0, buffer.Length)
+ /// Loop
+ /// End Using
+ /// End Using
+ /// End Using
+ /// </code>
+ /// </example>
+ /// <param name="stream">The stream which will be read or written.</param>
+ /// <param name="mode">Indicates whether the DeflateStream will compress or decompress.</param>
+ public DeflateStream(System.IO.Stream stream, CompressionMode mode)
+ : this(stream, mode, CompressionLevel.Default, false)
+ {
+ }
+
+ /// <summary>
+ /// Create a DeflateStream using the specified CompressionMode and the specified CompressionLevel.
+ /// </summary>
+ ///
+ /// <remarks>
+ ///
+ /// <para>
+ /// When mode is <c>CompressionMode.Decompress</c>, the level parameter is
+ /// ignored. The "captive" stream will be closed when the DeflateStream is
+ /// closed.
+ /// </para>
+ ///
+ /// </remarks>
+ ///
+ /// <example>
+ ///
+ /// This example uses a DeflateStream to compress data from a file, and writes
+ /// the compressed data to another file.
+ ///
+ /// <code>
+ /// using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ /// {
+ /// using (var raw = System.IO.File.Create(fileToCompress + ".deflated"))
+ /// {
+ /// using (Stream compressor = new DeflateStream(raw,
+ /// CompressionMode.Compress,
+ /// CompressionLevel.BestCompression))
+ /// {
+ /// byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ /// int n= -1;
+ /// while (n != 0)
+ /// {
+ /// if (n &gt; 0)
+ /// compressor.Write(buffer, 0, n);
+ /// n= input.Read(buffer, 0, buffer.Length);
+ /// }
+ /// }
+ /// }
+ /// }
+ /// </code>
+ ///
+ /// <code lang="VB">
+ /// Using input As Stream = File.OpenRead(fileToCompress)
+ /// Using raw As FileStream = File.Create(fileToCompress &amp; ".deflated")
+ /// Using compressor As Stream = New DeflateStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression)
+ /// Dim buffer As Byte() = New Byte(4096) {}
+ /// Dim n As Integer = -1
+ /// Do While (n &lt;&gt; 0)
+ /// If (n &gt; 0) Then
+ /// compressor.Write(buffer, 0, n)
+ /// End If
+ /// n = input.Read(buffer, 0, buffer.Length)
+ /// Loop
+ /// End Using
+ /// End Using
+ /// End Using
+ /// </code>
+ /// </example>
+ /// <param name="stream">The stream to be read or written while deflating or inflating.</param>
+ /// <param name="mode">Indicates whether the <c>DeflateStream</c> will compress or decompress.</param>
+ /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
+ public DeflateStream(System.IO.Stream stream, CompressionMode mode, CompressionLevel level)
+ : this(stream, mode, level, false)
+ {
+ }
+
+ /// <summary>
+ /// Create a <c>DeflateStream</c> using the specified
+ /// <c>CompressionMode</c>, and explicitly specify whether the
+ /// stream should be left open after Deflation or Inflation.
+ /// </summary>
+ ///
+ /// <remarks>
+ ///
+ /// <para>
+ /// This constructor allows the application to request that the captive stream
+ /// remain open after the deflation or inflation occurs. By default, after
+ /// <c>Close()</c> is called on the stream, the captive stream is also
+ /// closed. In some cases this is not desired, for example if the stream is a
+ /// memory stream that will be re-read after compression. Specify true for
+ /// the <paramref name="leaveOpen"/> parameter to leave the stream open.
+ /// </para>
+ ///
+ /// <para>
+ /// The <c>DeflateStream</c> will use the default compression level.
+ /// </para>
+ ///
+ /// <para>
+ /// See the other overloads of this constructor for example code.
+ /// </para>
+ /// </remarks>
+ ///
+ /// <param name="stream">
+ /// The stream which will be read or written. This is called the
+ /// "captive" stream in other places in this documentation.
+ /// </param>
+ ///
+ /// <param name="mode">
+ /// Indicates whether the <c>DeflateStream</c> will compress or decompress.
+ /// </param>
+ ///
+ /// <param name="leaveOpen">true if the application would like the stream to
+ /// remain open after inflation/deflation.</param>
+ public DeflateStream(System.IO.Stream stream, CompressionMode mode, bool leaveOpen)
+ : this(stream, mode, CompressionLevel.Default, leaveOpen)
+ {
+ }
+
+ /// <summary>
+ /// Create a <c>DeflateStream</c> using the specified <c>CompressionMode</c>
+ /// and the specified <c>CompressionLevel</c>, and explicitly specify whether
+ /// the stream should be left open after Deflation or Inflation.
+ /// </summary>
+ ///
+ /// <remarks>
+ ///
+ /// <para>
+ /// When mode is <c>CompressionMode.Decompress</c>, the level parameter is ignored.
+ /// </para>
+ ///
+ /// <para>
+ /// This constructor allows the application to request that the captive stream
+ /// remain open after the deflation or inflation occurs. By default, after
+ /// <c>Close()</c> is called on the stream, the captive stream is also
+ /// closed. In some cases this is not desired, for example if the stream is a
+ /// <see cref="System.IO.MemoryStream"/> that will be re-read after
+ /// compression. Specify true for the <paramref name="leaveOpen"/> parameter
+ /// to leave the stream open.
+ /// </para>
+ ///
+ /// </remarks>
+ ///
+ /// <example>
+ ///
+ /// This example shows how to use a <c>DeflateStream</c> to compress data from
+ /// a file, and store the compressed data into another file.
+ ///
+ /// <code>
+ /// using (var output = System.IO.File.Create(fileToCompress + ".deflated"))
+ /// {
+ /// using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress))
+ /// {
+ /// using (Stream compressor = new DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, true))
+ /// {
+ /// byte[] buffer = new byte[WORKING_BUFFER_SIZE];
+ /// int n= -1;
+ /// while (n != 0)
+ /// {
+ /// if (n &gt; 0)
+ /// compressor.Write(buffer, 0, n);
+ /// n= input.Read(buffer, 0, buffer.Length);
+ /// }
+ /// }
+ /// }
+ /// // can write additional data to the output stream here
+ /// }
+ /// </code>
+ ///
+ /// <code lang="VB">
+ /// Using output As FileStream = File.Create(fileToCompress &amp; ".deflated")
+ /// Using input As Stream = File.OpenRead(fileToCompress)
+ /// Using compressor As Stream = New DeflateStream(output, CompressionMode.Compress, CompressionLevel.BestCompression, True)
+ /// Dim buffer As Byte() = New Byte(4096) {}
+ /// Dim n As Integer = -1
+ /// Do While (n &lt;&gt; 0)
+ /// If (n &gt; 0) Then
+ /// compressor.Write(buffer, 0, n)
+ /// End If
+ /// n = input.Read(buffer, 0, buffer.Length)
+ /// Loop
+ /// End Using
+ /// End Using
+ /// ' can write additional data to the output stream here.
+ /// End Using
+ /// </code>
+ /// </example>
+ /// <param name="stream">The stream which will be read or written.</param>
+ /// <param name="mode">Indicates whether the DeflateStream will compress or decompress.</param>
+ /// <param name="leaveOpen">true if the application would like the stream to remain open after inflation/deflation.</param>
+ /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
+ public DeflateStream(System.IO.Stream stream, CompressionMode mode, CompressionLevel level, bool leaveOpen)
+ {
+ _innerStream = stream;
+ _baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.DEFLATE, leaveOpen);
+ }
+
+ #region Zlib properties
+
+ /// <summary>
+ /// This property sets the flush behavior on the stream.
+ /// </summary>
+ /// <remarks> See the ZLIB documentation for the meaning of the flush behavior.
+ /// </remarks>
+ virtual public FlushType FlushMode
+ {
+ get { return (this._baseStream._flushMode); }
+ set
+ {
+ if (_disposed) throw new ObjectDisposedException("DeflateStream");
+ this._baseStream._flushMode = value;
+ }
+ }
+
+ /// <summary>
+ /// The size of the working buffer for the compression codec.
+ /// </summary>
+ ///
+ /// <remarks>
+ /// <para>
+ /// The working buffer is used for all stream operations. The default size is
+ /// 1024 bytes. The minimum size is 128 bytes. You may get better performance
+ /// with a larger buffer. Then again, you might not. You would have to test
+ /// it.
+ /// </para>
+ ///
+ /// <para>
+ /// Set this before the first call to <c>Read()</c> or <c>Write()</c> on the
+ /// stream. If you try to set it afterwards, it will throw.
+ /// </para>
+ /// </remarks>
+ public int BufferSize
+ {
+ get
+ {
+ return this._baseStream._bufferSize;
+ }
+ set
+ {
+ if (_disposed) throw new ObjectDisposedException("DeflateStream");
+ if (this._baseStream._workingBuffer != null)
+ throw new ZlibException("The working buffer is already set.");
+ if (value < ZlibConstants.WorkingBufferSizeMin)
+ throw new ZlibException(String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value, ZlibConstants.WorkingBufferSizeMin));
+ this._baseStream._bufferSize = value;
+ }
+ }
+
+ /// <summary>
+ /// The ZLIB strategy to be used during compression.
+ /// </summary>
+ ///
+ /// <remarks>
+ /// By tweaking this parameter, you may be able to optimize the compression for
+ /// data with particular characteristics.
+ /// </remarks>
+ public CompressionStrategy Strategy
+ {
+ get
+ {
+ return this._baseStream.Strategy;
+ }
+ set
+ {
+ if (_disposed) throw new ObjectDisposedException("DeflateStream");
+ this._baseStream.Strategy = value;
+ }
+ }
+
+ /// <summary> Returns the total number of bytes input so far.</summary>
+ virtual public long TotalIn
+ {
+ get
+ {