The Labs \ Source Viewer \ SSCLI \ System.IO.Compression \ Deflater

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // zlib.h -- interface of the 'zlib' general purpose compression library
  15. // version 1.2.1, November 17th, 2003
  16. //
  17. // Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
  18. //
  19. // This software is provided 'as-is', without any express or implied
  20. // warranty. In no event will the authors be held liable for any damages
  21. // arising from the use of this software.
  22. //
  23. // Permission is granted to anyone to use this software for any purpose,
  24. // including commercial applications, and to alter it and redistribute it
  25. // freely, subject to the following restrictions:
  26. //
  27. // 1. The origin of this software must not be misrepresented; you must not
  28. // claim that you wrote the original software. If you use this software
  29. // in a product, an acknowledgment in the product documentation would be
  30. // appreciated but is not required.
  31. // 2. Altered source versions must be plainly marked as such, and must not be
  32. // misrepresented as being the original software.
  33. // 3. This notice may not be removed or altered from any source distribution.
  34. //
  35. //
  36. // ==--==
  37. // Compression engine
  38. namespace System.IO.Compression
  39. {
  40.     using System;
  41.     using System.Diagnostics;
  42.    
  43.     internal class Deflater
  44.     {
  45.         private FastEncoder encoder;
  46.        
  47.         public Deflater(bool doGZip)
  48.         {
  49.             encoder = new FastEncoder(doGZip);
  50.         }
  51.        
  52.         public void SetInput(byte[] input, int startIndex, int count)
  53.         {
  54.             encoder.SetInput(input, startIndex, count);
  55.         }
  56.        
  57.         public int GetDeflateOutput(byte[] output)
  58.         {
  59.             Debug.Assert(output != null, "Can't pass in a null output buffer!");
  60.             return encoder.GetCompressedOutput(output);
  61.         }
  62.        
  63.         public bool NeedsInput()
  64.         {
  65.             return encoder.NeedsInput();
  66.         }
  67.        
  68.         public int Finish(byte[] output)
  69.         {
  70.             Debug.Assert(output != null, "Can't pass in a null output buffer!");
  71.             return encoder.Finish(output);
  72.         }
  73.     }
  74. }

Developer Fusion