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