BZip2.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // BZip2.cs
  2. // Copyright (C) 2001 Mike Krueger
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. //
  18. // Linking this library statically or dynamically with other modules is
  19. // making a combined work based on this library. Thus, the terms and
  20. // conditions of the GNU General Public License cover the whole
  21. // combination.
  22. //
  23. // As a special exception, the copyright holders of this library give you
  24. // permission to link this library with independent modules to produce an
  25. // executable, regardless of the license terms of these independent
  26. // modules, and to copy and distribute the resulting executable under
  27. // terms of your choice, provided that you also meet, for each linked
  28. // independent module, the terms and conditions of the license of that
  29. // module. An independent module is a module which is not derived from
  30. // or based on this library. If you modify this library, you may extend
  31. // this exception to your version of the library, but you are not
  32. // obligated to do so. If you do not wish to do so, delete this
  33. // exception statement from your version.
  34. using System;
  35. using System.IO;
  36. namespace ICSharpCode.SharpZipLib.BZip2
  37. {
  38. /// <summary>
  39. /// Does all the compress and decompress pre-operation stuff.
  40. /// Sets up the streams and file header characters.
  41. /// Uses multiply overloaded methods to call for the compress/decompress.
  42. /// </summary>
  43. public sealed class BZip2
  44. {
  45. public static void Decompress(Stream instream, Stream outstream)
  46. {
  47. System.IO.Stream bos = outstream;
  48. System.IO.Stream bis = instream;
  49. BZip2InputStream bzis = new BZip2InputStream(bis);
  50. int ch = bzis.ReadByte();
  51. while (ch != -1) {
  52. bos.WriteByte((byte)ch);
  53. ch = bzis.ReadByte();
  54. }
  55. bos.Flush();
  56. }
  57. public static void Compress(Stream instream, Stream outstream, int blockSize)
  58. {
  59. System.IO.Stream bos = outstream;
  60. System.IO.Stream bis = instream;
  61. int ch = bis.ReadByte();
  62. BZip2OutputStream bzos = new BZip2OutputStream(bos, blockSize);
  63. while(ch != -1) {
  64. bzos.WriteByte((byte)ch);
  65. ch = bis.ReadByte();
  66. }
  67. bis.Close();
  68. bzos.Close();
  69. }
  70. }
  71. }
  72. /* derived from a file which contained this license :
  73. * Copyright (c) 1999-2001 Keiron Liddle, Aftex Software
  74. *
  75. * This library is free software; you can redistribute it and/or
  76. * modify it under the terms of the GNU Lesser General Public
  77. * License as published by the Free Software Foundation; either
  78. * version 2.1 of the License, or (at your option) any later version.
  79. *
  80. * This library is distributed in the hope that it will be useful,
  81. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  82. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  83. * Lesser General Public License for more details.
  84. *
  85. */