Add this for backwards compatibility
authorMiguel de Icaza <miguel@gnome.org>
Wed, 21 Dec 2005 18:52:25 +0000 (18:52 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 21 Dec 2005 18:52:25 +0000 (18:52 -0000)
svn path=/trunk/mcs/; revision=54699

45 files changed:
1  2 
mcs/class/Compat.ICSharpCode.SharpZipLib/ChangeLog
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.dll.sources
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/AssemblyInfo.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/BZip2/BZip2.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/BZip2/BZip2Constants.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/BZip2/BZip2InputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/BZip2/BZip2OutputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/ChangeLog
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Checksums/Adler32.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Checksums/Crc32.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Checksums/IChecksum.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Checksums/StrangeCrc.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/GZip/GZipConstants.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/GZip/GZipInputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/GZip/GZipOutputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarArchive.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarBuffer.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarEntry.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarHeader.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarInputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarOutputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/Deflater.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/DeflaterConstants.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/DeflaterEngine.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/DeflaterHuffman.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/DeflaterPending.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/Inflater.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/InflaterDynHeader.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/InflaterHuffmanTree.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/PendingBuffer.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/Streams/DeflaterOutputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/Streams/InflaterInputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/Streams/OutputWindow.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/Compression/Streams/StreamManipulator.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/ZipConstants.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/ZipInputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/ZipException.cs
mcs/class/Compat.ICSharpCode.SharpZipLib/Makefile
mcs/class/Compat.ICSharpCode.SharpZipLib/README
mcs/class/Compat.ICSharpCode.SharpZipLib/SharpZipLib.key
mcs/class/Compat.ICSharpCode.SharpZipLib/SharpZipLib.pub

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..8e91e21a4c4a56ab011884731ba9117d4ea79956
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,17 @@@
++2004-11-25  Raja R Harinath  <rharinath@novell.com>
++
++      * Makefile (EXTRA_DISTFILES): Add SharpZipLib.pub.
++
++2004-06-21  Raja R Harinath  <rharinath@novell.com>
++
++      * Makefile (LIBRARY_SNK): Sign with SharpZipLib.key.  The library
++      is delay-signed according to ICSharpCode.SharpZipLib/AssemblyInfo.cs.
++
++2004-06-09  Sebastien Pouliot  <sebastien@ximian.com>
++
++      * Makefile: Don't sign this assembly as it is fully signed during
++      compilation (we have the original private key). Thanks to Jackson.
++
++2004-05-28  Duncan Mak  <duncan@ximian.com>
++
++      * SharpZipLib.pub: Added public key.
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..98de302206bae41dfb39a2241e43923f9e40fcf1
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,38 @@@
++./ICSharpCode.SharpZipLib/BZip2/BZip2.cs
++./ICSharpCode.SharpZipLib/BZip2/BZip2Constants.cs
++./ICSharpCode.SharpZipLib/BZip2/BZip2InputStream.cs
++./ICSharpCode.SharpZipLib/BZip2/BZip2OutputStream.cs
++./ICSharpCode.SharpZipLib/Checksums/Adler32.cs
++./ICSharpCode.SharpZipLib/Checksums/Crc32.cs
++./ICSharpCode.SharpZipLib/Checksums/IChecksum.cs
++./ICSharpCode.SharpZipLib/Checksums/StrangeCrc.cs
++./ICSharpCode.SharpZipLib/GZip/GZipConstants.cs
++./ICSharpCode.SharpZipLib/GZip/GZipInputStream.cs
++./ICSharpCode.SharpZipLib/GZip/GZipOutputStream.cs
++./ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs
++./ICSharpCode.SharpZipLib/Tar/TarArchive.cs
++./ICSharpCode.SharpZipLib/Tar/TarBuffer.cs
++./ICSharpCode.SharpZipLib/Tar/TarEntry.cs
++./ICSharpCode.SharpZipLib/Tar/TarHeader.cs
++./ICSharpCode.SharpZipLib/Tar/TarInputStream.cs
++./ICSharpCode.SharpZipLib/Tar/TarOutputStream.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/Deflater.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/DeflaterConstants.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/DeflaterEngine.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/DeflaterHuffman.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/DeflaterPending.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/Inflater.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/InflaterDynHeader.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/InflaterHuffmanTree.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/PendingBuffer.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/Streams/DeflaterOutputStream.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/Streams/InflaterInputStream.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/Streams/OutputWindow.cs
++./ICSharpCode.SharpZipLib/Zip/Compression/Streams/StreamManipulator.cs
++./ICSharpCode.SharpZipLib/Zip/ZipConstants.cs
++./ICSharpCode.SharpZipLib/Zip/ZipEntry.cs
++./ICSharpCode.SharpZipLib/Zip/ZipFile.cs
++./ICSharpCode.SharpZipLib/Zip/ZipInputStream.cs
++./ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs
++./ICSharpCode.SharpZipLib/AssemblyInfo.cs
++./ICSharpCode.SharpZipLib/ZipException.cs
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a7be065d43d2a1ae4e3d2be758ff96316d4a8da1
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,58 @@@
++// AssemblyInfo.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.Reflection;\r
++using System.Runtime.CompilerServices;\r
++\r
++[assembly: CLSCompliant(true)]\r
++\r
++[assembly: AssemblyTitle("ICSharpCode.SharpZipLibrary")]\r
++[assembly: AssemblyDescription("free C# zlib implementation")]\r
++[assembly: AssemblyConfiguration("")]\r
++[assembly: AssemblyCompany("")]\r
++[assembly: AssemblyProduct("#ZipLibrary")]\r
++[assembly: AssemblyCopyright("(c) Mike Krueger 2001-2004")]\r
++[assembly: AssemblyTrademark("")]\r
++[assembly: AssemblyCulture("")]\r
++\r
++#if NET_2_0
++[assembly: AssemblyVersion("2.6.0.0")]\r
++#else
++// not worrying about the NET_1_0 profile for now.
++[assembly: AssemblyVersion("0.6.0.0")]\r
++#endif
++\r
++[assembly: AssemblyDelaySign(true)]\r
++[assembly: AssemblyKeyFile ("SharpZipLib.pub")]\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..fc24db04701858637afdf93a741334dc1417d4d6
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,89 @@@
++// BZip2.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++\r
++namespace ICSharpCode.SharpZipLib.BZip2 \r
++{\r
++      \r
++      /// <summary>\r
++      /// Does all the compress and decompress pre-operation stuff.\r
++      /// Sets up the streams and file header characters.\r
++      /// Uses multiply overloaded methods to call for the compress/decompress.\r
++      /// </summary>\r
++      public sealed class BZip2\r
++      {\r
++              public static void Decompress(Stream instream, Stream outstream) \r
++              {\r
++                      System.IO.Stream bos = outstream;\r
++                      System.IO.Stream bis = instream;\r
++                      BZip2InputStream bzis = new BZip2InputStream(bis);\r
++                      int ch = bzis.ReadByte();\r
++                      while (ch != -1) {\r
++                              bos.WriteByte((byte)ch);\r
++                              ch = bzis.ReadByte();\r
++                      }\r
++                      bos.Flush();\r
++              }\r
++              \r
++              public static void Compress(Stream instream, Stream outstream, int blockSize) \r
++              {                       \r
++                      System.IO.Stream bos = outstream;\r
++                      System.IO.Stream bis = instream;\r
++                      int ch = bis.ReadByte();\r
++                      BZip2OutputStream bzos = new BZip2OutputStream(bos, blockSize);\r
++                      while(ch != -1) {\r
++                              bzos.WriteByte((byte)ch);\r
++                              ch = bis.ReadByte();\r
++                      }\r
++                      bis.Close();\r
++                      bzos.Close();\r
++              }\r
++      }\r
++}\r
++/* derived from a file which contained this license :\r
++ * Copyright (c) 1999-2001 Keiron Liddle, Aftex Software\r
++ *\r
++ * This library is free software; you can redistribute it and/or\r
++ * modify it under the terms of the GNU Lesser General Public\r
++ * License as published by the Free Software Foundation; either\r
++ * version 2.1 of the License, or (at your option) any later version.\r
++ *\r
++ * This library is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++ * Lesser General Public License for more details.\r
++ *\r
++*/\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a9db486bfa45972a79aeab12641b57a9c6300153
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,156 @@@
++// BZip2Constants.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++namespace ICSharpCode.SharpZipLib.BZip2 \r
++{\r
++      \r
++      /// <summary>\r
++      /// Base class for both the compress and decompress classes.\r
++      /// Holds common arrays, and static data.\r
++      /// </summary>\r
++      public sealed class BZip2Constants\r
++      {\r
++              public readonly static int[] rNums = {\r
++                                                                                               619, 720, 127, 481, 931, 816, 813, 233, 566, 247,\r
++                                                                                               985, 724, 205, 454, 863, 491, 741, 242, 949, 214,\r
++                                                                                               733, 859, 335, 708, 621, 574, 73, 654, 730, 472,\r
++                                                                                               419, 436, 278, 496, 867, 210, 399, 680, 480, 51,\r
++                                                                                               878, 465, 811, 169, 869, 675, 611, 697, 867, 561,\r
++                                                                                               862, 687, 507, 283, 482, 129, 807, 591, 733, 623,\r
++                                                                                               150, 238, 59, 379, 684, 877, 625, 169, 643, 105,\r
++                                                                                               170, 607, 520, 932, 727, 476, 693, 425, 174, 647,\r
++                                                                                               73, 122, 335, 530, 442, 853, 695, 249, 445, 515,\r
++                                                                                               909, 545, 703, 919, 874, 474, 882, 500, 594, 612,\r
++                                                                                               641, 801, 220, 162, 819, 984, 589, 513, 495, 799,\r
++                                                                                               161, 604, 958, 533, 221, 400, 386, 867, 600, 782,\r
++                                                                                               382, 596, 414, 171, 516, 375, 682, 485, 911, 276,\r
++                                                                                               98, 553, 163, 354, 666, 933, 424, 341, 533, 870,\r
++                                                                                               227, 730, 475, 186, 263, 647, 537, 686, 600, 224,\r
++                                                                                               469, 68, 770, 919, 190, 373, 294, 822, 808, 206,\r
++                                                                                               184, 943, 795, 384, 383, 461, 404, 758, 839, 887,\r
++                                                                                               715, 67, 618, 276, 204, 918, 873, 777, 604, 560,\r
++                                                                                               951, 160, 578, 722, 79, 804, 96, 409, 713, 940,\r
++                                                                                               652, 934, 970, 447, 318, 353, 859, 672, 112, 785,\r
++                                                                                               645, 863, 803, 350, 139, 93, 354, 99, 820, 908,\r
++                                                                                               609, 772, 154, 274, 580, 184, 79, 626, 630, 742,\r
++                                                                                               653, 282, 762, 623, 680, 81, 927, 626, 789, 125,\r
++                                                                                               411, 521, 938, 300, 821, 78, 343, 175, 128, 250,\r
++                                                                                               170, 774, 972, 275, 999, 639, 495, 78, 352, 126,\r
++                                                                                               857, 956, 358, 619, 580, 124, 737, 594, 701, 612,\r
++                                                                                               669, 112, 134, 694, 363, 992, 809, 743, 168, 974,\r
++                                                                                               944, 375, 748, 52, 600, 747, 642, 182, 862, 81,\r
++                                                                                               344, 805, 988, 739, 511, 655, 814, 334, 249, 515,\r
++                                                                                               897, 955, 664, 981, 649, 113, 974, 459, 893, 228,\r
++                                                                                               433, 837, 553, 268, 926, 240, 102, 654, 459, 51,\r
++                                                                                               686, 754, 806, 760, 493, 403, 415, 394, 687, 700,\r
++                                                                                               946, 670, 656, 610, 738, 392, 760, 799, 887, 653,\r
++                                                                                               978, 321, 576, 617, 626, 502, 894, 679, 243, 440,\r
++                                                                                               680, 879, 194, 572, 640, 724, 926, 56, 204, 700,\r
++                                                                                               707, 151, 457, 449, 797, 195, 791, 558, 945, 679,\r
++                                                                                               297, 59, 87, 824, 713, 663, 412, 693, 342, 606,\r
++                                                                                               134, 108, 571, 364, 631, 212, 174, 643, 304, 329,\r
++                                                                                               343, 97, 430, 751, 497, 314, 983, 374, 822, 928,\r
++                                                                                               140, 206, 73, 263, 980, 736, 876, 478, 430, 305,\r
++                                                                                               170, 514, 364, 692, 829, 82, 855, 953, 676, 246,\r
++                                                                                               369, 970, 294, 750, 807, 827, 150, 790, 288, 923,\r
++                                                                                               804, 378, 215, 828, 592, 281, 565, 555, 710, 82,\r
++                                                                                               896, 831, 547, 261, 524, 462, 293, 465, 502, 56,\r
++                                                                                               661, 821, 976, 991, 658, 869, 905, 758, 745, 193,\r
++                                                                                               768, 550, 608, 933, 378, 286, 215, 979, 792, 961,\r
++                                                                                               61, 688, 793, 644, 986, 403, 106, 366, 905, 644,\r
++                                                                                               372, 567, 466, 434, 645, 210, 389, 550, 919, 135,\r
++                                                                                               780, 773, 635, 389, 707, 100, 626, 958, 165, 504,\r
++                                                                                               920, 176, 193, 713, 857, 265, 203, 50, 668, 108,\r
++                                                                                               645, 990, 626, 197, 510, 357, 358, 850, 858, 364,\r
++                                                                                               936, 638\r
++                                                                                       };\r
++              \r
++              public readonly static int baseBlockSize = 100000;\r
++              \r
++              public readonly static int MAX_ALPHA_SIZE = 258;\r
++              public readonly static int MAX_CODE_LEN = 23;\r
++              \r
++              public readonly static int RUNA = 0;\r
++              public readonly static int RUNB = 1;\r
++              \r
++              public readonly static int N_GROUPS = 6;\r
++              public readonly static int G_SIZE = 50;\r
++              public readonly static int N_ITERS = 4;\r
++              \r
++              public readonly static int MAX_SELECTORS = (2 + (900000 / G_SIZE));\r
++              \r
++              public readonly static int NUM_OVERSHOOT_BYTES = 20;\r
++      }\r
++}\r
++      \r
++/* This file was derived from a file containing under this license:\r
++ * \r
++ * This file is a part of bzip2 and/or libbzip2, a program and\r
++ * library for lossless, block-sorting data compression.\r
++ * \r
++ * Copyright (C) 1996-1998 Julian R Seward.  All rights reserved.\r
++ * \r
++ * Redistribution and use in source and binary forms, with or without\r
++ * modification, are permitted provided that the following conditions\r
++ * are met:\r
++ * \r
++ * 1. Redistributions of source code must retain the above copyright\r
++ * notice, this list of conditions and the following disclaimer.\r
++ * \r
++ * 2. The origin of this software must not be misrepresented; you must \r
++ * not claim that you wrote the original software.  If you use this \r
++ * software in a product, an acknowledgment in the product \r
++ * documentation would be appreciated but is not required.\r
++ * \r
++ * 3. Altered source versions must be plainly marked as such, and must\r
++ * not be misrepresented as being the original software.\r
++ * \r
++ * 4. The name of the author may not be used to endorse or promote \r
++ * products derived from this software without specific prior written \r
++ * permission.\r
++ * \r
++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
++ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
++ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
++ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
++ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
++ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
++ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
++ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
++ * \r
++ * Java version ported by Keiron Liddle, Aftex Software <keiron@aftexsw.com> 1999-2001\r
++ */\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..454878d8a015f55f986f924bf9c63edea5f7fb37
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,958 @@@
++// BZip2InputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++\r
++namespace ICSharpCode.SharpZipLib.BZip2 \r
++{\r
++      \r
++      /// <summary>\r
++      /// An input stream that decompresses from the BZip2 format (without the file\r
++      /// header chars) to be read as any other stream.\r
++      /// </summary>\r
++      public class BZip2InputStream : Stream\r
++      {\r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanRead {\r
++                      get {\r
++                              return baseStream.CanRead;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanSeek {\r
++                      get {\r
++                              return baseStream.CanSeek;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanWrite {\r
++                      get {\r
++                              return baseStream.CanWrite;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Length {\r
++                      get {\r
++                              return baseStream.Length;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Position {\r
++                      get {\r
++                              return baseStream.Position;\r
++                      }\r
++                      set {\r
++                              baseStream.Position = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Flushes the baseInputStream\r
++              /// </summary>\r
++              public override void Flush()\r
++              {\r
++                      if (baseStream != null) {\r
++                              baseStream.Flush();\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Seek(long offset, SeekOrigin origin)\r
++              {\r
++                      return baseStream.Seek(offset, origin);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void SetLength(long val)\r
++              {\r
++                      baseStream.SetLength(val);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void Write(byte[] array, int offset, int count)\r
++              {\r
++                      baseStream.Write(array, offset, count);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void WriteByte(byte val)\r
++              {\r
++                      baseStream.WriteByte(val);\r
++              }\r
++              \r
++              public override int Read(byte[] b, int off, int len)\r
++              {\r
++                      for (int i = 0; i < len; ++i) {\r
++                              int rb = ReadByte();\r
++                              if (rb == -1) {\r
++                                      return i;\r
++                              }\r
++                              b[off + i] = (byte)rb;\r
++                      }\r
++                      return len;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Closes the input stream\r
++              /// </summary>\r
++              public override void Close()\r
++              {\r
++                      if (baseStream != null) {\r
++                              baseStream.Close();\r
++                      }\r
++              }\r
++              \r
++              static void Cadvise()\r
++              {\r
++                      //Console.WriteLine("CRC Error");\r
++                      //throw new CCoruptionError();\r
++              }\r
++              \r
++              static void BadBGLengths() \r
++              {\r
++                      //Console.WriteLine("bad BG lengths");\r
++              }\r
++              \r
++              static void BitStreamEOF() \r
++              {\r
++                      //Console.WriteLine("bit stream eof");\r
++              }\r
++              \r
++              static void CompressedStreamEOF() \r
++              {\r
++                      //Console.WriteLine("compressed stream eof");\r
++              }\r
++              \r
++              void MakeMaps() \r
++              {\r
++                      nInUse = 0;\r
++                      for (int i = 0; i < 256; ++i) {\r
++                              if (inUse[i]) {\r
++                                      seqToUnseq[nInUse] = (byte)i;\r
++                                      unseqToSeq[i] = (byte)nInUse;\r
++                                      nInUse++;\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              /*--\r
++              index of the last char in the block, so\r
++              the block size == last + 1.\r
++              --*/\r
++              int last;\r
++              \r
++              /*--\r
++              index in zptr[] of original string after sorting.\r
++              --*/\r
++              int origPtr;\r
++              \r
++              /*--\r
++              always: in the range 0 .. 9.\r
++              The current block size is 100000 * this number.\r
++              --*/\r
++              int blockSize100k;\r
++              \r
++              bool blockRandomised;\r
++              \r
++              //              private int bytesIn;\r
++              //              private int bytesOut;\r
++              int bsBuff;\r
++              int bsLive;\r
++              IChecksum mCrc = new StrangeCRC();\r
++              \r
++              bool[] inUse = new bool[256];\r
++              int    nInUse;\r
++              \r
++              byte[] seqToUnseq = new byte[256];\r
++              byte[] unseqToSeq = new byte[256];\r
++              \r
++              byte[] selector    = new byte[BZip2Constants.MAX_SELECTORS];\r
++              byte[] selectorMtf = new byte[BZip2Constants.MAX_SELECTORS];\r
++              \r
++              int[] tt;\r
++              byte[] ll8;\r
++              \r
++              /*--\r
++              freq table collected to save a pass over the data\r
++              during decompression.\r
++              --*/\r
++              int[] unzftab = new int[256];\r
++              \r
++              int[][] limit     = new int[BZip2Constants.N_GROUPS][];\r
++              int[][] baseArray = new int[BZip2Constants.N_GROUPS][];\r
++              int[][] perm      = new int[BZip2Constants.N_GROUPS][];\r
++              int[] minLens     = new int[BZip2Constants.N_GROUPS];\r
++              \r
++              Stream baseStream;\r
++              bool   streamEnd = false;\r
++              \r
++              int currentChar = -1;\r
++              \r
++              const int START_BLOCK_STATE = 1;\r
++              const int RAND_PART_A_STATE = 2;\r
++              const int RAND_PART_B_STATE = 3;\r
++              const int RAND_PART_C_STATE = 4;\r
++              const int NO_RAND_PART_A_STATE = 5;\r
++              const int NO_RAND_PART_B_STATE = 6;\r
++              const int NO_RAND_PART_C_STATE = 7;\r
++              \r
++              int currentState = START_BLOCK_STATE;\r
++              \r
++              int storedBlockCRC, storedCombinedCRC;\r
++              int computedBlockCRC;\r
++              uint computedCombinedCRC;\r
++              \r
++              int count, chPrev, ch2;\r
++              int tPos;\r
++              int rNToGo = 0;\r
++              int rTPos  = 0;\r
++              int i2, j2;\r
++              byte z;\r
++              \r
++              public BZip2InputStream(Stream zStream) \r
++              {\r
++                      // init arrays\r
++                      for (int i = 0; i < BZip2Constants.N_GROUPS; ++i) {\r
++                              limit[i] = new int[BZip2Constants.MAX_ALPHA_SIZE];\r
++                              baseArray[i]  = new int[BZip2Constants.MAX_ALPHA_SIZE];\r
++                              perm[i]  = new int[BZip2Constants.MAX_ALPHA_SIZE];\r
++                      }\r
++                      \r
++                      ll8 = null;\r
++                      tt  = null;\r
++                      BsSetStream(zStream);\r
++                      Initialize();\r
++                      InitBlock();\r
++                      SetupBlock();\r
++              }\r
++              \r
++              public override int ReadByte()\r
++              {\r
++                      if (streamEnd) {\r
++                              return -1; // ok\r
++                      }\r
++                      \r
++                      int retChar = currentChar;\r
++                      switch (currentState) {\r
++                              case RAND_PART_B_STATE:\r
++                                      SetupRandPartB();\r
++                                      break;\r
++                              case RAND_PART_C_STATE:\r
++                                      SetupRandPartC();\r
++                                      break;\r
++                              case NO_RAND_PART_B_STATE:\r
++                                      SetupNoRandPartB();\r
++                                      break;\r
++                              case NO_RAND_PART_C_STATE:\r
++                                      SetupNoRandPartC();\r
++                                      break;\r
++                              case START_BLOCK_STATE:\r
++                              case NO_RAND_PART_A_STATE:\r
++                              case RAND_PART_A_STATE:\r
++                                      break;\r
++                              default:\r
++                                      break;\r
++                      }\r
++                      return retChar;\r
++              }\r
++              \r
++              void Initialize() \r
++              {\r
++                      // -jr- 18-Nov-2003 magic1 and 2 added here so stream is fully capable on its own\r
++                      char magic1 = BsGetUChar();\r
++                      char magic2 = BsGetUChar();\r
++                      \r
++                      char magic3 = BsGetUChar();\r
++                      char magic4 = BsGetUChar();\r
++                      \r
++                      if (magic1 != 'B' || magic2 != 'Z' || magic3 != 'h' || magic4 < '1' || magic4 > '9') {\r
++                              streamEnd = true;\r
++                              return;\r
++                      }\r
++                      \r
++                      SetDecompressStructureSizes(magic4 - '0');\r
++                      computedCombinedCRC = 0;\r
++              }\r
++              \r
++              void InitBlock() \r
++              {\r
++                      char magic1 = BsGetUChar();\r
++                      char magic2 = BsGetUChar();\r
++                      char magic3 = BsGetUChar();\r
++                      char magic4 = BsGetUChar();\r
++                      char magic5 = BsGetUChar();\r
++                      char magic6 = BsGetUChar();\r
++                      \r
++                      if (magic1 == 0x17 && magic2 == 0x72 && magic3 == 0x45 && magic4 == 0x38 && magic5 == 0x50 && magic6 == 0x90) {\r
++                              Complete();\r
++                              return;\r
++                      }\r
++                      \r
++                      if (magic1 != 0x31 || magic2 != 0x41 || magic3 != 0x59 || magic4 != 0x26 || magic5 != 0x53 || magic6 != 0x59) {\r
++                              BadBlockHeader();\r
++                              streamEnd = true;\r
++                              return;\r
++                      }\r
++                      \r
++                      storedBlockCRC  = BsGetInt32();\r
++                      \r
++                      blockRandomised = (BsR(1) == 1);\r
++                      \r
++                      //              currBlockNo++;\r
++                      GetAndMoveToFrontDecode();\r
++                      \r
++                      mCrc.Reset();\r
++                      currentState = START_BLOCK_STATE;\r
++              }\r
++              \r
++              void EndBlock() \r
++              {\r
++                      computedBlockCRC = (int)mCrc.Value;\r
++                      \r
++                      /*-- A bad CRC is considered a fatal error. --*/\r
++                      if (storedBlockCRC != computedBlockCRC) {\r
++                              CrcError();\r
++                      }\r
++                      \r
++                      // 1528150659\r
++                      computedCombinedCRC = ((computedCombinedCRC << 1) & 0xFFFFFFFF) | (computedCombinedCRC >> 31);\r
++                      computedCombinedCRC = computedCombinedCRC ^ (uint)computedBlockCRC;\r
++              }\r
++              \r
++              void Complete() \r
++              {\r
++                      storedCombinedCRC = BsGetInt32();\r
++                      if (storedCombinedCRC != (int)computedCombinedCRC) {\r
++                              CrcError();\r
++                      }\r
++                      \r
++                      streamEnd = true;\r
++              }\r
++              \r
++              static void BlockOverrun() \r
++              {\r
++                      //Console.WriteLine("Block overrun");\r
++              }\r
++              \r
++              static void BadBlockHeader() \r
++              {\r
++                      //Console.WriteLine("Bad block header");\r
++              }\r
++              \r
++              static void CrcError() \r
++              {\r
++                      //Console.WriteLine("crc error");\r
++              }\r
++              \r
++              \r
++              void BsSetStream(Stream f) \r
++              {\r
++                      baseStream = f;\r
++                      bsLive = 0;\r
++                      bsBuff = 0;\r
++              }\r
++              \r
++              void FillBuffer()\r
++              {\r
++                      int thech = 0;\r
++                      \r
++                      try {\r
++                              thech = baseStream.ReadByte();\r
++                      } catch (Exception) {\r
++                              CompressedStreamEOF();\r
++                      }\r
++                      \r
++                      if (thech == -1) {\r
++                              CompressedStreamEOF();\r
++                      }\r
++                      \r
++                      bsBuff = (bsBuff << 8) | (thech & 0xFF);\r
++                      bsLive += 8;\r
++              }\r
++              \r
++              int BsR(int n) \r
++              {\r
++                      while (bsLive < n) {\r
++                              FillBuffer();\r
++                      }\r
++                      \r
++                      int v = (bsBuff >> (bsLive - n)) & ((1 << n) - 1);\r
++                      bsLive -= n;\r
++                      return v;\r
++              }\r
++              \r
++              char BsGetUChar() \r
++              {\r
++                      return (char)BsR(8);\r
++              }\r
++              \r
++              int BsGetint() \r
++              {\r
++                      int u = 0;\r
++                      u = (u << 8) | BsR(8);\r
++                      u = (u << 8) | BsR(8);\r
++                      u = (u << 8) | BsR(8);\r
++                      u = (u << 8) | BsR(8);\r
++                      return u;\r
++              }\r
++              \r
++              int BsGetIntVS(int numBits) \r
++              {\r
++                      return (int)BsR(numBits);\r
++              }\r
++              \r
++              int BsGetInt32() \r
++              {\r
++                      return (int)BsGetint();\r
++              }\r
++              \r
++              void HbCreateDecodeTables(int[] limit, int[] baseArray, int[] perm, char[] length, int minLen, int maxLen, int alphaSize) \r
++              {\r
++                      int pp = 0;\r
++                      \r
++                      for (int i = minLen; i <= maxLen; ++i) {\r
++                              for (int j = 0; j < alphaSize; ++j) {\r
++                                      if (length[j] == i) {\r
++                                              perm[pp] = j;\r
++                                              ++pp;\r
++                                      }\r
++                              }\r
++                      }\r
++                      \r
++                      for (int i = 0; i < BZip2Constants.MAX_CODE_LEN; i++) {\r
++                              baseArray[i] = 0;\r
++                      }\r
++                      \r
++                      for (int i = 0; i < alphaSize; i++) {\r
++                              ++baseArray[length[i] + 1];\r
++                      }\r
++                      \r
++                      for (int i = 1; i < BZip2Constants.MAX_CODE_LEN; i++) {\r
++                              baseArray[i] += baseArray[i - 1];\r
++                      }\r
++                      \r
++                      for (int i = 0; i < BZip2Constants.MAX_CODE_LEN; i++) {\r
++                              limit[i] = 0;\r
++                      }\r
++                      \r
++                      int vec = 0;\r
++                      \r
++                      for (int i = minLen; i <= maxLen; i++) {\r
++                              vec += (baseArray[i + 1] - baseArray[i]);\r
++                              limit[i] = vec - 1;\r
++                              vec <<= 1;\r
++                      }\r
++                      \r
++                      for (int i = minLen + 1; i <= maxLen; i++) {\r
++                              baseArray[i] = ((limit[i - 1] + 1) << 1) - baseArray[i];\r
++                      }\r
++              }\r
++              \r
++              void RecvDecodingTables() \r
++              {\r
++                      char[][] len = new char[BZip2Constants.N_GROUPS][];\r
++                      for (int i = 0; i < BZip2Constants.N_GROUPS; ++i) {\r
++                              len[i] = new char[BZip2Constants.MAX_ALPHA_SIZE];\r
++                      }\r
++                      \r
++                      bool[] inUse16 = new bool[16];\r
++                      \r
++                      /*--- Receive the mapping table ---*/\r
++                      for (int i = 0; i < 16; i++) {\r
++                              inUse16[i] = (BsR(1) == 1);\r
++                      } \r
++                      \r
++                      for (int i = 0; i < 16; i++) {\r
++                              if (inUse16[i]) {\r
++                                      for (int j = 0; j < 16; j++) {\r
++                                              inUse[i * 16 + j] = (BsR(1) == 1);\r
++                                      }\r
++                              } else {\r
++                                      for (int j = 0; j < 16; j++) {\r
++                                              inUse[i * 16 + j] = false;\r
++                                      }\r
++                              }\r
++                      }\r
++                      \r
++                      MakeMaps();\r
++                      int alphaSize = nInUse + 2;\r
++                      \r
++                      /*--- Now the selectors ---*/\r
++                      int nGroups    = BsR(3);\r
++                      int nSelectors = BsR(15);\r
++                      \r
++                      for (int i = 0; i < nSelectors; i++) {\r
++                              int j = 0;\r
++                              while (BsR(1) == 1) {\r
++                                      j++;\r
++                              }\r
++                              selectorMtf[i] = (byte)j;\r
++                      }\r
++                      \r
++                      /*--- Undo the MTF values for the selectors. ---*/\r
++                      byte[] pos = new byte[BZip2Constants.N_GROUPS];\r
++                      for (int v = 0; v < nGroups; v++) {\r
++                              pos[v] = (byte)v;\r
++                      }\r
++                      \r
++                      for (int i = 0; i < nSelectors; i++) {\r
++                              int  v   = selectorMtf[i];\r
++                              byte tmp = pos[v];\r
++                              while (v > 0) {\r
++                                      pos[v] = pos[v - 1];\r
++                                      v--;\r
++                              }\r
++                              pos[0]      = tmp;\r
++                              selector[i] = tmp;\r
++                      }\r
++                      \r
++                      /*--- Now the coding tables ---*/\r
++                      for (int t = 0; t < nGroups; t++) {\r
++                              int curr = BsR(5);\r
++                              for (int i = 0; i < alphaSize; i++) {\r
++                                      while (BsR(1) == 1) {\r
++                                              if (BsR(1) == 0) {\r
++                                                      curr++;\r
++                                              } else {\r
++                                                      curr--;\r
++                                              }\r
++                                      }\r
++                                      len[t][i] = (char)curr;\r
++                              }\r
++                      }\r
++                      \r
++                      /*--- Create the Huffman decoding tables ---*/\r
++                      for (int t = 0; t < nGroups; t++) {\r
++                              int minLen = 32;\r
++                              int maxLen = 0;\r
++                              for (int i = 0; i < alphaSize; i++) {\r
++                                      maxLen = Math.Max(maxLen, len[t][i]);\r
++                                      minLen = Math.Min(minLen, len[t][i]);\r
++                              }\r
++                              HbCreateDecodeTables(limit[t], baseArray[t], perm[t], len[t], minLen, maxLen, alphaSize);\r
++                              minLens[t] = minLen;\r
++                      }\r
++              }\r
++              \r
++              void GetAndMoveToFrontDecode() \r
++              {\r
++                      byte[] yy = new byte[256];\r
++                      int nextSym;\r
++                      \r
++                      int limitLast = BZip2Constants.baseBlockSize * blockSize100k;\r
++                      origPtr = BsGetIntVS(24);\r
++                      \r
++                      RecvDecodingTables();\r
++                      int EOB = nInUse+1;\r
++                      int groupNo = -1;\r
++                      int groupPos = 0;\r
++                      \r
++                      /*--\r
++                      Setting up the unzftab entries here is not strictly\r
++                      necessary, but it does save having to do it later\r
++                      in a separate pass, and so saves a block's worth of\r
++                      cache misses.\r
++                      --*/\r
++                      for (int i = 0; i <= 255; i++) {\r
++                              unzftab[i] = 0;\r
++                      }\r
++                      \r
++                      for (int i = 0; i <= 255; i++) {\r
++                              yy[i] = (byte)i;\r
++                      }\r
++                      \r
++                      last = -1;\r
++                      \r
++                      if (groupPos == 0) {\r
++                              groupNo++;\r
++                              groupPos = BZip2Constants.G_SIZE;\r
++                      }\r
++                      \r
++                      groupPos--;\r
++                      int zt = selector[groupNo];\r
++                      int zn = minLens[zt];\r
++                      int zvec = BsR(zn);\r
++                      int zj;\r
++                      \r
++                      while (zvec > limit[zt][zn]) {\r
++                              if (zn > 20) { // the longest code\r
++                                      throw new ApplicationException("Bzip data error");  // -jr- 17-Dec-2003 from bzip 1.02 why 20???\r
++                              }\r
++                              zn++;\r
++                              while (bsLive < 1) {\r
++                                      FillBuffer();\r
++                              }\r
++                              zj = (bsBuff >> (bsLive-1)) & 1;\r
++                              bsLive--;\r
++                              zvec = (zvec << 1) | zj;\r
++                      }\r
++                      if (zvec - baseArray[zt][zn] < 0 || zvec - baseArray[zt][zn] >= BZip2Constants.MAX_ALPHA_SIZE) {\r
++                              throw new ApplicationException("Bzip data error");  // -jr- 17-Dec-2003 from bzip 1.02\r
++                      }\r
++                      nextSym = perm[zt][zvec - baseArray[zt][zn]];\r
++                      \r
++                      while (true) {\r
++                              if (nextSym == EOB) {\r
++                                      break;\r
++                              }\r
++                              \r
++                              if (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB) {\r
++                                      int s = -1;\r
++                                      int n = 1;\r
++                                      do {\r
++                                              if (nextSym == BZip2Constants.RUNA) {\r
++                                                      s += (0 + 1) * n;\r
++                                              } else if (nextSym == BZip2Constants.RUNB) {\r
++                                                      s += (1 + 1) * n;\r
++                                              }\r
++\r
++                                              n <<= 1;\r
++                                              \r
++                                              if (groupPos == 0) {\r
++                                                      groupNo++;\r
++                                                      groupPos = BZip2Constants.G_SIZE;\r
++                                              }\r
++                                              \r
++                                              groupPos--;\r
++                                              \r
++                                              zt = selector[groupNo];\r
++                                              zn = minLens[zt];\r
++                                              zvec = BsR(zn);\r
++                                              \r
++                                              while (zvec > limit[zt][zn]) {\r
++                                                      zn++;\r
++                                                      while (bsLive < 1) {\r
++                                                              FillBuffer();\r
++                                                      }\r
++                                                      zj = (bsBuff >> (bsLive - 1)) & 1;\r
++                                                      bsLive--;\r
++                                                      zvec = (zvec << 1) | zj;\r
++                                              }\r
++                                              nextSym = perm[zt][zvec - baseArray[zt][zn]];\r
++                                      } while (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB);\r
++                                      \r
++                                      s++;\r
++                                      byte ch = seqToUnseq[yy[0]];\r
++                                      unzftab[ch] += s;\r
++                                      \r
++                                      while (s > 0) {\r
++                                              last++;\r
++                                              ll8[last] = ch;\r
++                                              s--;\r
++                                      }\r
++                                      \r
++                                      if (last >= limitLast) {\r
++                                              BlockOverrun();\r
++                                      }\r
++                                      continue;\r
++                              } else {\r
++                                      last++;\r
++                                      if (last >= limitLast) {\r
++                                              BlockOverrun();\r
++                                      }\r
++                                      \r
++                                      byte tmp = yy[nextSym - 1];\r
++                                      unzftab[seqToUnseq[tmp]]++;\r
++                                      ll8[last] = seqToUnseq[tmp];\r
++                                      \r
++                                      for (int j = nextSym-1; j > 0; --j) {\r
++                                              yy[j] = yy[j - 1];\r
++                                      }\r
++                                      yy[0] = tmp;\r
++                                      \r
++                                      if (groupPos == 0) {\r
++                                              groupNo++;\r
++                                              groupPos = BZip2Constants.G_SIZE;\r
++                                      }\r
++                                      \r
++                                      groupPos--;\r
++                                      zt = selector[groupNo];\r
++                                      zn = minLens[zt];\r
++                                      zvec = BsR(zn);\r
++                                      while (zvec > limit[zt][zn]) {\r
++                                              zn++;\r
++                                              while (bsLive < 1) {\r
++                                                      FillBuffer();\r
++                                              }\r
++                                              zj = (bsBuff >> (bsLive-1)) & 1;\r
++                                              bsLive--;\r
++                                              zvec = (zvec << 1) | zj;\r
++                                      }\r
++                                      nextSym = perm[zt][zvec - baseArray[zt][zn]];\r
++                                      continue;\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              void SetupBlock() \r
++              {\r
++                      int[] cftab = new int[257];\r
++                      \r
++                      cftab[0] = 0;\r
++                      Array.Copy(unzftab, 0, cftab, 1, 256);\r
++                      \r
++                      for (int i = 1; i <= 256; i++) {\r
++                              cftab[i] += cftab[i - 1];\r
++                      }\r
++                      \r
++                      for (int i = 0; i <= last; i++) {\r
++                              byte ch = ll8[i];\r
++                              tt[cftab[ch]] = i;\r
++                              cftab[ch]++;\r
++                      }\r
++                      \r
++                      cftab = null;\r
++                      \r
++                      tPos = tt[origPtr];\r
++                      \r
++                      count = 0;\r
++                      i2    = 0;\r
++                      ch2   = 256;   /*-- not a char and not EOF --*/\r
++                      \r
++                      if (blockRandomised) {\r
++                              rNToGo = 0;\r
++                              rTPos = 0;\r
++                              SetupRandPartA();\r
++                      } else {\r
++                              SetupNoRandPartA();\r
++                      }\r
++              }\r
++              \r
++              void SetupRandPartA() \r
++              {\r
++                      if (i2 <= last) {\r
++                              chPrev = ch2;\r
++                              ch2  = ll8[tPos];\r
++                              tPos = tt[tPos];\r
++                              if (rNToGo == 0) {\r
++                                      rNToGo = BZip2Constants.rNums[rTPos];\r
++                                      rTPos++;\r
++                                      if(rTPos == 512) {\r
++                                              rTPos = 0;\r
++                                      }\r
++                              }\r
++                              rNToGo--;\r
++                              ch2 ^= (int)((rNToGo == 1) ? 1 : 0);\r
++                              i2++;\r
++                              \r
++                              currentChar  = ch2;\r
++                              currentState = RAND_PART_B_STATE;\r
++                              mCrc.Update(ch2);\r
++                      } else {\r
++                              EndBlock();\r
++                              InitBlock();\r
++                              SetupBlock();\r
++                      }\r
++              }\r
++              \r
++              void SetupNoRandPartA() \r
++              {\r
++                      if (i2 <= last) {\r
++                              chPrev = ch2;\r
++                              ch2  = ll8[tPos];\r
++                              tPos = tt[tPos];\r
++                              i2++;\r
++                              \r
++                              currentChar = ch2;\r
++                              currentState = NO_RAND_PART_B_STATE;\r
++                              mCrc.Update(ch2);\r
++                      } else {\r
++                              EndBlock();\r
++                              InitBlock();\r
++                              SetupBlock();\r
++                      }\r
++              }\r
++              \r
++              void SetupRandPartB() \r
++              {\r
++                      if (ch2 != chPrev) {\r
++                              currentState = RAND_PART_A_STATE;\r
++                              count = 1;\r
++                              SetupRandPartA();\r
++                      } else {\r
++                              count++;\r
++                              if (count >= 4) {\r
++                                      z = ll8[tPos];\r
++                                      tPos = tt[tPos];\r
++                                      if (rNToGo == 0) {\r
++                                              rNToGo = BZip2Constants.rNums[rTPos];\r
++                                              rTPos++;\r
++                                              if (rTPos == 512) {\r
++                                                      rTPos = 0;\r
++                                              }\r
++                                      }\r
++                                      rNToGo--;\r
++                                      z ^= (byte)((rNToGo == 1) ? 1 : 0);\r
++                                      j2 = 0;\r
++                                      currentState = RAND_PART_C_STATE;\r
++                                      SetupRandPartC();\r
++                              } else {\r
++                                      currentState = RAND_PART_A_STATE;\r
++                                      SetupRandPartA();\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              void SetupRandPartC() \r
++              {\r
++                      if (j2 < (int)z) {\r
++                              currentChar = ch2;\r
++                              mCrc.Update(ch2);\r
++                              j2++;\r
++                      } else {\r
++                              currentState = RAND_PART_A_STATE;\r
++                              i2++;\r
++                              count = 0;\r
++                              SetupRandPartA();\r
++                      }\r
++              }\r
++              \r
++              void SetupNoRandPartB() \r
++              {\r
++                      if (ch2 != chPrev) {\r
++                              currentState = NO_RAND_PART_A_STATE;\r
++                              count = 1;\r
++                              SetupNoRandPartA();\r
++                      } else {\r
++                              count++;\r
++                              if (count >= 4) {\r
++                                      z = ll8[tPos];\r
++                                      tPos = tt[tPos];\r
++                                      currentState = NO_RAND_PART_C_STATE;\r
++                                      j2 = 0;\r
++                                      SetupNoRandPartC();\r
++                              } else {\r
++                                      currentState = NO_RAND_PART_A_STATE;\r
++                                      SetupNoRandPartA();\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              void SetupNoRandPartC() \r
++              {\r
++                      if (j2 < (int)z) {\r
++                              currentChar = ch2;\r
++                              mCrc.Update(ch2);\r
++                              j2++;\r
++                      } else {\r
++                              currentState = NO_RAND_PART_A_STATE;\r
++                              i2++;\r
++                              count = 0;\r
++                              SetupNoRandPartA();\r
++                      }\r
++              }\r
++              \r
++              void SetDecompressStructureSizes(int newSize100k) \r
++              {\r
++                      if (!(0 <= newSize100k   && newSize100k <= 9 && 0 <= blockSize100k && blockSize100k <= 9)) {\r
++                              throw new ApplicationException("Invalid block size");\r
++                      }\r
++                      \r
++                      blockSize100k = newSize100k;\r
++                      \r
++                      if (newSize100k == 0) {\r
++                              return;\r
++                      }\r
++                      \r
++                      int n = BZip2Constants.baseBlockSize * newSize100k;\r
++                      ll8 = new byte[n];\r
++                      tt  = new int[n];\r
++              }\r
++      }\r
++}\r
++/* This file was derived from a file containing under this license:\r
++ * \r
++ * This file is a part of bzip2 and/or libbzip2, a program and\r
++ * library for lossless, block-sorting data compression.\r
++ * \r
++ * Copyright (C) 1996-1998 Julian R Seward.  All rights reserved.\r
++ * \r
++ * Redistribution and use in source and binary forms, with or without\r
++ * modification, are permitted provided that the following conditions\r
++ * are met:\r
++ * \r
++ * 1. Redistributions of source code must retain the above copyright\r
++ * notice, this list of conditions and the following disclaimer.\r
++ * \r
++ * 2. The origin of this software must not be misrepresented; you must \r
++ * not claim that you wrote the original software.  If you use this \r
++ * software in a product, an acknowledgment in the product \r
++ * documentation would be appreciated but is not required.\r
++ * \r
++ * 3. Altered source versions must be plainly marked as such, and must\r
++ * not be misrepresented as being the original software.\r
++ * \r
++ * 4. The name of the author may not be used to endorse or promote \r
++ * products derived from this software without specific prior written \r
++ * permission.\r
++ * \r
++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
++ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
++ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
++ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
++ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
++ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
++ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
++ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
++ * \r
++ * Java version ported by Keiron Liddle, Aftex Software <keiron@aftexsw.com> 1999-2001\r
++ */\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..4f3d91372ccebdc5fa818b041f7963e485279ef7
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,1776 @@@
++// BZip2OutputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++\r
++namespace ICSharpCode.SharpZipLib.BZip2 \r
++{\r
++      \r
++      /// <summary>\r
++      /// An output stream that compresses into the BZip2 format (without the file\r
++      /// header chars) into another stream.\r
++      /// TODO: Update to BZip2 1.0.1, 1.0.2\r
++      /// </summary>\r
++      public class BZip2OutputStream : Stream\r
++      {\r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanRead {\r
++                      get {\r
++                              return baseStream.CanRead;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanSeek {\r
++                      get {\r
++                              return baseStream.CanSeek;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanWrite {\r
++                      get {\r
++                              return baseStream.CanWrite;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Length {\r
++                      get {\r
++                              return baseStream.Length;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Position {\r
++                      get {\r
++                              return baseStream.Position;\r
++                      }\r
++                      set {\r
++                              baseStream.Position = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Seek(long offset, SeekOrigin origin)\r
++              {\r
++                      return baseStream.Seek(offset, origin);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void SetLength(long val)\r
++              {\r
++                      baseStream.SetLength(val);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override int ReadByte()\r
++              {\r
++                      return baseStream.ReadByte();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override int Read(byte[] b, int off, int len)\r
++              {\r
++                      return baseStream.Read(b, off, len);\r
++              }\r
++              \r
++              public override void Write(byte[] buf, int off, int len)\r
++              {\r
++                      for (int i = 0; i < len; ++i) {\r
++                              WriteByte(buf[off + i]);\r
++                      }\r
++              }\r
++              \r
++              readonly static int SETMASK       = (1 << 21);\r
++              readonly static int CLEARMASK     = (~SETMASK);\r
++              readonly static int GREATER_ICOST = 15;\r
++              readonly static int LESSER_ICOST  = 0;\r
++              readonly static int SMALL_THRESH  = 20;\r
++              readonly static int DEPTH_THRESH  = 10;\r
++              \r
++              /*--\r
++              If you are ever unlucky/improbable enough\r
++              to get a stack overflow whilst sorting,\r
++              increase the following constant and try\r
++              again.  In practice I have never seen the\r
++              stack go above 27 elems, so the following\r
++              limit seems very generous.\r
++              --*/\r
++              readonly static int QSORT_STACK_SIZE = 1000;\r
++              \r
++              static void Panic() \r
++              {\r
++                      //Console.WriteLine("panic");\r
++              }\r
++              \r
++              void MakeMaps() \r
++              {\r
++                      int i;\r
++                      nInUse = 0;\r
++                      for (i = 0; i < 256; i++) {\r
++                              if (inUse[i]) {\r
++                                      seqToUnseq[nInUse] = (char)i;\r
++                                      unseqToSeq[i] = (char)nInUse;\r
++                                      nInUse++;\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              static void HbMakeCodeLengths(char[] len, int[] freq, int alphaSize, int maxLen) \r
++              {\r
++                      /*--\r
++                      Nodes and heap entries run from 1.  Entry 0\r
++                      for both the heap and nodes is a sentinel.\r
++                      --*/\r
++                      int nNodes, nHeap, n1, n2, j, k;\r
++                      bool  tooLong;\r
++                      \r
++                      int[] heap   = new int[BZip2Constants.MAX_ALPHA_SIZE + 2];\r
++                      int[] weight = new int[BZip2Constants.MAX_ALPHA_SIZE * 2];\r
++                      int[] parent = new int[BZip2Constants.MAX_ALPHA_SIZE * 2];\r
++                      \r
++                      for (int i = 0; i < alphaSize; ++i) {\r
++                              weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;\r
++                      }\r
++                      \r
++                      while (true) {\r
++                              nNodes = alphaSize;\r
++                              nHeap = 0;\r
++                              \r
++                              heap[0] = 0;\r
++                              weight[0] = 0;\r
++                              parent[0] = -2;\r
++                              \r
++                              for (int i = 1; i <= alphaSize; ++i) {\r
++                                      parent[i] = -1;\r
++                                      nHeap++;\r
++                                      heap[nHeap] = i;\r
++                                      int zz = nHeap;\r
++                                      int tmp = heap[zz];\r
++                                      while (weight[tmp] < weight[heap[zz >> 1]]) {\r
++                                              heap[zz] = heap[zz >> 1];\r
++                                              zz >>= 1;\r
++                                      }\r
++                                      heap[zz] = tmp;\r
++                              }\r
++                              if (!(nHeap < (BZip2Constants.MAX_ALPHA_SIZE+2))) {\r
++                                      Panic();\r
++                              }\r
++                              \r
++                              while (nHeap > 1) {\r
++                                      n1 = heap[1];\r
++                                      heap[1] = heap[nHeap];\r
++                                      nHeap--;\r
++                                      int zz = 1;\r
++                                      int yy = 0;\r
++                                      int tmp = heap[zz];\r
++                                      while (true) {\r
++                                              yy = zz << 1;\r
++                                              if (yy > nHeap) {\r
++                                                      break;\r
++                                              }\r
++                                              if (yy < nHeap &&  weight[heap[yy+1]] < weight[heap[yy]]) {\r
++                                                      yy++;\r
++                                              }\r
++                                              if (weight[tmp] < weight[heap[yy]]) {\r
++                                                      break;\r
++                                              }\r
++                                              \r
++                                              heap[zz] = heap[yy];\r
++                                              zz = yy;\r
++                                      }\r
++                                      heap[zz] = tmp;\r
++                                      n2 = heap[1];\r
++                                      heap[1] = heap[nHeap];\r
++                                      nHeap--;\r
++                                      \r
++                                      zz = 1;\r
++                                      yy = 0;\r
++                                      tmp = heap[zz];\r
++                                      while (true) {\r
++                                              yy = zz << 1;\r
++                                              if (yy > nHeap) {\r
++                                                      break;\r
++                                              }\r
++                                              if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) {\r
++                                                      yy++;\r
++                                              }\r
++                                              if (weight[tmp] < weight[heap[yy]]) {\r
++                                                      break;\r
++                                              }\r
++                                              heap[zz] = heap[yy];\r
++                                              zz = yy;\r
++                                      }\r
++                                      heap[zz] = tmp;\r
++                                      nNodes++;\r
++                                      parent[n1] = parent[n2] = nNodes;\r
++                                      \r
++                                      weight[nNodes] = (int)((weight[n1] & 0xffffff00) + (weight[n2] & 0xffffff00)) | \r
++                                                       (int)(1 + (((weight[n1] & 0x000000ff) > (weight[n2] & 0x000000ff)) ? (weight[n1] & 0x000000ff) : (weight[n2] & 0x000000ff)));\r
++                                      \r
++                                      parent[nNodes] = -1;\r
++                                      nHeap++;\r
++                                      heap[nHeap] = nNodes;\r
++                                      \r
++                                      zz  = nHeap;\r
++                                      tmp = heap[zz];\r
++                                      while (weight[tmp] < weight[heap[zz >> 1]]) {\r
++                                              heap[zz] = heap[zz >> 1];\r
++                                              zz >>= 1;\r
++                                      }\r
++                                      heap[zz] = tmp;\r
++                              }\r
++                              if (!(nNodes < (BZip2Constants.MAX_ALPHA_SIZE * 2))) {\r
++                                      Panic();\r
++                              }\r
++                              \r
++                              tooLong = false;\r
++                              for (int i = 1; i <= alphaSize; ++i) {\r
++                                      j = 0;\r
++                                      k = i;\r
++                                      while (parent[k] >= 0) {\r
++                                              k = parent[k];\r
++                                              j++;\r
++                                      }\r
++                                      len[i - 1] = (char)j;\r
++                                      if (j > maxLen) {\r
++                                              tooLong = true;\r
++                                      }\r
++                              }\r
++                              \r
++                              if (!tooLong) {\r
++                                      break;\r
++                              }\r
++                              \r
++                              for (int i = 1; i < alphaSize; ++i) {\r
++                                      j = weight[i] >> 8;\r
++                                      j = 1 + (j / 2);\r
++                                      weight[i] = j << 8;\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              /*--\r
++              index of the last char in the block, so\r
++              the block size == last + 1.\r
++              --*/\r
++              int last;\r
++              \r
++              /*--\r
++              index in zptr[] of original string after sorting.\r
++              --*/\r
++              int origPtr;\r
++              \r
++              /*--\r
++              always: in the range 0 .. 9.\r
++              The current block size is 100000 * this number.\r
++              --*/\r
++              int blockSize100k;\r
++              \r
++              bool blockRandomised;\r
++              \r
++              //              int bytesIn;\r
++              int bytesOut;\r
++              int bsBuff;\r
++              int bsLive;\r
++              IChecksum mCrc = new StrangeCRC();\r
++              \r
++              bool[] inUse = new bool[256];\r
++              int nInUse;\r
++              \r
++              char[] seqToUnseq = new char[256];\r
++              char[] unseqToSeq = new char[256];\r
++              \r
++              char[] selector = new char[BZip2Constants.MAX_SELECTORS];\r
++              char[] selectorMtf = new char[BZip2Constants.MAX_SELECTORS];\r
++              \r
++              byte[]  block;\r
++              int[]   quadrant;\r
++              int[]   zptr;\r
++              short[] szptr;\r
++              int[]   ftab;\r
++              \r
++              int nMTF;\r
++              \r
++              int[] mtfFreq = new int[BZip2Constants.MAX_ALPHA_SIZE];\r
++              \r
++              /*\r
++              * Used when sorting.  If too many long comparisons\r
++              * happen, we stop sorting, randomise the block\r
++              * slightly, and try again.\r
++              */\r
++              int workFactor;\r
++              int workDone;\r
++              int workLimit;\r
++              bool firstAttempt;\r
++              int nBlocksRandomised;\r
++              \r
++              int currentChar = -1;\r
++              int runLength = 0;\r
++              \r
++              public BZip2OutputStream(Stream inStream) : this(inStream, 9)\r
++              {\r
++              }\r
++              \r
++              public BZip2OutputStream(Stream inStream, int inBlockSize)\r
++              {\r
++                      block    = null;\r
++                      quadrant = null;\r
++                      zptr     = null;\r
++                      ftab     = null;\r
++                      \r
++                      BsSetStream(inStream);\r
++                      \r
++                      workFactor = 50;\r
++                      if(inBlockSize > 9) {\r
++                              inBlockSize = 9;\r
++                      }\r
++                      if(inBlockSize < 1) {\r
++                              inBlockSize = 1;\r
++                      }\r
++                      blockSize100k = inBlockSize;\r
++                      AllocateCompressStructures();\r
++                      Initialize();\r
++                      InitBlock();\r
++              }\r
++              \r
++              public override void WriteByte(byte bv)\r
++              {\r
++                      int b = (256 + bv) % 256;\r
++                      if (currentChar != -1) {\r
++                              if (currentChar == b) {\r
++                                      runLength++;\r
++                                      if (runLength > 254) {\r
++                                              WriteRun();\r
++                                              currentChar = -1;\r
++                                              runLength = 0;\r
++                                      }\r
++                              } else {\r
++                                      WriteRun();\r
++                                      runLength = 1;\r
++                                      currentChar = b;\r
++                              }\r
++                      } else {\r
++                              currentChar = b;\r
++                              runLength++;\r
++                      }\r
++              }\r
++              \r
++              void WriteRun()\r
++              {\r
++                      if (last < allowableBlockSize) {\r
++                              inUse[currentChar] = true;\r
++                              for (int i = 0; i < runLength; i++) {\r
++                                      mCrc.Update(currentChar);\r
++                              }\r
++                              \r
++                              switch (runLength) {\r
++                                      case 1:\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              break;\r
++                                      case 2:\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              break;\r
++                                      case 3:\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              break;\r
++                                      default:\r
++                                              inUse[runLength - 4] = true;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)currentChar;\r
++                                              last++;\r
++                                              block[last + 1] = (byte)(runLength - 4);\r
++                                              break;\r
++                              }\r
++                      } else {\r
++                              EndBlock();\r
++                              InitBlock();\r
++                              WriteRun();\r
++                      }\r
++              }\r
++              \r
++              bool closed = false;\r
++              \r
++              public void Finalize()\r
++              {\r
++                      Close();\r
++              }\r
++              \r
++              public override void Close()\r
++              {\r
++                      if (closed) {\r
++                              return;\r
++                      }\r
++                      \r
++                      if (runLength > 0) {\r
++                              WriteRun();\r
++                      }\r
++                      \r
++                      currentChar = -1;\r
++                      EndBlock();\r
++                      EndCompression();\r
++                      closed = true;\r
++                      //                      super.close();\r
++                      Flush();\r
++                      baseStream.Close();\r
++              }\r
++              \r
++              public override void Flush()\r
++              {\r
++                      //                      super.flush();\r
++                      baseStream.Flush();\r
++              }\r
++              \r
++              uint blockCRC, combinedCRC;\r
++              \r
++              void Initialize()\r
++              {\r
++                      //                      bytesIn = 0;\r
++                      bytesOut = 0;\r
++                      nBlocksRandomised = 0;\r
++                      \r
++                      /*--- Write `magic' bytes h indicating file-format == huffmanised,\r
++                      followed by a digit indicating blockSize100k.\r
++                      ---*/\r
++                      BsPutUChar('B');     // -jr- 18-Nov-2003 added to match BZ2 1.02 header already in BZip class but that sux a lot\r
++                      BsPutUChar('Z');\r
++                      \r
++                      BsPutUChar('h');\r
++                      BsPutUChar('0' + blockSize100k);\r
++                      \r
++                      combinedCRC = 0;\r
++              }\r
++              \r
++              int allowableBlockSize;\r
++              \r
++              void InitBlock() \r
++              {\r
++                      //              blockNo++;\r
++                      mCrc.Reset();\r
++                      last = -1;\r
++                      //              ch = 0;\r
++                      \r
++                      for (int i = 0; i < 256; i++) {\r
++                              inUse[i] = false;\r
++                      }\r
++                      \r
++                      /*--- 20 is just a paranoia constant ---*/\r
++                      allowableBlockSize = BZip2Constants.baseBlockSize * blockSize100k - 20;\r
++              }\r
++              \r
++              void EndBlock()\r
++              {\r
++                      if (last < 0) {       //-jr- dont do anything for empty files, (makes empty files compatible with original Bzip)\r
++                              return;\r
++                      }\r
++                      \r
++                      blockCRC = (uint)mCrc.Value;\r
++                      combinedCRC = (combinedCRC << 1) | (combinedCRC >> 31);\r
++                      combinedCRC ^= blockCRC;\r
++                      \r
++                      /*-- sort the block and establish posn of original string --*/\r
++                      DoReversibleTransformation();\r
++                      \r
++                      /*--\r
++                      A 6-byte block header, the value chosen arbitrarily\r
++                      as 0x314159265359 :-).  A 32 bit value does not really\r
++                      give a strong enough guarantee that the value will not\r
++                      appear by chance in the compressed datastream.  Worst-case\r
++                      probability of this event, for a 900k block, is about\r
++                      2.0e-3 for 32 bits, 1.0e-5 for 40 bits and 4.0e-8 for 48 bits.\r
++                      For a compressed file of size 100Gb -- about 100000 blocks --\r
++                      only a 48-bit marker will do.  NB: normal compression/\r
++                      decompression do *not* rely on these statistical properties.\r
++                      They are only important when trying to recover blocks from\r
++                      damaged files.\r
++                      --*/\r
++                      BsPutUChar(0x31);\r
++                      BsPutUChar(0x41);\r
++                      BsPutUChar(0x59);\r
++                      BsPutUChar(0x26);\r
++                      BsPutUChar(0x53);\r
++                      BsPutUChar(0x59);\r
++                      \r
++                      /*-- Now the block's CRC, so it is in a known place. --*/\r
++                      BsPutint((int)blockCRC);\r
++                      \r
++                      /*-- Now a single bit indicating randomisation. --*/\r
++                      if (blockRandomised) {\r
++                              BsW(1,1);\r
++                              nBlocksRandomised++;\r
++                      } else {\r
++                              BsW(1,0);\r
++                      }\r
++                      \r
++                      /*-- Finally, block's contents proper. --*/\r
++                      MoveToFrontCodeAndSend();\r
++              }\r
++              \r
++              void EndCompression()\r
++              {\r
++                      /*--\r
++                      Now another magic 48-bit number, 0x177245385090, to\r
++                      indicate the end of the last block.  (sqrt(pi), if\r
++                      you want to know.  I did want to use e, but it contains\r
++                      too much repetition -- 27 18 28 18 28 46 -- for me\r
++                      to feel statistically comfortable.  Call me paranoid.)\r
++                      --*/\r
++                      BsPutUChar(0x17);\r
++                      BsPutUChar(0x72);\r
++                      BsPutUChar(0x45);\r
++                      BsPutUChar(0x38);\r
++                      BsPutUChar(0x50);\r
++                      BsPutUChar(0x90);\r
++                      \r
++                      BsPutint((int)combinedCRC);\r
++                      \r
++                      BsFinishedWithStream();\r
++              }\r
++              \r
++              void HbAssignCodes (int[] code, char[] length, int minLen, int maxLen, int alphaSize) \r
++              {\r
++                      int vec = 0;\r
++                      for (int n = minLen; n <= maxLen; ++n) {\r
++                              for (int i = 0; i < alphaSize; ++i) {\r
++                                      if (length[i] == n) {\r
++                                              code[i] = vec;\r
++                                              ++vec;\r
++                                      }\r
++                              }\r
++                              vec <<= 1;\r
++                      }\r
++              }\r
++              \r
++              void BsSetStream(Stream f) \r
++              {\r
++                      baseStream = f;\r
++                      bsLive = 0;\r
++                      bsBuff = 0;\r
++                      bytesOut = 0;\r
++              }\r
++              \r
++              void BsFinishedWithStream()\r
++              {\r
++                      while (bsLive > 0) \r
++                      {\r
++                              int ch = (bsBuff >> 24);\r
++                              baseStream.WriteByte((byte)ch); // write 8-bit\r
++                              bsBuff <<= 8;\r
++                              bsLive -= 8;\r
++                              bytesOut++;\r
++                      }\r
++              }\r
++              \r
++              void BsW(int n, int v)\r
++              {\r
++                      while (bsLive >= 8) {\r
++                              int ch = (bsBuff >> 24);\r
++                              baseStream.WriteByte((byte)ch); // write 8-bit\r
++                              bsBuff <<= 8;\r
++                              bsLive -= 8;\r
++                              ++bytesOut;\r
++                      }\r
++                      bsBuff |= (v << (32 - bsLive - n));\r
++                      bsLive += n;\r
++              }\r
++              \r
++              void BsPutUChar(int c)\r
++              {\r
++                      BsW(8, c);\r
++              }\r
++              \r
++              void BsPutint(int u)\r
++              {\r
++                      BsW(8, (u >> 24) & 0xFF);\r
++                      BsW(8, (u >> 16) & 0xFF);\r
++                      BsW(8, (u >>  8) & 0xFF);\r
++                      BsW(8,  u        & 0xFF);\r
++              }\r
++              \r
++              void BsPutIntVS(int numBits, int c)\r
++              {\r
++                      BsW(numBits, c);\r
++              }\r
++              \r
++              void SendMTFValues()\r
++              {\r
++                      char[][] len = new char[BZip2Constants.N_GROUPS][];\r
++                      for (int i = 0; i < BZip2Constants.N_GROUPS; ++i) {\r
++                              len[i] = new char[BZip2Constants.MAX_ALPHA_SIZE];\r
++                      }\r
++                      \r
++                      int gs, ge, totc, bt, bc, iter;\r
++                      int nSelectors = 0, alphaSize, minLen, maxLen, selCtr;\r
++                      int nGroups, nBytes;\r
++                      \r
++                      alphaSize = nInUse + 2;\r
++                      for (int t = 0; t < BZip2Constants.N_GROUPS; t++) {\r
++                              for (int v = 0; v < alphaSize; v++) {\r
++                                      len[t][v] = (char)GREATER_ICOST;\r
++                              }\r
++                      }\r
++                      \r
++                      /*--- Decide how many coding tables to use ---*/\r
++                      if (nMTF <= 0) {\r
++                              Panic();\r
++                      }\r
++                      \r
++                      if (nMTF < 200) {\r
++                              nGroups = 2;\r
++                      } else if (nMTF < 600) {\r
++                              nGroups = 3;\r
++                      } else if (nMTF < 1200) {\r
++                              nGroups = 4;\r
++                      } else if (nMTF < 2400) {\r
++                              nGroups = 5;\r
++                      } else {\r
++                              nGroups = 6;\r
++                      }\r
++                      \r
++                      /*--- Generate an initial set of coding tables ---*/ \r
++                      int nPart = nGroups;\r
++                      int remF  = nMTF;\r
++                      gs = 0;\r
++                      while (nPart > 0) {\r
++                              int tFreq = remF / nPart;\r
++                              int aFreq = 0;\r
++                              ge = gs - 1;\r
++                              while (aFreq < tFreq && ge < alphaSize - 1) {\r
++                                      ge++;\r
++                                      aFreq += mtfFreq[ge];\r
++                              }\r
++                              \r
++                              if (ge > gs && nPart != nGroups && nPart != 1 && ((nGroups - nPart) % 2 == 1)) {\r
++                                      aFreq -= mtfFreq[ge];\r
++                                      ge--;\r
++                              }\r
++                              \r
++                              for (int v = 0; v < alphaSize; v++) {\r
++                                      if (v >= gs && v <= ge) {\r
++                                              len[nPart - 1][v] = (char)LESSER_ICOST;\r
++                                      } else {\r
++                                              len[nPart - 1][v] = (char)GREATER_ICOST;\r
++                                      }\r
++                              }\r
++                              \r
++                              nPart--;\r
++                              gs = ge + 1;\r
++                              remF -= aFreq;\r
++                      }\r
++                      \r
++                      int[][] rfreq = new int[BZip2Constants.N_GROUPS][];\r
++                      for (int i = 0; i < BZip2Constants.N_GROUPS; ++i) {\r
++                              rfreq[i] = new int[BZip2Constants.MAX_ALPHA_SIZE];\r
++                      }\r
++                      \r
++                      int[]   fave = new int[BZip2Constants.N_GROUPS];\r
++                      short[] cost = new short[BZip2Constants.N_GROUPS];\r
++                      /*---\r
++                      Iterate up to N_ITERS times to improve the tables.\r
++                      ---*/\r
++                      for (iter = 0; iter < BZip2Constants.N_ITERS; ++iter) {\r
++                              for (int t = 0; t < nGroups; ++t) {\r
++                                      fave[t] = 0;\r
++                              }\r
++                              \r
++                              for (int t = 0; t < nGroups; ++t) {\r
++                                      for (int v = 0; v < alphaSize; ++v) {\r
++                                              rfreq[t][v] = 0;\r
++                                      }\r
++                              }\r
++                              \r
++                              nSelectors = 0;\r
++                              totc = 0;\r
++                              gs   = 0;\r
++                              while (true) {\r
++                                      /*--- Set group start & end marks. --*/\r
++                                      if (gs >= nMTF) {\r
++                                              break;\r
++                                      }\r
++                                      ge = gs + BZip2Constants.G_SIZE - 1;\r
++                                      if (ge >= nMTF) {\r
++                                              ge = nMTF - 1;\r
++                                      }\r
++                                      \r
++                                      /*--\r
++                                      Calculate the cost of this group as coded\r
++                                      by each of the coding tables.\r
++                                      --*/\r
++                                      for (int t = 0; t < nGroups; t++) {\r
++                                              cost[t] = 0;\r
++                                      }\r
++                                      \r
++                                      if (nGroups == 6) {\r
++                                              short cost0, cost1, cost2, cost3, cost4, cost5;\r
++                                              cost0 = cost1 = cost2 = cost3 = cost4 = cost5 = 0;\r
++                                              for (int i = gs; i <= ge; ++i) {\r
++                                                      short icv = szptr[i];\r
++                                                      cost0 += (short)len[0][icv];\r
++                                                      cost1 += (short)len[1][icv];\r
++                                                      cost2 += (short)len[2][icv];\r
++                                                      cost3 += (short)len[3][icv];\r
++                                                      cost4 += (short)len[4][icv];\r
++                                                      cost5 += (short)len[5][icv];\r
++                                              }\r
++                                              cost[0] = cost0;\r
++                                              cost[1] = cost1;\r
++                                              cost[2] = cost2;\r
++                                              cost[3] = cost3;\r
++                                              cost[4] = cost4;\r
++                                              cost[5] = cost5;\r
++                                      } else {\r
++                                              for (int i = gs; i <= ge; ++i) {\r
++                                                      short icv = szptr[i];\r
++                                                      for (int t = 0; t < nGroups; t++) {\r
++                                                              cost[t] += (short)len[t][icv];\r
++                                                      }\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      /*--\r
++                                      Find the coding table which is best for this group,\r
++                                      and record its identity in the selector table.\r
++                                      --*/\r
++                                      bc = 999999999;\r
++                                      bt = -1;\r
++                                      for (int t = 0; t < nGroups; ++t) {\r
++                                              if (cost[t] < bc) {\r
++                                                      bc = cost[t];\r
++                                                      bt = t;\r
++                                              }\r
++                                      }\r
++                                      totc += bc;\r
++                                      fave[bt]++;\r
++                                      selector[nSelectors] = (char)bt;\r
++                                      nSelectors++;\r
++                                      \r
++                                      /*--\r
++                                      Increment the symbol frequencies for the selected table.\r
++                                      --*/\r
++                                      for (int i = gs; i <= ge; ++i) {\r
++                                              ++rfreq[bt][szptr[i]];\r
++                                      }\r
++                                      \r
++                                      gs = ge+1;\r
++                              }\r
++                              \r
++                              /*--\r
++                              Recompute the tables based on the accumulated frequencies.\r
++                              --*/\r
++                              for (int t = 0; t < nGroups; ++t) {\r
++                                      HbMakeCodeLengths(len[t], rfreq[t], alphaSize, 20);\r
++                              }\r
++                      }\r
++                      \r
++                      rfreq = null;\r
++                      fave = null;\r
++                      cost = null;\r
++                      \r
++                      if (!(nGroups < 8)) {\r
++                              Panic();\r
++                      }\r
++                      if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / BZip2Constants.G_SIZE)))) {\r
++                              Panic();\r
++                      }\r
++                      \r
++                      /*--- Compute MTF values for the selectors. ---*/\r
++                      char[] pos = new char[BZip2Constants.N_GROUPS];\r
++                      char ll_i, tmp2, tmp;\r
++                      for (int i = 0; i < nGroups; i++) {\r
++                              pos[i] = (char)i;\r
++                      }\r
++                      for (int i = 0; i < nSelectors; i++) {\r
++                              ll_i = selector[i];\r
++                              int j = 0;\r
++                              tmp = pos[j];\r
++                              while (ll_i != tmp) {\r
++                                      j++;\r
++                                      tmp2 = tmp;\r
++                                      tmp = pos[j];\r
++                                      pos[j] = tmp2;\r
++                              }\r
++                              pos[0] = tmp;\r
++                              selectorMtf[i] = (char)j;\r
++                      }\r
++                      \r
++                      int[][] code = new int[BZip2Constants.N_GROUPS][];\r
++                      \r
++                      for (int i = 0; i < BZip2Constants.N_GROUPS; ++i) {\r
++                              code[i] = new int[BZip2Constants.MAX_ALPHA_SIZE];\r
++                      }\r
++                      \r
++                      /*--- Assign actual codes for the tables. --*/\r
++                      for (int t = 0; t < nGroups; t++) {\r
++                              minLen = 32;\r
++                              maxLen = 0;\r
++                              for (int i = 0; i < alphaSize; i++) {\r
++                                      if (len[t][i] > maxLen) {\r
++                                              maxLen = len[t][i];\r
++                                      }\r
++                                      if (len[t][i] < minLen) {\r
++                                              minLen = len[t][i];\r
++                                      }\r
++                              }\r
++                              if (maxLen > 20) {\r
++                                      Panic();\r
++                              }\r
++                              if (minLen < 1) {\r
++                                      Panic();\r
++                              }\r
++                              HbAssignCodes(code[t], len[t], minLen, maxLen, alphaSize);\r
++                      }\r
++                      \r
++                      /*--- Transmit the mapping table. ---*/\r
++                      bool[] inUse16 = new bool[16];\r
++                      for (int i = 0; i < 16; ++i) {\r
++                              inUse16[i] = false;\r
++                              for (int j = 0; j < 16; ++j) {\r
++                                      if (inUse[i * 16 + j]) {\r
++                                              inUse16[i] = true; \r
++                                      } // TODO : insert break;\r
++                              }\r
++                      }\r
++                      \r
++                      nBytes = bytesOut;\r
++                      for (int i = 0; i < 16; ++i) {\r
++                              if (inUse16[i]) {\r
++                                      BsW(1,1);\r
++                              } else {\r
++                                      BsW(1,0);\r
++                              }\r
++                      }\r
++                      \r
++                      for (int i = 0; i < 16; ++i) {\r
++                              if (inUse16[i]) {\r
++                                      for (int j = 0; j < 16; ++j) {\r
++                                              if (inUse[i * 16 + j]) {\r
++                                                      BsW(1,1);\r
++                                              } else {\r
++                                                      BsW(1,0);\r
++                                              }\r
++                                      }\r
++                              }\r
++                      }\r
++                      \r
++                      /*--- Now the selectors. ---*/\r
++                      nBytes = bytesOut;\r
++                      BsW(3, nGroups);\r
++                      BsW(15, nSelectors);\r
++                      for (int i = 0; i < nSelectors; ++i) {\r
++                              for (int j = 0; j < selectorMtf[i]; ++j) {\r
++                                      BsW(1,1);\r
++                              }\r
++                              BsW(1,0);\r
++                      }\r
++                      \r
++                      /*--- Now the coding tables. ---*/\r
++                      nBytes = bytesOut;\r
++                      \r
++                      for (int t = 0; t < nGroups; ++t) {\r
++                              int curr = len[t][0];\r
++                              BsW(5, curr);\r
++                              for (int i = 0; i < alphaSize; ++i) {\r
++                                      while (curr < len[t][i]) {\r
++                                              BsW(2, 2);\r
++                                              curr++; /* 10 */\r
++                                      }\r
++                                      while (curr > len[t][i]) {\r
++                                              BsW(2, 3);\r
++                                              curr--; /* 11 */\r
++                                      }\r
++                                      BsW (1, 0);\r
++                              }\r
++                      }\r
++                      \r
++                      /*--- And finally, the block data proper ---*/\r
++                      nBytes = bytesOut;\r
++                      selCtr = 0;\r
++                      gs = 0;\r
++                      while (true) {\r
++                              if (gs >= nMTF) {\r
++                                      break;\r
++                              }\r
++                              ge = gs + BZip2Constants.G_SIZE - 1;\r
++                              if (ge >= nMTF) {\r
++                                      ge = nMTF - 1;\r
++                              }\r
++                              \r
++                              for (int i = gs; i <= ge; i++) {\r
++                                      BsW(len[selector[selCtr]][szptr[i]], code[selector[selCtr]][szptr[i]]);\r
++                              }\r
++                              \r
++                              gs = ge + 1;\r
++                              ++selCtr;\r
++                      }\r
++                      if (!(selCtr == nSelectors)) {\r
++                              Panic();\r
++                      }\r
++              }\r
++              \r
++              void MoveToFrontCodeAndSend () \r
++              {\r
++                      BsPutIntVS(24, origPtr);\r
++                      GenerateMTFValues();\r
++                      SendMTFValues();\r
++              }\r
++              \r
++              Stream baseStream;\r
++              \r
++              void SimpleSort(int lo, int hi, int d) \r
++              {\r
++                      int i, j, h, bigN, hp;\r
++                      int v;\r
++                      \r
++                      bigN = hi - lo + 1;\r
++                      if (bigN < 2) {\r
++                              return;\r
++                      }\r
++                      \r
++                      hp = 0;\r
++                      while (incs[hp] < bigN) {\r
++                              hp++;\r
++                      }\r
++                      hp--;\r
++                      \r
++                      for (; hp >= 0; hp--) {\r
++                              h = incs[hp];\r
++                              \r
++                              i = lo + h;\r
++                              while (true) {\r
++                                      /*-- copy 1 --*/\r
++                                      if (i > hi)\r
++                                              break;\r
++                                      v = zptr[i];\r
++                                      j = i;\r
++                                      while (FullGtU(zptr[j-h]+d, v+d)) {\r
++                                              zptr[j] = zptr[j-h];\r
++                                              j = j - h;\r
++                                              if (j <= (lo + h - 1))\r
++                                                      break;\r
++                                      }\r
++                                      zptr[j] = v;\r
++                                      i++;\r
++                                      \r
++                                      /*-- copy 2 --*/\r
++                                      if (i > hi) {\r
++                                              break;\r
++                                      }\r
++                                      v = zptr[i];\r
++                                      j = i;\r
++                                      while (FullGtU ( zptr[j-h]+d, v+d )) {\r
++                                              zptr[j] = zptr[j-h];\r
++                                              j = j - h;\r
++                                              if (j <= (lo + h - 1)) {\r
++                                                      break;\r
++                                              }\r
++                                      }\r
++                                      zptr[j] = v;\r
++                                      i++;\r
++                                      \r
++                                      /*-- copy 3 --*/\r
++                                      if (i > hi) {\r
++                                              break;\r
++                                      }\r
++                                      v = zptr[i];\r
++                                      j = i;\r
++                                      while (FullGtU ( zptr[j-h]+d, v+d)) {\r
++                                              zptr[j] = zptr[j-h];\r
++                                              j = j - h;\r
++                                              if (j <= (lo + h - 1)) {\r
++                                                      break;\r
++                                              }\r
++                                      }\r
++                                      zptr[j] = v;\r
++                                      i++;\r
++                                      \r
++                                      if (workDone > workLimit && firstAttempt) {\r
++                                              return;\r
++                                      }\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              void Vswap(int p1, int p2, int n ) \r
++              {\r
++                      int temp = 0;\r
++                      while (n > 0) {\r
++                              temp = zptr[p1];\r
++                              zptr[p1] = zptr[p2];\r
++                              zptr[p2] = temp;\r
++                              p1++;\r
++                              p2++;\r
++                              n--;\r
++                      }\r
++              }\r
++              \r
++              byte Med3(byte a, byte b, byte c ) \r
++              {\r
++                      byte t;\r
++                      if (a > b) {\r
++                              t = a;\r
++                              a = b;\r
++                              b = t;\r
++                      }\r
++                      if (b > c) {\r
++                              t = b;\r
++                              b = c;\r
++                              c = t;\r
++                      }\r
++                      if (a > b) {\r
++                              b = a;\r
++                      }\r
++                      return b;\r
++              }\r
++              \r
++              class StackElem \r
++              {\r
++                      public int ll;\r
++                      public int hh;\r
++                      public int dd;\r
++              }\r
++              \r
++              void QSort3(int loSt, int hiSt, int dSt) \r
++              {\r
++                      int unLo, unHi, ltLo, gtHi, med, n, m;\r
++                      int sp, lo, hi, d;\r
++                      StackElem[] stack = new StackElem[QSORT_STACK_SIZE];\r
++                      for (int count = 0; count < QSORT_STACK_SIZE; count++) {\r
++                              stack[count] = new StackElem();\r
++                      }\r
++                      \r
++                      sp = 0;\r
++                      \r
++                      stack[sp].ll = loSt;\r
++                      stack[sp].hh = hiSt;\r
++                      stack[sp].dd = dSt;\r
++                      sp++;\r
++                      \r
++                      while (sp > 0) {\r
++                              if (sp >= QSORT_STACK_SIZE) {\r
++                                      Panic();\r
++                              }\r
++                              \r
++                              sp--;\r
++                              lo = stack[sp].ll;\r
++                              hi = stack[sp].hh;\r
++                              d = stack[sp].dd;\r
++                              \r
++                              if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) {\r
++                                      SimpleSort(lo, hi, d);\r
++                                      if (workDone > workLimit && firstAttempt) {\r
++                                              return;\r
++                                      }\r
++                                      continue;\r
++                              }\r
++                              \r
++                              med = Med3(block[zptr[lo] + d + 1],\r
++                                         block[zptr[hi            ] + d  + 1],\r
++                                         block[zptr[(lo + hi) >> 1] + d + 1]);\r
++                              \r
++                              unLo = ltLo = lo;\r
++                              unHi = gtHi = hi;\r
++                              \r
++                              while (true) {\r
++                                      while (true) {\r
++                                              if (unLo > unHi) {\r
++                                                      break;\r
++                                              }\r
++                                              n = ((int)block[zptr[unLo]+d + 1]) - med;\r
++                                              if (n == 0) {\r
++                                                      int temp = 0;\r
++                                                      temp = zptr[unLo];\r
++                                                      zptr[unLo] = zptr[ltLo];\r
++                                                      zptr[ltLo] = temp;\r
++                                                      ltLo++;\r
++                                                      unLo++;\r
++                                                      continue;\r
++                                              }\r
++                                              if (n >  0) {\r
++                                                      break;\r
++                                              }\r
++                                              unLo++;\r
++                                      }\r
++                                      while (true) {\r
++                                              if (unLo > unHi) {\r
++                                                      break;\r
++                                              }\r
++                                              n = ((int)block[zptr[unHi]+d + 1]) - med;\r
++                                              if (n == 0) {\r
++                                                      int temp = 0;\r
++                                                      temp = zptr[unHi];\r
++                                                      zptr[unHi] = zptr[gtHi];\r
++                                                      zptr[gtHi] = temp;\r
++                                                      gtHi--;\r
++                                                      unHi--;\r
++                                                      continue;\r
++                                              }\r
++                                              if (n <  0) {\r
++                                                      break;\r
++                                              }\r
++                                              unHi--;\r
++                                      }\r
++                                      if (unLo > unHi) {\r
++                                              break;\r
++                                      }\r
++                                      {\r
++                                              int temp = zptr[unLo];\r
++                                              zptr[unLo] = zptr[unHi];\r
++                                              zptr[unHi] = temp;\r
++                                              unLo++;\r
++                                              unHi--;\r
++                                      }\r
++                              }\r
++                              \r
++                              if (gtHi < ltLo) {\r
++                                      stack[sp].ll = lo;\r
++                                      stack[sp].hh = hi;\r
++                                      stack[sp].dd = d+1;\r
++                                      sp++;\r
++                                      continue;\r
++                              }\r
++                              \r
++                              n = ((ltLo-lo) < (unLo-ltLo)) ? (ltLo-lo) : (unLo-ltLo);\r
++                              Vswap(lo, unLo-n, n);\r
++                              m = ((hi-gtHi) < (gtHi-unHi)) ? (hi-gtHi) : (gtHi-unHi);\r
++                              Vswap(unLo, hi-m+1, m);\r
++                              \r
++                              n = lo + unLo - ltLo - 1;\r
++                              m = hi - (gtHi - unHi) + 1;\r
++                              \r
++                              stack[sp].ll = lo;\r
++                              stack[sp].hh = n;\r
++                              stack[sp].dd = d;\r
++                              sp++;\r
++                              \r
++                              stack[sp].ll = n + 1;\r
++                              stack[sp].hh = m - 1;\r
++                              stack[sp].dd = d+1;\r
++                              sp++;\r
++                              \r
++                              stack[sp].ll = m;\r
++                              stack[sp].hh = hi;\r
++                              stack[sp].dd = d;\r
++                              sp++;\r
++                      }\r
++              }\r
++              \r
++              void MainSort() \r
++              {\r
++                      int i, j, ss, sb;\r
++                      int[] runningOrder = new int[256];\r
++                      int[] copy = new int[256];\r
++                      bool[] bigDone = new bool[256];\r
++                      int c1, c2;\r
++                      int numQSorted;\r
++                      \r
++                      /*--\r
++                      In the various block-sized structures, live data runs\r
++                      from 0 to last+NUM_OVERSHOOT_BYTES inclusive.  First,\r
++                      set up the overshoot area for block.\r
++                      --*/\r
++                      \r
++                      //   if (verbosity >= 4) fprintf ( stderr, "        sort initialise ...\n" );\r
++                      for (i = 0; i < BZip2Constants.NUM_OVERSHOOT_BYTES; i++) {\r
++                              block[last + i + 2] = block[(i % (last + 1)) + 1];\r
++                      }\r
++                      for (i = 0; i <= last + BZip2Constants.NUM_OVERSHOOT_BYTES; i++) {\r
++                              quadrant[i] = 0;\r
++                      }\r
++                      \r
++                      block[0] = (byte)(block[last + 1]);\r
++                      \r
++                      if (last < 4000) {\r
++                              /*--\r
++                              Use simpleSort(), since the full sorting mechanism\r
++                              has quite a large constant overhead.\r
++                              --*/\r
++                              for (i = 0; i <= last; i++) {\r
++                                      zptr[i] = i;\r
++                              }\r
++                              firstAttempt = false;\r
++                              workDone = workLimit = 0;\r
++                              SimpleSort(0, last, 0);\r
++                      } else {\r
++                              numQSorted = 0;\r
++                              for (i = 0; i <= 255; i++) {\r
++                                      bigDone[i] = false;\r
++                              }\r
++                              for (i = 0; i <= 65536; i++) {\r
++                                      ftab[i] = 0;\r
++                              }\r
++                              \r
++                              c1 = block[0];\r
++                              for (i = 0; i <= last; i++) {\r
++                                      c2 = block[i + 1];\r
++                                      ftab[(c1 << 8) + c2]++;\r
++                                      c1 = c2;\r
++                              }\r
++                              \r
++                              for (i = 1; i <= 65536; i++) {\r
++                                      ftab[i] += ftab[i - 1];\r
++                              }\r
++                              \r
++                              c1 = block[1];\r
++                              for (i = 0; i < last; i++) {\r
++                                      c2 = block[i + 2];\r
++                                      j = (c1 << 8) + c2;\r
++                                      c1 = c2;\r
++                                      ftab[j]--;\r
++                                      zptr[ftab[j]] = i;\r
++                              }\r
++                              \r
++                              j = ((block[last + 1]) << 8) + (block[1]);\r
++                              ftab[j]--;\r
++                              zptr[ftab[j]] = last;\r
++                              \r
++                              /*--\r
++                              Now ftab contains the first loc of every small bucket.\r
++                              Calculate the running order, from smallest to largest\r
++                              big bucket.\r
++                              --*/\r
++                              \r
++                              for (i = 0; i <= 255; i++) {\r
++                                      runningOrder[i] = i;\r
++                              }\r
++                              \r
++                              int vv;\r
++                              int h = 1;\r
++                              do {\r
++                                      h = 3 * h + 1;\r
++                              } while (h <= 256);\r
++                              do {\r
++                                      h = h / 3;\r
++                                      for (i = h; i <= 255; i++) {\r
++                                              vv = runningOrder[i];\r
++                                              j = i;\r
++                                              while ((ftab[((runningOrder[j-h])+1) << 8] - ftab[(runningOrder[j-h]) << 8]) > (ftab[((vv)+1) << 8] - ftab[(vv) << 8])) {\r
++                                                      runningOrder[j] = runningOrder[j-h];\r
++                                                      j = j - h;\r
++                                                      if (j <= (h - 1)) {\r
++                                                              break;\r
++                                                      }\r
++                                              }\r
++                                              runningOrder[j] = vv;\r
++                                      }\r
++                              } while (h != 1);\r
++                              \r
++                              /*--\r
++                              The main sorting loop.\r
++                              --*/\r
++                              for (i = 0; i <= 255; i++) {\r
++                                      \r
++                                      /*--\r
++                                      Process big buckets, starting with the least full.\r
++                                      --*/\r
++                                      ss = runningOrder[i];\r
++                                      \r
++                                      /*--\r
++                                      Complete the big bucket [ss] by quicksorting\r
++                                      any unsorted small buckets [ss, j].  Hopefully\r
++                                      previous pointer-scanning phases have already\r
++                                      completed many of the small buckets [ss, j], so\r
++                                      we don't have to sort them at all.\r
++                                      --*/\r
++                                      for (j = 0; j <= 255; j++) {\r
++                                              sb = (ss << 8) + j;\r
++                                              if(!((ftab[sb] & SETMASK) == SETMASK)) {\r
++                                                      int lo = ftab[sb] & CLEARMASK;\r
++                                                      int hi = (ftab[sb+1] & CLEARMASK) - 1;\r
++                                                      if (hi > lo) {\r
++                                                              QSort3(lo, hi, 2);\r
++                                                              numQSorted += (hi - lo + 1);\r
++                                                              if (workDone > workLimit && firstAttempt) {\r
++                                                                      return;\r
++                                                              }\r
++                                                      }\r
++                                                      ftab[sb] |= SETMASK;\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      /*--\r
++                                      The ss big bucket is now done.  Record this fact,\r
++                                      and update the quadrant descriptors.  Remember to\r
++                                      update quadrants in the overshoot area too, if\r
++                                      necessary.  The "if (i < 255)" test merely skips\r
++                                      this updating for the last bucket processed, since\r
++                                      updating for the last bucket is pointless.\r
++                                      --*/\r
++                                      bigDone[ss] = true;\r
++                                      \r
++                                      if (i < 255) {\r
++                                              int bbStart  = ftab[ss << 8] & CLEARMASK;\r
++                                              int bbSize   = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;\r
++                                              int shifts   = 0;\r
++                                              \r
++                                              while ((bbSize >> shifts) > 65534) {\r
++                                                      shifts++;\r
++                                              }\r
++                                              \r
++                                              for (j = 0; j < bbSize; j++) {\r
++                                                      int a2update = zptr[bbStart + j];\r
++                                                      int qVal = (j >> shifts);\r
++                                                      quadrant[a2update] = qVal;\r
++                                                      if (a2update < BZip2Constants.NUM_OVERSHOOT_BYTES) {\r
++                                                              quadrant[a2update + last + 1] = qVal;\r
++                                                      }\r
++                                              }\r
++                                              \r
++                                              if (!(((bbSize-1) >> shifts) <= 65535)) {\r
++                                                      Panic();\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      /*--\r
++                                      Now scan this big bucket so as to synthesise the\r
++                                      sorted order for small buckets [t, ss] for all t != ss.\r
++                                      --*/\r
++                                      for (j = 0; j <= 255; j++) {\r
++                                              copy[j] = ftab[(j << 8) + ss] & CLEARMASK;\r
++                                      }\r
++                                      \r
++                                      for (j = ftab[ss << 8] & CLEARMASK; j < (ftab[(ss+1) << 8] & CLEARMASK); j++) {\r
++                                              c1 = block[zptr[j]];\r
++                                              if (!bigDone[c1]) {\r
++                                                      zptr[copy[c1]] = zptr[j] == 0 ? last : zptr[j] - 1;\r
++                                                      copy[c1] ++;\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      for (j = 0; j <= 255; j++) {\r
++                                              ftab[(j << 8) + ss] |= SETMASK;\r
++                                      }\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              void RandomiseBlock() \r
++              {\r
++                      int i;\r
++                      int rNToGo = 0;\r
++                      int rTPos  = 0;\r
++                      for (i = 0; i < 256; i++) {\r
++                              inUse[i] = false;\r
++                      }\r
++                      \r
++                      for (i = 0; i <= last; i++) {\r
++                              if (rNToGo == 0) {\r
++                                      rNToGo = (int)BZip2Constants.rNums[rTPos];\r
++                                      rTPos++;\r
++                                      if (rTPos == 512) {\r
++                                              rTPos = 0;\r
++                                      }\r
++                              }\r
++                              rNToGo--;\r
++                              block[i + 1] ^= (byte)((rNToGo == 1) ? 1 : 0);\r
++                              // handle 16 bit signed numbers\r
++                              block[i + 1] &= 0xFF;\r
++                              \r
++                              inUse[block[i + 1]] = true;\r
++                      }\r
++              }\r
++              \r
++              void DoReversibleTransformation() \r
++              {\r
++                      workLimit = workFactor * last;\r
++                      workDone = 0;\r
++                      blockRandomised = false;\r
++                      firstAttempt = true;\r
++                      \r
++                      MainSort();\r
++                      \r
++                      if (workDone > workLimit && firstAttempt) {\r
++                              RandomiseBlock();\r
++                              workLimit = workDone = 0;\r
++                              blockRandomised = true;\r
++                              firstAttempt = false;\r
++                              MainSort();\r
++                      }\r
++                      \r
++                      origPtr = -1;\r
++                      for (int i = 0; i <= last; i++) {\r
++                              if (zptr[i] == 0) {\r
++                                      origPtr = i;\r
++                                      break;\r
++                              }\r
++                      }\r
++                      \r
++                      if (origPtr == -1) {\r
++                              Panic();\r
++                      }\r
++              }\r
++              \r
++              bool FullGtU(int i1, int i2) \r
++              {\r
++                      int k;\r
++                      byte c1, c2;\r
++                      int s1, s2;\r
++                      \r
++                      c1 = block[i1 + 1];\r
++                      c2 = block[i2 + 1];\r
++                      if (c1 != c2) {\r
++                              return c1 > c2;\r
++                      }\r
++                      i1++;\r
++                      i2++;\r
++                      \r
++                      c1 = block[i1 + 1];\r
++                      c2 = block[i2 + 1];\r
++                      if (c1 != c2) {\r
++                              return c1 > c2;\r
++                      }\r
++                      i1++;\r
++                      i2++;\r
++                      \r
++                      c1 = block[i1 + 1];\r
++                      c2 = block[i2 + 1];\r
++                      if (c1 != c2) {\r
++                              return c1 > c2;\r
++                      }\r
++                      i1++;\r
++                      i2++;\r
++                      \r
++                      c1 = block[i1 + 1];\r
++                      c2 = block[i2 + 1];\r
++                      if (c1 != c2) {\r
++                              return c1 > c2;\r
++                      }\r
++                      i1++;\r
++                      i2++;\r
++                      \r
++                      c1 = block[i1 + 1];\r
++                      c2 = block[i2 + 1];\r
++                      if (c1 != c2) {\r
++                              return c1 > c2;\r
++                      }\r
++                      i1++;\r
++                      i2++;\r
++                      \r
++                      c1 = block[i1 + 1];\r
++                      c2 = block[i2 + 1];\r
++                      if (c1 != c2) {\r
++                              return c1 > c2;\r
++                      }\r
++                      i1++;\r
++                      i2++;\r
++                      \r
++                      k = last + 1;\r
++                      \r
++                      do {\r
++                              c1 = block[i1 + 1];\r
++                              c2 = block[i2 + 1];\r
++                              if (c1 != c2) {\r
++                                      return c1 > c2;\r
++                              }\r
++                              s1 = quadrant[i1];\r
++                              s2 = quadrant[i2];\r
++                              if (s1 != s2) {\r
++                                      return s1 > s2;\r
++                              }\r
++                              i1++;\r
++                              i2++;\r
++                              \r
++                              c1 = block[i1 + 1];\r
++                              c2 = block[i2 + 1];\r
++                              if (c1 != c2) {\r
++                                      return c1 > c2;\r
++                              }\r
++                              s1 = quadrant[i1];\r
++                              s2 = quadrant[i2];\r
++                              if (s1 != s2) {\r
++                                      return s1 > s2;\r
++                              }\r
++                              i1++;\r
++                              i2++;\r
++                              \r
++                              c1 = block[i1 + 1];\r
++                              c2 = block[i2 + 1];\r
++                              if (c1 != c2) {\r
++                                      return c1 > c2;\r
++                              }\r
++                              s1 = quadrant[i1];\r
++                              s2 = quadrant[i2];\r
++                              if (s1 != s2) {\r
++                                      return s1 > s2;\r
++                              }\r
++                              i1++;\r
++                              i2++;\r
++                              \r
++                              c1 = block[i1 + 1];\r
++                              c2 = block[i2 + 1];\r
++                              if (c1 != c2) {\r
++                                      return c1 > c2;\r
++                              }\r
++                              s1 = quadrant[i1];\r
++                              s2 = quadrant[i2];\r
++                              if (s1 != s2) {\r
++                                      return s1 > s2;\r
++                              }\r
++                              i1++;\r
++                              i2++;\r
++                              \r
++                              if (i1 > last) {\r
++                                      i1 -= last;\r
++                                      i1--;\r
++                              }\r
++                              if (i2 > last) {\r
++                                      i2 -= last;\r
++                                      i2--;\r
++                              }\r
++                              \r
++                              k -= 4;\r
++                              ++workDone;\r
++                      } while (k >= 0);\r
++                      \r
++                      return false;\r
++              }\r
++              \r
++              /*--\r
++              Knuth's increments seem to work better\r
++              than Incerpi-Sedgewick here.  Possibly\r
++              because the number of elems to sort is\r
++              usually small, typically <= 20.\r
++              --*/\r
++              readonly int[] incs = new int[] { \r
++                      1, 4, 13, 40, 121, 364, 1093, 3280,\r
++                      9841, 29524, 88573, 265720,\r
++                      797161, 2391484 \r
++              };\r
++              \r
++              void AllocateCompressStructures() \r
++              {\r
++                      int n = BZip2Constants.baseBlockSize * blockSize100k;\r
++                      block = new byte[(n + 1 + BZip2Constants.NUM_OVERSHOOT_BYTES)];\r
++                      quadrant = new int[(n + BZip2Constants.NUM_OVERSHOOT_BYTES)];\r
++                      zptr = new int[n];\r
++                      ftab = new int[65537];\r
++                      \r
++                      if (block == null || quadrant == null || zptr == null  || ftab == null) {\r
++                              //              int totalDraw = (n + 1 + NUM_OVERSHOOT_BYTES) + (n + NUM_OVERSHOOT_BYTES) + n + 65537;\r
++                              //              compressOutOfMemory ( totalDraw, n );\r
++                      }\r
++                      \r
++                      /*\r
++                      The back end needs a place to store the MTF values\r
++                      whilst it calculates the coding tables.  We could\r
++                      put them in the zptr array.  However, these values\r
++                      will fit in a short, so we overlay szptr at the\r
++                      start of zptr, in the hope of reducing the number\r
++                      of cache misses induced by the multiple traversals\r
++                      of the MTF values when calculating coding tables.\r
++                      Seems to improve compression speed by about 1%.\r
++                      */\r
++                      //      szptr = zptr;\r
++                      \r
++                      \r
++                      szptr = new short[2 * n];\r
++              }\r
++              \r
++              void GenerateMTFValues() \r
++              {\r
++                      char[] yy = new char[256];\r
++                      int  i, j;\r
++                      char tmp;\r
++                      char tmp2;\r
++                      int zPend;\r
++                      int wr;\r
++                      int EOB;\r
++                      \r
++                      MakeMaps();\r
++                      EOB = nInUse+1;\r
++                      \r
++                      for (i = 0; i <= EOB; i++) {\r
++                              mtfFreq[i] = 0;\r
++                      }\r
++                      \r
++                      wr = 0;\r
++                      zPend = 0;\r
++                      for (i = 0; i < nInUse; i++) {\r
++                              yy[i] = (char) i;\r
++                      }\r
++                      \r
++                      \r
++                      for (i = 0; i <= last; i++) {\r
++                              char ll_i;\r
++                              \r
++                              ll_i = unseqToSeq[block[zptr[i]]];\r
++                              \r
++                              j = 0;\r
++                              tmp = yy[j];\r
++                              while (ll_i != tmp) {\r
++                                      j++;\r
++                                      tmp2 = tmp;\r
++                                      tmp = yy[j];\r
++                                      yy[j] = tmp2;\r
++                              }\r
++                              yy[0] = tmp;\r
++                              \r
++                              if (j == 0) {\r
++                                      zPend++;\r
++                              } else {\r
++                                      if (zPend > 0) {\r
++                                              zPend--;\r
++                                              while (true) {\r
++                                                      switch (zPend % 2) {\r
++                                                              case 0:\r
++                                                                      szptr[wr] = (short)BZip2Constants.RUNA;\r
++                                                                      wr++;\r
++                                                                      mtfFreq[BZip2Constants.RUNA]++;\r
++                                                                      break;\r
++                                                              case 1:\r
++                                                                      szptr[wr] = (short)BZip2Constants.RUNB;\r
++                                                                      wr++;\r
++                                                                      mtfFreq[BZip2Constants.RUNB]++;\r
++                                                                      break;\r
++                                                      }\r
++                                                      if (zPend < 2) {\r
++                                                              break;\r
++                                                      }\r
++                                                      zPend = (zPend - 2) / 2;\r
++                                              }\r
++                                              zPend = 0;\r
++                                      }\r
++                                      szptr[wr] = (short)(j + 1);\r
++                                      wr++;\r
++                                      mtfFreq[j + 1]++;\r
++                              }\r
++                      }\r
++                      \r
++                      if (zPend > 0) {\r
++                              zPend--;\r
++                              while (true) {\r
++                                      switch (zPend % 2) {\r
++                                              case 0:\r
++                                                      szptr[wr] = (short)BZip2Constants.RUNA;\r
++                                                      wr++;\r
++                                                      mtfFreq[BZip2Constants.RUNA]++;\r
++                                                      break;\r
++                                              case 1:\r
++                                                      szptr[wr] = (short)BZip2Constants.RUNB;\r
++                                                      wr++;\r
++                                                      mtfFreq[BZip2Constants.RUNB]++;\r
++                                                      break;\r
++                                      }\r
++                                      if (zPend < 2) {\r
++                                              break;\r
++                                      }\r
++                                      zPend = (zPend - 2) / 2;\r
++                              }\r
++                      }\r
++                      \r
++                      szptr[wr] = (short)EOB;\r
++                      wr++;\r
++                      mtfFreq[EOB]++;\r
++                      \r
++                      nMTF = wr;\r
++              }\r
++      }\r
++}\r
++\r
++/* This file was derived from a file containing under this license:\r
++ * \r
++ * This file is a part of bzip2 and/or libbzip2, a program and\r
++ * library for lossless, block-sorting data compression.\r
++ * \r
++ * Copyright (C) 1996-1998 Julian R Seward.  All rights reserved.\r
++ * \r
++ * Redistribution and use in source and binary forms, with or without\r
++ * modification, are permitted provided that the following conditions\r
++ * are met:\r
++ * \r
++ * 1. Redistributions of source code must retain the above copyright\r
++ * notice, this list of conditions and the following disclaimer.\r
++ * \r
++ * 2. The origin of this software must not be misrepresented; you must \r
++ * not claim that you wrote the original software.  If you use this \r
++ * software in a product, an acknowledgment in the product \r
++ * documentation would be appreciated but is not required.\r
++ * \r
++ * 3. Altered source versions must be plainly marked as such, and must\r
++ * not be misrepresented as being the original software.\r
++ * \r
++ * 4. The name of the author may not be used to endorse or promote \r
++ * products derived from this software without specific prior written \r
++ * permission.\r
++ * \r
++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
++ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
++ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
++ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
++ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
++ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
++ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
++ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
++ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
++ * \r
++ * Java version ported by Keiron Liddle, Aftex Software <keiron@aftexsw.com> 1999-2001\r
++ */\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..514b0719bf6acaa0de5b8117e2f1dff5f10cacb4
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,10 @@@
++2004-06-24  Raja R Harinath  <rharinath@novell.com>
++
++      * AssemblyInfo.cs (AssemblyVersion): Set different version for the
++      net_2_0 profile.
++
++2004-05-28  Duncan Mak  <duncan@ximian.com>
++
++      * AssemblyInfo.cs: Use the new SharpZipLib.pub.
++      * Zip/Compression/DeflaterHuffman.cs (FlushBlock): Add some
++      parenthesis to help the generics compiler read this source.
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..220dcbafa0c5264b886277fb597b587387eb6f91
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,200 @@@
++// Adler32.cs - Computes Adler32 data checksum of a data stream\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Checksums \r
++{\r
++      \r
++      /// <summary>\r
++      /// Computes Adler32 checksum for a stream of data. An Adler32\r
++      /// checksum is not as reliable as a CRC32 checksum, but a lot faster to\r
++      /// compute.\r
++      /// \r
++      /// The specification for Adler32 may be found in RFC 1950.\r
++      /// ZLIB Compressed Data Format Specification version 3.3)\r
++      /// \r
++      /// \r
++      /// From that document:\r
++      /// \r
++      ///      "ADLER32 (Adler-32 checksum)\r
++      ///       This contains a checksum value of the uncompressed data\r
++      ///       (excluding any dictionary data) computed according to Adler-32\r
++      ///       algorithm. This algorithm is a 32-bit extension and improvement\r
++      ///       of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073\r
++      ///       standard.\r
++      /// \r
++      ///       Adler-32 is composed of two sums accumulated per byte: s1 is\r
++      ///       the sum of all bytes, s2 is the sum of all s1 values. Both sums\r
++      ///       are done modulo 65521. s1 is initialized to 1, s2 to zero.  The\r
++      ///       Adler-32 checksum is stored as s2*65536 + s1 in most-\r
++      ///       significant-byte first (network) order."\r
++      /// \r
++      ///  "8.2. The Adler-32 algorithm\r
++      /// \r
++      ///    The Adler-32 algorithm is much faster than the CRC32 algorithm yet\r
++      ///    still provides an extremely low probability of undetected errors.\r
++      /// \r
++      ///    The modulo on unsigned long accumulators can be delayed for 5552\r
++      ///    bytes, so the modulo operation time is negligible.  If the bytes\r
++      ///    are a, b, c, the second sum is 3a + 2b + c + 3, and so is position\r
++      ///    and order sensitive, unlike the first sum, which is just a\r
++      ///    checksum.  That 65521 is prime is important to avoid a possible\r
++      ///    large class of two-byte errors that leave the check unchanged.\r
++      ///    (The Fletcher checksum uses 255, which is not prime and which also\r
++      ///    makes the Fletcher check insensitive to single byte changes 0 -\r
++      ///    255.)\r
++      /// \r
++      ///    The sum s1 is initialized to 1 instead of zero to make the length\r
++      ///    of the sequence part of s2, so that the length does not have to be\r
++      ///    checked separately. (Any sequence of zeroes has a Fletcher\r
++      ///    checksum of zero.)"\r
++      /// </summary>\r
++      /// <see cref="ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream"/>\r
++      /// <see cref="ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream"/>\r
++      public sealed class Adler32 : IChecksum\r
++      {\r
++              /// <summary>\r
++              /// largest prime smaller than 65536\r
++              /// </summary>\r
++              readonly static uint BASE = 65521;\r
++              \r
++              uint checksum;\r
++              \r
++              /// <summary>\r
++              /// Returns the Adler32 data checksum computed so far.\r
++              /// </summary>\r
++              public long Value {\r
++                      get {\r
++                              return checksum;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new instance of the <code>Adler32</code> class.\r
++              /// The checksum starts off with a value of 1.\r
++              /// </summary>\r
++              public Adler32()\r
++              {\r
++                      Reset();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Resets the Adler32 checksum to the initial value.\r
++              /// </summary>\r
++              public void Reset()\r
++              {\r
++                      checksum = 1; //Initialize to 1\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Updates the checksum with the byte b.\r
++              /// </summary>\r
++              /// <param name="bval">\r
++              /// the data value to add. The high byte of the int is ignored.\r
++              /// </param>\r
++              public void Update(int bval)\r
++              {\r
++                      //We could make a length 1 byte array and call update again, but I\r
++                      //would rather not have that overhead\r
++                      uint s1 = checksum & 0xFFFF;\r
++                      uint s2 = checksum >> 16;\r
++                      \r
++                      s1 = (s1 + ((uint)bval & 0xFF)) % BASE;\r
++                      s2 = (s1 + s2) % BASE;\r
++                      \r
++                      checksum = (s2 << 16) + s1;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Updates the checksum with the bytes taken from the array.\r
++              /// </summary>\r
++              /// <param name="buffer">\r
++              /// buffer an array of bytes\r
++              /// </param>\r
++              public void Update(byte[] buffer)\r
++              {\r
++                      Update(buffer, 0, buffer.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Updates the checksum with the bytes taken from the array.\r
++              /// </summary>\r
++              /// <param name="buf">\r
++              /// an array of bytes\r
++              /// </param>\r
++              /// <param name="off">\r
++              /// the start of the data used for this update\r
++              /// </param>\r
++              /// <param name="len">\r
++              /// the number of bytes to use for this update\r
++              /// </param>\r
++              public void Update(byte[] buf, int off, int len)\r
++              {\r
++                      if (buf == null) {\r
++                              throw new ArgumentNullException("buf");\r
++                      }\r
++                      \r
++                      if (off < 0 || len < 0 || off + len > buf.Length) {\r
++                              throw new ArgumentOutOfRangeException();\r
++                      }\r
++                      \r
++                      //(By Per Bothner)\r
++                      uint s1 = checksum & 0xFFFF;\r
++                      uint s2 = checksum >> 16;\r
++                      \r
++                      while (len > 0) {\r
++                              // We can defer the modulo operation:\r
++                              // s1 maximally grows from 65521 to 65521 + 255 * 3800\r
++                              // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31\r
++                              int n = 3800;\r
++                              if (n > len) {\r
++                                      n = len;\r
++                              }\r
++                              len -= n;\r
++                              while (--n >= 0) {\r
++                                      s1 = s1 + (uint)(buf[off++] & 0xFF);\r
++                                      s2 = s2 + s1;\r
++                              }\r
++                              s1 %= BASE;\r
++                              s2 %= BASE;\r
++                      }\r
++                      \r
++                      checksum = (s2 << 16) | s1;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a78ad4c29f6db9da583513a106a92f972858fdff
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,211 @@@
++// CRC32.cs - Computes CRC32 data checksum of a data stream\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Checksums \r
++{\r
++      \r
++      /// <summary>\r
++      /// Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:\r
++      /// x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.\r
++      ///\r
++      /// Polynomials over GF(2) are represented in binary, one bit per coefficient,\r
++      /// with the lowest powers in the most significant bit.  Then adding polynomials\r
++      /// is just exclusive-or, and multiplying a polynomial by x is a right shift by\r
++      /// one.  If we call the above polynomial p, and represent a byte as the\r
++      /// polynomial q, also with the lowest power in the most significant bit (so the\r
++      /// byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,\r
++      /// where a mod b means the remainder after dividing a by b.\r
++      ///\r
++      /// This calculation is done using the shift-register method of multiplying and\r
++      /// taking the remainder.  The register is initialized to zero, and for each\r
++      /// incoming bit, x^32 is added mod p to the register if the bit is a one (where\r
++      /// x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by\r
++      /// x (which is shifting right by one and adding x^32 mod p if the bit shifted\r
++      /// out is a one).  We start with the highest power (least significant bit) of\r
++      /// q and repeat for all eight bits of q.\r
++      ///\r
++      /// The table is simply the CRC of all possible eight bit values.  This is all\r
++      /// the information needed to generate CRC's on data a byte at a time for all\r
++      /// combinations of CRC register values and incoming bytes.\r
++      /// </summary>\r
++      public sealed class Crc32 : IChecksum\r
++      {\r
++              readonly static uint CrcSeed = 0xFFFFFFFF;\r
++              \r
++              readonly static uint[] CrcTable = new uint[] {\r
++                      0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,\r
++                      0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,\r
++                      0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,\r
++                      0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,\r
++                      0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856,\r
++                      0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,\r
++                      0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,\r
++                      0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,\r
++                      0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,\r
++                      0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A,\r
++                      0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599,\r
++                      0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,\r
++                      0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190,\r
++                      0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,\r
++                      0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E,\r
++                      0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,\r
++                      0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED,\r
++                      0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,\r
++                      0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,\r
++                      0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,\r
++                      0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,\r
++                      0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,\r
++                      0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010,\r
++                      0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,\r
++                      0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17,\r
++                      0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,\r
++                      0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,\r
++                      0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,\r
++                      0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,\r
++                      0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,\r
++                      0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,\r
++                      0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,\r
++                      0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1,\r
++                      0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,\r
++                      0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,\r
++                      0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,\r
++                      0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE,\r
++                      0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,\r
++                      0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C,\r
++                      0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,\r
++                      0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,\r
++                      0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,\r
++                      0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1,\r
++                      0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,\r
++                      0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,\r
++                      0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,\r
++                      0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66,\r
++                      0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,\r
++                      0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,\r
++                      0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,\r
++                      0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,\r
++                      0x2D02EF8D\r
++              };\r
++              \r
++              internal static uint ComputeCrc32(uint oldCrc, byte bval)\r
++              {\r
++                      return (uint)(Crc32.CrcTable[(oldCrc ^ bval) & 0xFF] ^ (oldCrc >> 8));\r
++              }\r
++              \r
++              /// <summary>\r
++              /// The crc data checksum so far.\r
++              /// </summary>\r
++              uint crc = 0;\r
++              \r
++              /// <summary>\r
++              /// Returns the CRC32 data checksum computed so far.\r
++              /// </summary>\r
++              public long Value {\r
++                      get {\r
++                              return (long)crc;\r
++                      }\r
++                      set {\r
++                              crc = (uint)value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Resets the CRC32 data checksum as if no update was ever called.\r
++              /// </summary>\r
++              public void Reset() \r
++              { \r
++                      crc = 0; \r
++              }\r
++              \r
++              /// <summary>\r
++              /// Updates the checksum with the int bval.\r
++              /// </summary>\r
++              /// <param name = "bval">\r
++              /// the byte is taken as the lower 8 bits of bval\r
++              /// </param>\r
++              public void Update(int bval)\r
++              {\r
++                      crc ^= CrcSeed;\r
++                      crc  = CrcTable[(crc ^ bval) & 0xFF] ^ (crc >> 8);\r
++                      crc ^= CrcSeed;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Updates the checksum with the bytes taken from the array.\r
++              /// </summary>\r
++              /// <param name="buffer">\r
++              /// buffer an array of bytes\r
++              /// </param>\r
++              public void Update(byte[] buffer)\r
++              {\r
++                      Update(buffer, 0, buffer.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Adds the byte array to the data checksum.\r
++              /// </summary>\r
++              /// <param name = "buf">\r
++              /// the buffer which contains the data\r
++              /// </param>\r
++              /// <param name = "off">\r
++              /// the offset in the buffer where the data starts\r
++              /// </param>\r
++              /// <param name = "len">\r
++              /// the length of the data\r
++              /// </param>\r
++              public void Update(byte[] buf, int off, int len)\r
++              {\r
++                      if (buf == null) {\r
++                              throw new ArgumentNullException("buf");\r
++                      }\r
++                      \r
++                      if (off < 0 || len < 0 || off + len > buf.Length) {\r
++                              throw new ArgumentOutOfRangeException();\r
++                      }\r
++                      \r
++                      crc ^= CrcSeed;\r
++                      \r
++                      while (--len >= 0) {\r
++                              crc = CrcTable[(crc ^ buf[off++]) & 0xFF] ^ (crc >> 8);\r
++                      }\r
++                      \r
++                      crc ^= CrcSeed;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..98385b316acb8a8150c3e67f582ca72ec67b8d0f
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,93 @@@
++// IChecksum.cs - Interface to compute a data checksum\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++namespace ICSharpCode.SharpZipLib.Checksums \r
++{\r
++      \r
++      /// <summary>\r
++      /// Interface to compute a data checksum used by checked input/output streams.\r
++      /// A data checksum can be updated by one byte or with a byte array. After each\r
++      /// update the value of the current checksum can be returned by calling\r
++      /// <code>getValue</code>. The complete checksum object can also be reset\r
++      /// so it can be used again with new data.\r
++      /// </summary>\r
++      public interface IChecksum\r
++      {\r
++              /// <summary>\r
++              /// Returns the data checksum computed so far.\r
++              /// </summary>\r
++              long Value \r
++              {\r
++                      get;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Resets the data checksum as if no update was ever called.\r
++              /// </summary>\r
++              void Reset();\r
++              \r
++              /// <summary>\r
++              /// Adds one byte to the data checksum.\r
++              /// </summary>\r
++              /// <param name = "bval">\r
++              /// the data value to add. The high byte of the int is ignored.\r
++              /// </param>\r
++              void Update(int bval);\r
++              \r
++              /// <summary>\r
++              /// Updates the data checksum with the bytes taken from the array.\r
++              /// </summary>\r
++              /// <param name="buffer">\r
++              /// buffer an array of bytes\r
++              /// </param>\r
++              void Update(byte[] buffer);\r
++              \r
++              /// <summary>\r
++              /// Adds the byte array to the data checksum.\r
++              /// </summary>\r
++              /// <param name = "buf">\r
++              /// the buffer which contains the data\r
++              /// </param>\r
++              /// <param name = "off">\r
++              /// the offset in the buffer where the data starts\r
++              /// </param>\r
++              /// <param name = "len">\r
++              /// the length of the data\r
++              /// </param>\r
++              void Update(byte[] buf, int off, int len);\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a2dc10fcf1241b75954406e765dabdfb88535404
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,159 @@@
++// StrangeCRC.cs - computes a crc used in the bziplib ... I don't think that\r
++//                 this is the 'standard' crc, please correct me, if I'm wrong\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Checksums \r
++{\r
++      \r
++      public class StrangeCRC : IChecksum\r
++      {\r
++              readonly static uint[] crc32Table = {\r
++                      0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,\r
++                      0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,\r
++                      0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,\r
++                      0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,\r
++                      0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,\r
++                      0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,\r
++                      0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,\r
++                      0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,\r
++                      0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,\r
++                      0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,\r
++                      0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,\r
++                      0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,\r
++                      0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,\r
++                      0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,\r
++                      0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,\r
++                      0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,\r
++                      0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,\r
++                      0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,\r
++                      0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,\r
++                      0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,\r
++                      0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,\r
++                      0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,\r
++                      0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,\r
++                      0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,\r
++                      0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,\r
++                      0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,\r
++                      0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,\r
++                      0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,\r
++                      0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,\r
++                      0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,\r
++                      0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,\r
++                      0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,\r
++                      0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,\r
++                      0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,\r
++                      0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,\r
++                      0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,\r
++                      0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,\r
++                      0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,\r
++                      0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,\r
++                      0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,\r
++                      0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,\r
++                      0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,\r
++                      0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,\r
++                      0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,\r
++                      0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,\r
++                      0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,\r
++                      0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,\r
++                      0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,\r
++                      0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,\r
++                      0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,\r
++                      0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,\r
++                      0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,\r
++                      0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,\r
++                      0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,\r
++                      0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,\r
++                      0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,\r
++                      0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,\r
++                      0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,\r
++                      0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,\r
++                      0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,\r
++                      0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,\r
++                      0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,\r
++                      0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,\r
++                      0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4\r
++              };\r
++              int globalCrc;\r
++      \r
++              public StrangeCRC() \r
++              {\r
++                      Reset();\r
++              }\r
++      \r
++              public void Reset()\r
++              {\r
++                      globalCrc = -1;\r
++              }\r
++      \r
++              public long Value {\r
++                      get {\r
++                              return ~globalCrc;\r
++                      }\r
++              }\r
++              \r
++              public void Update(int inCh)\r
++              {\r
++                      int temp = (globalCrc >> 24) ^ inCh;\r
++                      if (temp < 0) {\r
++                              temp = 256 + temp;\r
++                      }\r
++                      globalCrc = (int)((globalCrc << 8) ^ crc32Table[temp]);\r
++              }\r
++              \r
++              public void Update(byte[] buf)\r
++              {\r
++                      Update(buf, 0, buf.Length);\r
++              }\r
++              \r
++              public void Update(byte[] buf, int off, int len)\r
++              {\r
++                      if (buf == null) {\r
++                              throw new ArgumentNullException("buf");\r
++                      }\r
++                      \r
++                      if (off < 0 || len < 0 || off + len > buf.Length) {\r
++                              throw new ArgumentOutOfRangeException();\r
++                      }\r
++                      \r
++                      for (int i = 0; i < len; ++i) {\r
++                              Update(buf[off++]);\r
++                      }\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..d40ef5a88c80756b80f0e93628428f5a290312ea
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,68 @@@
++// GZIPConstants.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++namespace ICSharpCode.SharpZipLib.GZip \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class contains constants used for gzip.\r
++      /// </summary>\r
++      public class GZipConstants \r
++      {\r
++              /// <summary>\r
++              /// Magic number found at start of GZIP header\r
++              /// </summary>\r
++              public static readonly int GZIP_MAGIC = 0x1F8B;\r
++              \r
++              /*  The flag byte is divided into individual bits as follows:\r
++                      \r
++                      bit 0   FTEXT\r
++                      bit 1   FHCRC\r
++                      bit 2   FEXTRA\r
++                      bit 3   FNAME\r
++                      bit 4   FCOMMENT\r
++                      bit 5   reserved\r
++                      bit 6   reserved\r
++                      bit 7   reserved\r
++               */\r
++              public const int FTEXT    = 0x1;\r
++              public const int FHCRC    = 0x2;\r
++              public const int FEXTRA   = 0x4;\r
++              public const int FNAME    = 0x8;\r
++              public const int FCOMMENT = 0x10;\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..5a35548e2fbcc172b6c74add1ad947cd012065be
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,336 @@@
++// GzipInputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++using ICSharpCode.SharpZipLib.Zip.Compression;\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++\r
++namespace ICSharpCode.SharpZipLib.GZip \r
++{\r
++      \r
++      /// <summary>\r
++      /// This filter stream is used to decompress a "GZIP" format stream.\r
++      /// The "GZIP" format is described baseInputStream RFC 1952.\r
++      /// \r
++      /// author of the original java version : John Leuner\r
++      /// </summary>\r
++      /// <example> This sample shows how to unzip a gzipped file\r
++      /// <code>\r
++      /// using System;\r
++      /// using System.IO;\r
++      /// \r
++      /// using NZlib.GZip;\r
++      /// \r
++      /// class MainClass\r
++      /// {\r
++      ///     public static void Main(string[] args)\r
++      ///     {\r
++      ///             Stream s = new GZipInputStream(File.OpenRead(args[0]));\r
++      ///             FileStream fs = File.Create(Path.GetFileNameWithoutExtension(args[0]));\r
++      ///             int size = 2048;\r
++      ///             byte[] writeData = new byte[2048];\r
++      ///             while (true) {\r
++      ///                     size = s.Read(writeData, 0, size);\r
++      ///                     if (size > 0) {\r
++      ///                             fs.Write(writeData, 0, size);\r
++      ///                     } else {\r
++      ///                             break;\r
++      ///                     }\r
++      ///             }\r
++      ///             s.Close();\r
++      ///     }\r
++      /// }   \r
++      /// </code>\r
++      /// </example>\r
++      public class GZipInputStream : InflaterInputStream \r
++      {\r
++              /// <summary>\r
++              /// CRC-32 value for uncompressed data\r
++              /// </summary>\r
++              protected Crc32 crc = new Crc32();\r
++              \r
++              /// <summary>\r
++              /// Indicates end of stream\r
++              /// </summary>\r
++              protected bool eos;\r
++              \r
++              // Have we read the GZIP header yet?\r
++              bool readGZIPHeader;\r
++              \r
++              /// <summary>\r
++              /// Creates a GzipInputStream with the default buffer size\r
++              /// </summary>\r
++              /// <param name="baseInputStream">\r
++              /// The stream to read compressed data from (baseInputStream GZIP format)\r
++              /// </param>\r
++              public GZipInputStream(Stream baseInputStream) : this(baseInputStream, 4096)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a GZIPInputStream with the specified buffer size\r
++              /// </summary>\r
++              /// <param name="baseInputStream">\r
++              /// The stream to read compressed data from (baseInputStream GZIP format)\r
++              /// </param>\r
++              /// <param name="size">\r
++              /// Size of the buffer to use\r
++              /// </param>\r
++              public GZipInputStream(Stream baseInputStream, int size) : base(baseInputStream, new Inflater(true), size)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Reads uncompressed data into an array of bytes\r
++              /// </summary>\r
++              /// <param name="buf">\r
++              /// the buffer to read uncompressed data into\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// the offset indicating where the data should be placed\r
++              /// </param>\r
++              /// <param name="len">\r
++              /// the number of uncompressed bytes to be read\r
++              /// </param>\r
++              public override int Read(byte[] buf, int offset, int len) \r
++              {\r
++                      // We first have to slurp baseInputStream the GZIP header, then we feed all the\r
++                      // rest of the data to the superclass.\r
++                      //\r
++                      // As we do that we continually update the CRC32. Once the data is\r
++                      // finished, we check the CRC32\r
++                      //\r
++                      // This means we don't need our own buffer, as everything is done\r
++                      // baseInputStream the superclass.\r
++                      if (!readGZIPHeader) {\r
++                              ReadHeader();\r
++                      }\r
++                      \r
++                      if (eos) {\r
++                              return 0;\r
++                      }\r
++                      \r
++                      //    System.err.println("GZIPIS.read(byte[], off, len ... " + offset + " and len " + len);\r
++                      //We don't have to read the header, so we just grab data from the superclass\r
++                      int numRead = base.Read(buf, offset, len);\r
++                      if (numRead > 0) {\r
++                              crc.Update(buf, offset, numRead);\r
++                      }\r
++                      \r
++                      if (inf.IsFinished) {\r
++                              ReadFooter();\r
++                      }\r
++                      return numRead;\r
++              }\r
++              \r
++              private void ReadHeader() \r
++              {\r
++                      /* 1. Check the two magic bytes */\r
++                      Crc32 headCRC = new Crc32();\r
++                      int magic = baseInputStream.ReadByte();\r
++                      if (magic < 0) {\r
++                              eos = true;\r
++                              return;\r
++                      }\r
++                      headCRC.Update(magic);\r
++                      if (magic != (GZipConstants.GZIP_MAGIC >> 8)) {\r
++                              throw new IOException("Error baseInputStream GZIP header, first byte doesn't match");\r
++                      }\r
++                              \r
++                      magic = baseInputStream.ReadByte();\r
++                      if (magic != (GZipConstants.GZIP_MAGIC & 0xFF)) {\r
++                              throw new IOException("Error baseInputStream GZIP header,  second byte doesn't match");\r
++                      }\r
++                      headCRC.Update(magic);\r
++                      \r
++                      /* 2. Check the compression type (must be 8) */\r
++                      int CM = baseInputStream.ReadByte();\r
++                      if (CM != 8) {\r
++                              throw new IOException("Error baseInputStream GZIP header, data not baseInputStream deflate format");\r
++                      }\r
++                      headCRC.Update(CM);\r
++                      \r
++                      /* 3. Check the flags */\r
++                      int flags = baseInputStream.ReadByte();\r
++                      if (flags < 0) {\r
++                              throw new Exception("Early EOF baseInputStream GZIP header");\r
++                      }\r
++                      headCRC.Update(flags);\r
++                      \r
++                      /*    This flag byte is divided into individual bits as follows:\r
++                              \r
++                              bit 0   FTEXT\r
++                              bit 1   FHCRC\r
++                              bit 2   FEXTRA\r
++                              bit 3   FNAME\r
++                              bit 4   FCOMMENT\r
++                              bit 5   reserved\r
++                              bit 6   reserved\r
++                              bit 7   reserved\r
++                              */\r
++                              \r
++                      /* 3.1 Check the reserved bits are zero */\r
++                      \r
++                      if ((flags & 0xd0) != 0) {\r
++                              throw new IOException("Reserved flag bits baseInputStream GZIP header != 0");\r
++                      }\r
++                      \r
++                      /* 4.-6. Skip the modification time, extra flags, and OS type */\r
++                      for (int i=0; i< 6; i++) {\r
++                              int readByte = baseInputStream.ReadByte();\r
++                              if (readByte < 0) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP header");\r
++                              }\r
++                              headCRC.Update(readByte);\r
++                      }\r
++                      \r
++                      /* 7. Read extra field */\r
++                      if ((flags & GZipConstants.FEXTRA) != 0) {\r
++                              /* Skip subfield id */\r
++                              for (int i=0; i< 2; i++) {\r
++                                      int readByte = baseInputStream.ReadByte();\r
++                                      if (readByte < 0) {\r
++                                              throw new Exception("Early EOF baseInputStream GZIP header");\r
++                                      }\r
++                                      headCRC.Update(readByte);\r
++                              }\r
++                              if (baseInputStream.ReadByte() < 0 || baseInputStream.ReadByte() < 0) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP header");\r
++                              }\r
++                              \r
++                              int len1, len2, extraLen;\r
++                              len1 = baseInputStream.ReadByte();\r
++                              len2 = baseInputStream.ReadByte();\r
++                              if ((len1 < 0) || (len2 < 0)) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP header");\r
++                              }\r
++                              headCRC.Update(len1);\r
++                              headCRC.Update(len2);\r
++                              \r
++                              extraLen = (len1 << 8) | len2;\r
++                              for (int i = 0; i < extraLen;i++) {\r
++                                      int readByte = baseInputStream.ReadByte();\r
++                                      if (readByte < 0) \r
++                                      {\r
++                                              throw new Exception("Early EOF baseInputStream GZIP header");\r
++                                      }\r
++                                      headCRC.Update(readByte);\r
++                              }\r
++                      }\r
++                      \r
++                      /* 8. Read file name */\r
++                      if ((flags & GZipConstants.FNAME) != 0) {\r
++                              int readByte;\r
++                              while ( (readByte = baseInputStream.ReadByte()) > 0) {\r
++                                      headCRC.Update(readByte);\r
++                              }\r
++                              if (readByte < 0) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP file name");\r
++                              }\r
++                              headCRC.Update(readByte);\r
++                      }\r
++                      \r
++                      /* 9. Read comment */\r
++                      if ((flags & GZipConstants.FCOMMENT) != 0) {\r
++                              int readByte;\r
++                              while ( (readByte = baseInputStream.ReadByte()) > 0) {\r
++                                      headCRC.Update(readByte);\r
++                              }\r
++                              \r
++                              if (readByte < 0) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP comment");\r
++                              }\r
++                              headCRC.Update(readByte);\r
++                      }\r
++                      \r
++                      /* 10. Read header CRC */\r
++                      if ((flags & GZipConstants.FHCRC) != 0) {\r
++                              int tempByte;\r
++                              int crcval = baseInputStream.ReadByte();\r
++                              if (crcval < 0) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP header");\r
++                              }\r
++                              \r
++                              tempByte = baseInputStream.ReadByte();\r
++                              if (tempByte < 0) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP header");\r
++                              }\r
++                              \r
++                              crcval = (crcval << 8) | tempByte;\r
++                              if (crcval != ((int) headCRC.Value & 0xffff)) {\r
++                                      throw new IOException("Header CRC value mismatch");\r
++                              }\r
++                      }\r
++                      \r
++                      readGZIPHeader = true;\r
++                      //System.err.println("Read GZIP header");\r
++              }\r
++              \r
++              private void ReadFooter() \r
++              {\r
++                      byte[] footer = new byte[8];\r
++                      int avail = inf.RemainingInput;\r
++                      if (avail > 8) {\r
++                              avail = 8;\r
++                      }\r
++                      System.Array.Copy(buf, len - inf.RemainingInput, footer, 0, avail);\r
++                      int needed = 8 - avail;\r
++                      while (needed > 0) {\r
++                              int count = baseInputStream.Read(footer, 8-needed, needed);\r
++                              if (count <= 0) {\r
++                                      throw new Exception("Early EOF baseInputStream GZIP footer");\r
++                              }\r
++                              needed -= count; //Jewel Jan 16\r
++                      }\r
++                      int crcval = (footer[0] & 0xff) | ((footer[1] & 0xff) << 8) | ((footer[2] & 0xff) << 16) | (footer[3] << 24);\r
++                      if (crcval != (int) crc.Value) {\r
++                              throw new IOException("GZIP crc sum mismatch, theirs \"" + crcval + "\" and ours \"" + (int) crc.Value);\r
++                      }\r
++                      int total = (footer[4] & 0xff) | ((footer[5] & 0xff) << 8) | ((footer[6] & 0xff) << 16) | (footer[7] << 24);\r
++                      if (total != inf.TotalOut) {\r
++                              throw new IOException("Number of bytes mismatch");\r
++                      }\r
++                      /* XXX Should we support multiple members.\r
++                      * Difficult, since there may be some bytes still baseInputStream buf\r
++                      */\r
++                      eos = true;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b150e66d5c2db1e826b7b4a1343170a68cc1caa2
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,174 @@@
++// GzipOutputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++using ICSharpCode.SharpZipLib.Zip.Compression;\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++\r
++namespace ICSharpCode.SharpZipLib.GZip \r
++{\r
++      \r
++      /// <summary>\r
++      /// This filter stream is used to compress a stream into a "GZIP" stream.\r
++      /// The "GZIP" format is described in RFC 1952.\r
++      ///\r
++      /// author of the original java version : John Leuner\r
++      /// </summary>\r
++      /// <example> This sample shows how to gzip a file\r
++      /// <code>\r
++      /// using System;\r
++      /// using System.IO;\r
++      /// \r
++      /// using ICSharpCode.SharpZipLib.GZip;    // -jr- corrected\r
++      /// \r
++      /// class MainClass\r
++      /// {\r
++      ///     public static void Main(string[] args)\r
++      ///     {\r
++      ///             Stream s = new GZipOutputStream(File.Create(args[0] + ".gz"));\r
++      ///             FileStream fs = File.OpenRead(args[0]);\r
++      ///             byte[] writeData = new byte[fs.Length];\r
++      ///             fs.Read(writeData, 0, (int)fs.Length);\r
++      ///             s.Write(writeData, 0, writeData.Length);\r
++      ///             s.Close();\r
++      ///     }\r
++      /// }   \r
++      /// </code>\r
++      /// </example>\r
++      public class GZipOutputStream : DeflaterOutputStream\r
++      {\r
++              //Variables\r
++              \r
++              /// <summary>\r
++              /// CRC-32 value for uncompressed data\r
++              /// </summary>\r
++              protected Crc32 crc = new Crc32();\r
++              \r
++              // Constructors\r
++              \r
++              /// <summary>\r
++              /// Creates a GzipOutputStream with the default buffer size\r
++              /// </summary>\r
++              /// <param name="baseOutputStream">\r
++              /// The stream to read data (to be compressed) from\r
++              /// </param>\r
++              public GZipOutputStream(Stream baseOutputStream) : this(baseOutputStream, 4096)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a GZIPOutputStream with the specified buffer size\r
++              /// </summary>\r
++              /// <param name="baseOutputStream">\r
++              /// The stream to read data (to be compressed) from\r
++              /// </param>\r
++              /// <param name="size">\r
++              /// Size of the buffer to use\r
++              /// </param>\r
++              public GZipOutputStream(Stream baseOutputStream, int size) : base(baseOutputStream, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size)\r
++              {\r
++                      WriteHeader();\r
++                      //    System.err.println("wrote GZIP header (" + gzipHeader.length + " bytes )");\r
++              }\r
++              \r
++              void WriteHeader()\r
++              {\r
++                      int mod_time = (int)(DateTime.Now.Ticks / 10000L);  // Ticks give back 100ns intervals\r
++                      byte[] gzipHeader = {\r
++                              /* The two magic bytes */\r
++                              (byte) (GZipConstants.GZIP_MAGIC >> 8), (byte) GZipConstants.GZIP_MAGIC,\r
++                              \r
++                              /* The compression type */\r
++                              (byte) Deflater.DEFLATED,\r
++                              \r
++                              /* The flags (not set) */\r
++                              0,\r
++                              \r
++                              /* The modification time */\r
++                              (byte) mod_time, (byte) (mod_time >> 8),\r
++                              (byte) (mod_time >> 16), (byte) (mod_time >> 24),\r
++                              \r
++                              /* The extra flags */\r
++                              0,\r
++                              \r
++                              /* The OS type (unknown) */\r
++                              (byte) 255\r
++                      };\r
++                      baseOutputStream.Write(gzipHeader, 0, gzipHeader.Length);\r
++              }\r
++              \r
++              public override void Write(byte[] buf, int off, int len)\r
++              {\r
++                      crc.Update(buf, off, len);\r
++                      base.Write(buf, off, len);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Writes remaining compressed output data to the output stream\r
++              /// and closes it.\r
++              /// </summary>\r
++              public override void Close()\r
++              {\r
++                      Finish();\r
++                      baseOutputStream.Close();\r
++              }\r
++              \r
++              public override void Finish()\r
++              {\r
++                      base.Finish();\r
++                      \r
++                      int totalin = def.TotalIn;\r
++                      int crcval = (int) (crc.Value & 0xffffffff);\r
++                      \r
++                      //    System.err.println("CRC val is " + Integer.toHexString( crcval )                 + " and length " + Integer.toHexString(totalin));\r
++                      \r
++                      byte[] gzipFooter = {\r
++                              (byte) crcval, (byte) (crcval >> 8),\r
++                              (byte) (crcval >> 16), (byte) (crcval >> 24),\r
++                              \r
++                              (byte) totalin, (byte) (totalin >> 8),\r
++                              (byte) (totalin >> 16), (byte) (totalin >> 24)\r
++                      };\r
++\r
++                      baseOutputStream.Write(gzipFooter, 0, gzipFooter.Length);\r
++                      //    System.err.println("wrote GZIP trailer (" + gzipFooter.length + " bytes )");\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..3fd5301df30db1cc1a1f5308150c9698a039b12a
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,72 @@@
++// InvalidHeaderException.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++\r
++namespace ICSharpCode.SharpZipLib.Tar {\r
++      \r
++      /// <summary>\r
++      /// This exception is used to indicate that there is a problem\r
++      /// with a TAR archive header.\r
++      /// </summary>\r
++      public class InvalidHeaderException : System.IO.IOException\r
++      {\r
++              public InvalidHeaderException()\r
++              {\r
++              }\r
++      \r
++              public InvalidHeaderException(string msg) : base(msg)\r
++              {\r
++              }\r
++      }\r
++}\r
++\r
++/* The original Java file had this header:\r
++** Authored by Timothy Gerard Endres\r
++** <mailto:time@gjt.org>  <http://www.trustice.com>\r
++** \r
++** This work has been placed into the public domain.\r
++** You may use this work in any way and for any purpose you wish.\r
++**\r
++** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,\r
++** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR\r
++** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY\r
++** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR\r
++** REDISTRIBUTION OF THIS SOFTWARE. \r
++** \r
++*/\r
++\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..ffe7b35a40248596529a21aa83a42dea89993df7
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,696 @@@
++// TarInputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++//\r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++using System.Text;\r
++\r
++namespace ICSharpCode.SharpZipLib.Tar {\r
++      \r
++      public delegate void ProgressMessageHandler(TarArchive archive, TarEntry entry, string message);\r
++      \r
++      /// <summary>\r
++      /// The TarArchive class implements the concept of a\r
++      /// tar archive. A tar archive is a series of entries, each of\r
++      /// which represents a file system object. Each entry in\r
++      /// the archive consists of a header block. Directory entries\r
++      /// consist only of the header block, and are followed by entries\r
++      /// for the directory's contents. File entries consist of a\r
++      /// header followed by the number of blocks needed to\r
++      /// contain the file's contents. All entries are written on\r
++      /// block boundaries. Blocks are 512 bytes long.\r
++      /// \r
++      /// TarArchives are instantiated in either read or write mode,\r
++      /// based upon whether they are instantiated with an InputStream\r
++      /// or an OutputStream. Once instantiated TarArchives read/write\r
++      /// mode can not be changed.\r
++      /// \r
++      /// There is currently no support for random access to tar archives.\r
++      /// However, it seems that subclassing TarArchive, and using the\r
++      /// TarBuffer.getCurrentRecordNum() and TarBuffer.getCurrentBlockNum()\r
++      /// methods, this would be rather trvial.\r
++      /// </summary>\r
++      public class TarArchive\r
++      {\r
++              bool verbose;\r
++              bool debug;\r
++              bool keepOldFiles;\r
++              bool asciiTranslate;\r
++              \r
++              int    userId;\r
++              string userName;\r
++              int    groupId;\r
++              string groupName;\r
++              \r
++              string rootPath;\r
++              string pathPrefix;\r
++              \r
++              int    recordSize;\r
++              byte[] recordBuf;\r
++              \r
++              TarInputStream  tarIn;\r
++              TarOutputStream tarOut;\r
++              \r
++              public event ProgressMessageHandler ProgressMessageEvent;\r
++              \r
++              protected virtual void OnProgressMessageEvent(TarEntry entry, string message)\r
++              {\r
++                      if (ProgressMessageEvent != null) {\r
++                              ProgressMessageEvent(this, entry, message);\r
++                      }\r
++              }\r
++              \r
++              protected TarArchive()\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// The InputStream based constructors create a TarArchive for the\r
++              /// purposes of e'x'tracting or lis't'ing a tar archive. Thus, use\r
++              /// these constructors when you wish to extract files from or list\r
++              /// the contents of an existing tar archive.\r
++              /// </summary>\r
++              public static TarArchive CreateInputTarArchive(Stream inputStream)\r
++              {\r
++                      return CreateInputTarArchive(inputStream, TarBuffer.DefaultBlockFactor);\r
++              }\r
++              \r
++              public static TarArchive CreateInputTarArchive(Stream inputStream, int blockFactor)\r
++              {\r
++                      TarArchive archive = new TarArchive();\r
++                      archive.tarIn = new TarInputStream(inputStream, blockFactor);\r
++                      archive.Initialize(blockFactor * TarBuffer.BlockSize);\r
++                      return archive;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// The OutputStream based constructors create a TarArchive for the\r
++              /// purposes of 'c'reating a tar archive. Thus, use these constructors\r
++              /// when you wish to create a new tar archive and write files into it.\r
++              /// </summary>\r
++              public static TarArchive CreateOutputTarArchive(Stream outputStream)\r
++              {\r
++                      return CreateOutputTarArchive(outputStream, TarBuffer.DefaultBlockFactor);\r
++              }\r
++              \r
++              public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockFactor)\r
++              {\r
++                      TarArchive archive = new TarArchive();\r
++                      archive.tarOut = new TarOutputStream(outputStream, blockFactor);\r
++                      archive.Initialize(blockFactor * TarBuffer.BlockSize);\r
++                      return archive;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Common constructor initialization code.\r
++              /// </summary>\r
++              void Initialize(int recordSize)\r
++              {\r
++         this.recordSize = recordSize;\r
++                      this.rootPath   = null;\r
++                      this.pathPrefix = null;\r
++                      \r
++//                    this.tempPath   = System.getProperty( "user.dir" );\r
++                      \r
++                      this.userId    = 0;\r
++                      this.userName  = String.Empty;\r
++                      this.groupId   = 0;\r
++                      this.groupName = String.Empty;\r
++                      \r
++                      this.debug           = false;\r
++                      this.verbose         = false;\r
++                      this.keepOldFiles    = false;\r
++                      \r
++                      this.recordBuf = new byte[RecordSize];\r
++              }\r
++              \r
++              ///\r
++         /// <summary> Set the debugging flag. </summary>\r
++              ///\r
++              /// <param name=debugF> The new debug setting. </param>\r
++              \r
++              public void SetDebug(bool debugF)\r
++              {\r
++                      this.debug = debugF;\r
++                      if (this.tarIn != null) {\r
++                              this.tarIn.SetDebug(debugF);\r
++                      } \r
++                      if (this.tarOut != null) {\r
++                              this.tarOut.SetDebug(debugF);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get/Set the verbosity setting.\r
++              /// </summary>\r
++              public bool IsVerbose {\r
++                      get {\r
++                              return verbose;\r
++                      }\r
++                      set {\r
++                              verbose = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Set the flag that determines whether existing files are\r
++              /// kept, or overwritten during extraction.\r
++              /// </summary>\r
++              /// <param name="keepOldFiles">\r
++              /// If true, do not overwrite existing files.\r
++              /// </param>\r
++              public void SetKeepOldFiles(bool keepOldFiles)\r
++              {\r
++                      this.keepOldFiles = keepOldFiles;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Set the ascii file translation flag. If ascii file translation\r
++              /// is true, then the MIME file type will be consulted to determine\r
++              /// if the file is of type 'text/*'. If the MIME type is not found,\r
++              /// then the TransFileTyper is consulted if it is not null. If\r
++              /// either of these two checks indicates the file is an ascii text\r
++              /// file, it will be translated. The translation converts the local\r
++              /// operating system's concept of line ends into the UNIX line end,\r
++              /// '\n', which is the defacto standard for a TAR archive. This makes\r
++              /// text files compatible with UNIX.\r
++              /// </summary>\r
++              /// <param name= "asciiTranslate">\r
++              /// If true, translate ascii text files.\r
++              /// </param>\r
++              public void SetAsciiTranslation(bool asciiTranslate)\r
++              {\r
++                      this.asciiTranslate = asciiTranslate;\r
++              }\r
++              \r
++/*\r
++              /// <summary>\r
++              /// Set the object that will determine if a file is of type\r
++              /// ascii text for translation purposes.\r
++              /// </summary>\r
++              /// <param name="transTyper">\r
++              /// The new TransFileTyper object.\r
++              /// </param>\r
++              public void SetTransFileTyper(TarTransFileTyper transTyper)\r
++              {\r
++                      this.transTyper = transTyper;\r
++              }\r
++*/\r
++              \r
++              /// <summary>\r
++              /// Set user and group information that will be used to fill in the\r
++              /// tar archive's entry headers. Since Java currently provides no means\r
++              /// of determining a user name, user id, group name, or group id for\r
++              /// a given File, TarArchive allows the programmer to specify values\r
++              /// to be used in their place.\r
++              /// </summary>\r
++              /// <param name="userId">\r
++              /// The user Id to use in the headers.\r
++              /// </param>\r
++              /// <param name="userName">\r
++              /// The user name to use in the headers.\r
++              /// </param>\r
++              /// <param name="groupId">\r
++              /// The group id to use in the headers.\r
++              /// </param>\r
++              /// <param name="groupName">\r
++              /// The group name to use in the headers.\r
++              /// </param>\r
++              public void SetUserInfo(int userId, string userName, int groupId, string groupName)\r
++              {\r
++                      this.userId    = userId;\r
++                      this.userName  = userName;\r
++                      this.groupId   = groupId;\r
++                      this.groupName = groupName;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the user id being used for archive entry headers.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The current user id.\r
++              /// </returns>\r
++              public int UserId {\r
++                      get {\r
++                              return this.userId;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the user name being used for archive entry headers.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The current user name.\r
++              /// </returns>\r
++              public string UserName {\r
++                      get {\r
++                              return this.userName;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the group id being used for archive entry headers.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The current group id.\r
++              /// </returns>\r
++              public int GroupId {\r
++                      get {\r
++                              return this.groupId;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the group name being used for archive entry headers.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The current group name.\r
++              /// </returns>\r
++              public string GroupName {\r
++                      get {\r
++                              return this.groupName;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the archive's record size. Because of its history, tar\r
++              /// supports the concept of buffered IO consisting of RECORDS of\r
++              /// BLOCKS. This allowed tar to match the IO characteristics of\r
++              /// the physical device being used. Of course, in the Java world,\r
++              /// this makes no sense, WITH ONE EXCEPTION - archives are expected\r
++              /// to be properly "blocked". Thus, all of the horrible TarBuffer\r
++              /// support boils down to simply getting the "boundaries" correct.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The record size this archive is using.\r
++              /// </returns>\r
++              public int RecordSize {\r
++                      get {\r
++                              if (this.tarIn != null) {\r
++                                      return this.tarIn.GetRecordSize();\r
++                              } \r
++            else if (this.tarOut != null) {\r
++                                      return this.tarOut.GetRecordSize();\r
++                              }\r
++                              return TarBuffer.DefaultRecordSize;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Close the archive. This simply calls the underlying\r
++              /// tar stream's close() method.\r
++              /// </summary>\r
++              public void CloseArchive()\r
++              {\r
++                      if (this.tarIn != null) {\r
++                              this.tarIn.Close();\r
++                      } \r
++         else if (this.tarOut != null) {\r
++                              this.tarOut.Flush();\r
++                              this.tarOut.Close();\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Perform the "list" command and list the contents of the archive.\r
++              /// \r
++              /// NOTE That this method uses the progress display to actually list\r
++              /// the conents. If the progress display is not set, nothing will be\r
++              /// listed!\r
++              /// </summary>\r
++              public void ListContents()\r
++              {\r
++                      while (true) {\r
++                              TarEntry entry = this.tarIn.GetNextEntry();\r
++                              \r
++                              if (entry == null) {\r
++                                      if (this.debug) {\r
++                                              Console.Error.WriteLine("READ EOF BLOCK");\r
++                                      }\r
++                                      break;\r
++                              }\r
++                              OnProgressMessageEvent(entry, null);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Perform the "extract" command and extract the contents of the archive.\r
++              /// </summary>\r
++              /// <param name="destDir">\r
++              /// The destination directory into which to extract.\r
++              /// </param>\r
++              public void ExtractContents(string destDir)\r
++              {\r
++                      while (true) {\r
++                              TarEntry entry = this.tarIn.GetNextEntry();\r
++                              \r
++                              if (entry == null) {\r
++                                      if (this.debug) {\r
++                                              Console.Error.WriteLine("READ EOF BLOCK");\r
++                                      }\r
++                                      break;\r
++                              }\r
++                              \r
++                              this.ExtractEntry(destDir, entry);\r
++                      }\r
++              }\r
++              \r
++              void EnsureDirectoryExists(string directoryName)\r
++              {\r
++                      if (!Directory.Exists(directoryName)) {\r
++                              try {\r
++                                      Directory.CreateDirectory(directoryName);\r
++                              }\r
++            catch (Exception e) {\r
++                                      throw new IOException("error making directory path '" + directoryName + "', " + e.Message);\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              // TODO -jr- No longer reads entire file into memory but is still a weak test!\r
++              bool IsBinary(string filename)\r
++              {\r
++                      FileStream fs = File.OpenRead(filename);\r
++                      \r
++         int sampleSize = System.Math.Min(4096, (int)fs.Length);\r
++                      byte[] content = new byte[sampleSize];\r
++                      \r
++                      fs.Read(content, 0, sampleSize);\r
++                      fs.Close();\r
++                      \r
++                      // assume that ascii 0 or \r
++                      // ascii 255 are only found in non text files.\r
++                      // and that all non text files contain 0 and 255\r
++                      foreach (byte b in content) {\r
++                              if (b == 0 || b == 255) {\r
++                                      return true;\r
++                              }\r
++                      }\r
++                      \r
++                      return false;\r
++              }               \r
++              \r
++              /// <summary>\r
++              /// Extract an entry from the archive. This method assumes that the\r
++              /// tarIn stream has been properly set with a call to getNextEntry().\r
++              /// </summary>\r
++              /// <param name="destDir">\r
++              /// The destination directory into which to extract.\r
++              /// </param>\r
++              /// <param name="entry">\r
++              /// The TarEntry returned by tarIn.getNextEntry().\r
++              /// </param>\r
++              void ExtractEntry(string destDir, TarEntry entry)\r
++              {\r
++                      if (this.verbose) {\r
++                              OnProgressMessageEvent(entry, null);\r
++                      }\r
++                      \r
++                      string name = entry.Name;\r
++                      name = name.Replace('/', Path.DirectorySeparatorChar);\r
++                      \r
++                      if (!destDir.EndsWith(Path.DirectorySeparatorChar.ToString())) {\r
++                              destDir += Path.DirectorySeparatorChar;\r
++                      }\r
++                      \r
++                      string destFile = destDir + name;\r
++                      \r
++                      if (entry.IsDirectory) {\r
++                              EnsureDirectoryExists(destFile);\r
++                      } \r
++         else {\r
++                              string parentDirectory = Path.GetDirectoryName(destFile);\r
++                              EnsureDirectoryExists(parentDirectory);\r
++                              \r
++                              if (this.keepOldFiles && File.Exists(destFile)) {\r
++                                      if (this.verbose) {\r
++                                              OnProgressMessageEvent(entry, "Destination file already exists");\r
++                                      }\r
++                              } \r
++            else {\r
++                                      bool asciiTrans = false;\r
++                                      Stream outputStream = File.Create(destFile);\r
++                                      if (this.asciiTranslate) {\r
++                                              asciiTrans = !IsBinary(destFile);\r
++// original java sourcecode : \r
++//                                            MimeType mime      = null;\r
++//                                            string contentType = null;\r
++//                                            try {\r
++//                                                    contentType = FileTypeMap.getDefaultFileTypeMap().getContentType( destFile );\r
++//                                                    \r
++//                                                    mime = new MimeType(contentType);\r
++//                                                    \r
++//                                                    if (mime.getPrimaryType().equalsIgnoreCase( "text" )) {\r
++//                                                            asciiTrans = true;\r
++//                                                    } else if ( this.transTyper != null ) {\r
++//                                                        if ( this.transTyper.isAsciiFile( entry.getName() ) ) {\r
++//                                                            asciiTrans = true;\r
++//                                                        }\r
++//                                                    }\r
++//                                            } catch (MimeTypeParseException ex) {\r
++//                                            }\r
++//                                            \r
++//                                            if (this.debug) {\r
++//                                                    Console.Error.WriteLine(("EXTRACT TRANS? '" + asciiTrans + "'  ContentType='" + contentType + "'  PrimaryType='" + mime.getPrimaryType() + "'" );\r
++//                                            }\r
++                                      }\r
++                                      \r
++                                      StreamWriter outw = null;\r
++                                      if (asciiTrans) {\r
++                                              outw = new StreamWriter(outputStream);\r
++                                      }\r
++                                      \r
++                                      byte[] rdbuf = new byte[32 * 1024];\r
++                                      \r
++                                      while (true) {\r
++                                              int numRead = this.tarIn.Read(rdbuf, 0, rdbuf.Length);\r
++                                              \r
++                                              if (numRead <= 0) {\r
++                                                      break;\r
++                                              }\r
++                                              \r
++                                              if (asciiTrans) {\r
++                                                      for (int off = 0, b = 0; b < numRead; ++b) {\r
++                                                              if (rdbuf[b] == 10) {\r
++                                                                      string s = Encoding.ASCII.GetString(rdbuf, off, (b - off));\r
++                                                                      outw.WriteLine(s);\r
++                                                                      off = b + 1;\r
++                                                              }\r
++                                                      }\r
++                                              } \r
++                  else {\r
++                                                      outputStream.Write(rdbuf, 0, numRead);\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      if (asciiTrans) {\r
++                                              outw.Close();\r
++                                      } \r
++               else {\r
++                                              outputStream.Close();\r
++                                      }\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write an entry to the archive. This method will call the putNextEntry\r
++              /// and then write the contents of the entry, and finally call closeEntry()()\r
++              /// for entries that are files. For directories, it will call putNextEntry(),\r
++              /// and then, if the recurse flag is true, process each entry that is a\r
++              /// child of the directory.\r
++              /// </summary>\r
++              /// <param name="entry">\r
++              /// The TarEntry representing the entry to write to the archive.\r
++              /// </param>\r
++              /// <param name="recurse">\r
++              /// If true, process the children of directory entries.\r
++              /// </param>\r
++              public void WriteEntry(TarEntry entry, bool recurse)\r
++              {\r
++                      bool asciiTrans = false;\r
++                      \r
++                      string tempFileName = null;\r
++                      string eFile        = entry.File;\r
++                      \r
++                      // Work on a copy of the entry so we can manipulate it.\r
++                      // Note that we must distinguish how the entry was constructed.\r
++                      //\r
++                      if (eFile == null || eFile.Length == 0) {\r
++                              entry = TarEntry.CreateTarEntry(entry.Name);\r
++                      } \r
++         else {\r
++                              //\r
++                              // The user may have explicitly set the entry's name to\r
++                              // something other than the file's path, so we must save\r
++                              // and restore it. This should work even when the name\r
++                              // was set from the File's name.\r
++                              //\r
++                              string saveName = entry.Name;\r
++                              entry = TarEntry.CreateEntryFromFile(eFile);\r
++                              entry.Name = saveName;\r
++                      }\r
++                      \r
++                      if (this.verbose) {\r
++                              OnProgressMessageEvent(entry, null);\r
++                      }\r
++                      \r
++                      if (this.asciiTranslate && !entry.IsDirectory) {\r
++                              asciiTrans = !IsBinary(eFile);\r
++\r
++// original java source :\r
++//                            MimeType mime = null;\r
++//                            string contentType = null;\r
++//    \r
++//                            try {\r
++//                                    contentType = FileTypeMap.getDefaultFileTypeMap(). getContentType( eFile );\r
++//                                    \r
++//                                    mime = new MimeType( contentType );\r
++//                                    \r
++//                                    if ( mime.getPrimaryType().\r
++//                                        equalsIgnoreCase( "text" ) )\r
++//                                        {\r
++//                                            asciiTrans = true;\r
++//                                        }\r
++//                                        else if ( this.transTyper != null )\r
++//                                        {\r
++//                                            if ( this.transTyper.isAsciiFile( eFile ) )\r
++//                                            {\r
++//                                                    asciiTrans = true;\r
++//                                            }\r
++//                                        }\r
++//                            } catch ( MimeTypeParseException ex )\r
++//                            {\r
++//    //                               IGNORE THIS ERROR...\r
++//                            }\r
++//                    \r
++//                    if (this.debug) {\r
++//                            Console.Error.WriteLine("CREATE TRANS? '" + asciiTrans + "'  ContentType='" + contentType + "'  PrimaryType='" + mime.getPrimaryType()+ "'" );\r
++//                    }\r
++                      \r
++                      if (asciiTrans) {\r
++                              tempFileName = Path.GetTempFileName();\r
++                              \r
++                              StreamReader inStream  = File.OpenText(eFile);\r
++                              Stream       outStream = new BufferedStream(File.Create(tempFileName));\r
++                              \r
++                              while (true) {\r
++                                      string line = inStream.ReadLine();\r
++                                      if (line == null) {\r
++                                              break;\r
++                                      }\r
++                                      byte[] data = Encoding.ASCII.GetBytes(line);\r
++                                      outStream.Write(data, 0, data.Length);\r
++                                      outStream.WriteByte((byte)'\n');\r
++                              }\r
++                              \r
++                              inStream.Close();\r
++\r
++                              outStream.Flush();\r
++                              outStream.Close();\r
++                              \r
++                              entry.Size = new FileInfo(tempFileName).Length;\r
++                              \r
++                              eFile = tempFileName;\r
++                      }\r
++                      }\r
++                  \r
++                  string newName = null;\r
++              \r
++                      if (this.rootPath != null) {\r
++                              if (entry.Name.StartsWith(this.rootPath)) {\r
++                                      newName = entry.Name.Substring(this.rootPath.Length + 1 );\r
++                              }\r
++                      }\r
++                      \r
++                      if (this.pathPrefix != null) {\r
++                              newName = (newName == null) ? this.pathPrefix + "/" + entry.Name : this.pathPrefix + "/" + newName;\r
++                      }\r
++                      \r
++                      if (newName != null) {\r
++                              entry.Name = newName;\r
++                      }\r
++                      \r
++                      this.tarOut.PutNextEntry(entry);\r
++                      \r
++                      if (entry.IsDirectory) {\r
++                              if (recurse) {\r
++                                      TarEntry[] list = entry.GetDirectoryEntries();\r
++                                      for (int i = 0; i < list.Length; ++i) {\r
++                                              this.WriteEntry(list[i], recurse);\r
++                                      }\r
++                              }\r
++                      }\r
++         else {\r
++                              Stream inputStream = File.OpenRead(eFile);\r
++                              int numWritten = 0;\r
++                              byte[] eBuf = new byte[32 * 1024];\r
++                              while (true) {\r
++                                      int numRead = inputStream.Read(eBuf, 0, eBuf.Length);\r
++                                      \r
++                                      if (numRead <=0) {\r
++                                              break;\r
++                                      }\r
++                                      \r
++                                      this.tarOut.Write(eBuf, 0, numRead);\r
++                                      numWritten +=  numRead;\r
++                              }\r
++\r
++//                            Console.WriteLine("written " + numWritten + " bytes");\r
++                              \r
++                              inputStream.Close();\r
++                              \r
++                              if (tempFileName != null && tempFileName.Length > 0) {\r
++                                      File.Delete(tempFileName);\r
++                              }\r
++                              \r
++                              this.tarOut.CloseEntry();\r
++                      }\r
++              }\r
++      }\r
++}\r
++/* The original Java file had this header:\r
++      ** Authored by Timothy Gerard Endres\r
++      ** <mailto:time@gjt.org>  <http://www.trustice.com>\r
++      **\r
++      ** This work has been placed into the public domain.\r
++      ** You may use this work in any way and for any purpose you wish.\r
++      **\r
++      ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,\r
++      ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR\r
++      ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY\r
++      ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR\r
++      ** REDISTRIBUTION OF THIS SOFTWARE.\r
++      **\r
++      */\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b53b713e26d2976d2f4a9b6bc6f6e0a053fecb34
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,510 @@@
++// TarBuffer.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++//\r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++using System.Text;\r
++\r
++namespace ICSharpCode.SharpZipLib.Tar \r
++{\r
++      \r
++      /// <summary>\r
++      /// The TarBuffer class implements the tar archive concept\r
++      /// of a buffered input stream. This concept goes back to the\r
++      /// days of blocked tape drives and special io devices. In the\r
++      /// C# universe, the only real function that this class\r
++      /// performs is to ensure that files have the correct "record"\r
++      /// size, or other tars will complain.\r
++      /// <p>\r
++      /// You should never have a need to access this class directly.\r
++      /// TarBuffers are created by Tar IO Streams.\r
++      /// </p>\r
++      /// </summary>\r
++      public class TarBuffer\r
++      {\r
++\r
++/* A quote from GNU tar man file on blocking and records\r
++   A `tar' archive file contains a series of blocks.  Each block\r
++contains `BLOCKSIZE' bytes.  Although this format may be thought of as\r
++being on magnetic tape, other media are often used.\r
++\r
++   Each file archived is represented by a header block which describes\r
++the file, followed by zero or more blocks which give the contents of\r
++the file.  At the end of the archive file there may be a block filled\r
++with binary zeros as an end-of-file marker.  A reasonable system should\r
++write a block of zeros at the end, but must not assume that such a\r
++block exists when reading an archive.\r
++\r
++   The blocks may be "blocked" for physical I/O operations.  Each\r
++record of N blocks (where N is set by the `--blocking-factor=512-SIZE'\r
++(`-b 512-SIZE') option to `tar') is written with a single `write ()'\r
++operation.  On magnetic tapes, the result of such a write is a single\r
++record.  When writing an archive, the last record of blocks should be\r
++written at the full size, with blocks after the zero block containing\r
++all zeros.  When reading an archive, a reasonable system should\r
++properly handle an archive whose last record is shorter than the rest,\r
++or which contains garbage records after a zero block.\r
++*/\r
++\r
++//      public static readonly int DEFAULT_RCDSIZE = 512;\r
++//      public const int DEFAULT_BLOCKFACTOR = 20;\r
++//         public static readonly int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * DEFAULT_BLOCKFACTOR;\r
++\r
++      public static readonly int BlockSize = 512;\r
++      public static readonly int DefaultBlockFactor = 20;\r
++      public static readonly int DefaultRecordSize = BlockSize * DefaultBlockFactor;\r
++              \r
++              Stream inputStream;\r
++              Stream outputStream;\r
++              \r
++              byte[] recordBuffer;\r
++              int    currentBlockIndex;\r
++              int    currentRecordIndex;\r
++\r
++              int    recordSize = DefaultRecordSize;\r
++      public int RecordSize\r
++      {\r
++         get { return recordSize; }\r
++      }\r
++\r
++      int    blockFactor = DefaultBlockFactor;\r
++\r
++      public int BlockFactor\r
++      {\r
++         get { return blockFactor; }\r
++      }\r
++\r
++              bool   debug = false;\r
++\r
++      /// <summary>\r
++      /// Set the debugging flag for the buffer.\r
++      /// </summary>\r
++      public void SetDebug(bool debug)\r
++      {\r
++         this.debug = debug;\r
++      }\r
++              \r
++              \r
++              protected TarBuffer()\r
++              {\r
++              }\r
++              \r
++              public static TarBuffer CreateInputTarBuffer(Stream inputStream)\r
++              {\r
++                      return CreateInputTarBuffer(inputStream, TarBuffer.DefaultBlockFactor);\r
++              }\r
++\r
++              public static TarBuffer CreateInputTarBuffer(Stream inputStream, int blockFactor)\r
++              {\r
++                      TarBuffer tarBuffer = new TarBuffer();\r
++                      tarBuffer.inputStream  = inputStream;\r
++                      tarBuffer.outputStream = null;\r
++                      tarBuffer.Initialize(blockFactor);\r
++                      \r
++                      return tarBuffer;\r
++              }\r
++\r
++              public static TarBuffer CreateOutputTarBuffer(Stream outputStream)\r
++              {\r
++                      return CreateOutputTarBuffer(outputStream, TarBuffer.DefaultBlockFactor);\r
++              }\r
++\r
++              public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)\r
++              {\r
++                      TarBuffer tarBuffer = new TarBuffer();\r
++                      tarBuffer.inputStream  = null;\r
++                      tarBuffer.outputStream = outputStream;\r
++                      tarBuffer.Initialize(blockFactor);\r
++                      \r
++                      return tarBuffer;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Initialization common to all constructors.\r
++              /// </summary>\r
++              void Initialize(int blockFactor)\r
++              {\r
++                      this.debug        = false;\r
++         this.blockFactor  = blockFactor;\r
++         this.recordSize   = blockFactor * BlockSize;\r
++\r
++                      this.recordBuffer  = new byte[RecordSize];\r
++                      \r
++                      if (inputStream != null) \r
++                      {\r
++                              this.currentRecordIndex = -1;\r
++                              this.currentBlockIndex = BlockFactor;\r
++                      } \r
++                      else \r
++                      {\r
++            this.currentRecordIndex = 0;\r
++            this.currentBlockIndex = 0;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the TAR Buffer's block factor\r
++              /// </summary>\r
++              public int GetBlockFactor()\r
++              {\r
++                      return this.blockFactor;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the TAR Buffer's record size.\r
++              /// </summary>\r
++              public int GetRecordSize()\r
++              {\r
++                      return this.recordSize;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Determine if an archive block indicates End of Archive. End of\r
++              /// archive is indicated by a block that consists entirely of null bytes.\r
++              /// All remaining blocks for the record should also be null's\r
++              /// However some older tars only do a couple of null blocks (Old GNU tar for one)\r
++              /// and also partial records\r
++              /// </summary>\r
++              /// <param name = "block">\r
++              /// The block data to check.\r
++              /// </param>\r
++              public bool IsEOFBlock(byte[] block)\r
++              {\r
++                      for (int i = 0, sz = BlockSize; i < sz; ++i) \r
++                      {\r
++                              if (block[i] != 0) \r
++                              {\r
++                                      return false;\r
++                              }\r
++                      }\r
++                      \r
++                      return true;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Skip over a block on the input stream.\r
++              /// </summary>\r
++              public void SkipBlock()\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine("SkipBlock: recIdx = " + this.currentRecordIndex + " blkIdx = " + this.currentBlockIndex);\r
++                      }\r
++                      \r
++                      if (this.inputStream == null) \r
++                      {\r
++                              throw new System.IO.IOException("no input stream defined");\r
++                      }\r
++                      \r
++                      if (this.currentBlockIndex >= this.BlockFactor) \r
++                      {\r
++                              if (!this.ReadRecord()) \r
++                              {\r
++                                      return; // UNDONE\r
++                              }\r
++                      }\r
++                      \r
++                      this.currentBlockIndex++;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Read a block from the input stream and return the data.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The block data.\r
++              /// </returns>\r
++              public byte[] ReadBlock()\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine( "ReadBlock: blockIndex = " + this.currentBlockIndex + " recordIndex = " + this.currentRecordIndex );\r
++                      }\r
++                      \r
++                      if (this.inputStream == null) \r
++                      {\r
++                              throw new ApplicationException("TarBuffer.ReadBlock - no input stream defined");\r
++                      }\r
++                      \r
++                      if (this.currentBlockIndex >= this.BlockFactor) \r
++                      {\r
++                              if (!this.ReadRecord()) \r
++                              {\r
++                                      return null;\r
++                              }\r
++                      }\r
++                      \r
++                      byte[] result = new byte[BlockSize];\r
++                      \r
++                      Array.Copy(this.recordBuffer, (this.currentBlockIndex * BlockSize), result, 0, BlockSize );\r
++                      this.currentBlockIndex++;\r
++                      return result;\r
++              }\r
++              \r
++              /// <returns>\r
++              /// false if End-Of-File, else true\r
++              /// </returns>\r
++              bool ReadRecord()\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine("ReadRecord: recordIndex = " + this.currentRecordIndex);\r
++                      }\r
++                      \r
++                      if (this.inputStream == null) \r
++                      {\r
++                              throw new System.IO.IOException("no input stream stream defined");\r
++                      }\r
++                                              \r
++                      this.currentBlockIndex = 0;\r
++                      \r
++                      int offset = 0;\r
++                      int bytesNeeded = RecordSize;\r
++\r
++                      while (bytesNeeded > 0) \r
++                      {\r
++                              long numBytes = this.inputStream.Read(this.recordBuffer, offset, bytesNeeded);\r
++                              \r
++                              //\r
++                              // NOTE\r
++                              // We have found EOF, and the record is not full!\r
++                              //\r
++                              // This is a broken archive. It does not follow the standard\r
++                              // blocking algorithm. However, because we are generous, and\r
++                              // it requires little effort, we will simply ignore the error\r
++                              // and continue as if the entire record were read. This does\r
++                              // not appear to break anything upstream. We used to return\r
++                              // false in this case.\r
++                              //\r
++                              // Thanks to 'Yohann.Roussel@alcatel.fr' for this fix.\r
++                              //\r
++                              if (numBytes <= 0) \r
++                              {\r
++                                      break;\r
++                              }\r
++                              \r
++                              offset      += (int)numBytes;\r
++                              bytesNeeded -= (int)numBytes;\r
++                              if (numBytes != RecordSize)\r
++                              {\r
++                                      if (this.debug) \r
++                                      {\r
++                                              //Console.WriteLine.WriteLine("ReadRecord: INCOMPLETE READ " + numBytes + " of " + this.blockSize + " bytes read.");\r
++                                      }\r
++                              }\r
++                      }\r
++                      \r
++                      this.currentRecordIndex++;\r
++                      return true;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the current block number, within the current record, zero based.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The current zero based block number.\r
++              /// </returns>\r
++              public int GetCurrentBlockNum()\r
++              {\r
++                      return this.currentBlockIndex;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the current record number\r
++              /// Absolute block number in file = (currentRecordNum * block factor) + currentBlockNum.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The current zero based record number.\r
++              /// </returns>\r
++              public int GetCurrentRecordNum()\r
++              {\r
++                      return this.currentRecordIndex;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write an archive block to the archive.\r
++              /// </summary>\r
++              /// <param name="block">\r
++              /// The data to write to the archive.\r
++              /// </param>\r
++              /// \r
++              public void WriteBlock(byte[] block)\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine("WriteRecord: recIdx = " + this.currentRecordIndex + " blkIdx = " + this.currentBlockIndex );\r
++                      }\r
++                      \r
++                      if (this.outputStream == null) \r
++                      {\r
++                              throw new ApplicationException("TarBuffer.WriteBlock - no output stream defined");\r
++                      }\r
++                                              \r
++                      if (block.Length != BlockSize) \r
++                      {\r
++                              throw new ApplicationException("TarBuffer.WriteBlock - block to write has length '" + block.Length + "' which is not the block size of '" + BlockSize + "'" );\r
++                      }\r
++                      \r
++                      if (this.currentBlockIndex >= BlockFactor) \r
++                      {\r
++                              this.WriteRecord();\r
++                      }\r
++\r
++                      Array.Copy(block, 0, this.recordBuffer, (this.currentBlockIndex * BlockSize), BlockSize);\r
++                      this.currentBlockIndex++;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write an archive record to the archive, where the record may be\r
++              /// inside of a larger array buffer. The buffer must be "offset plus\r
++              /// record size" long.\r
++              /// </summary>\r
++              /// <param name="buf">\r
++              /// The buffer containing the record data to write.\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// The offset of the record data within buf.\r
++              /// </param>\r
++              public void WriteBlock(byte[] buf, int offset)\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine("WriteBlock: recIdx = " + this.currentRecordIndex + " blkIdx = " + this.currentBlockIndex );\r
++                      }\r
++                      \r
++                      if (this.outputStream == null) \r
++                      {\r
++                              throw new ApplicationException("TarBuffer.WriteBlock - no output stream stream defined");\r
++                      }\r
++                                              \r
++                      if ((offset + BlockSize) > buf.Length) \r
++                      {\r
++                              throw new ApplicationException("TarBuffer.WriteBlock - record has length '" + buf.Length + "' with offset '" + offset + "' which is less than the record size of '" + this.recordSize + "'" );\r
++                      }\r
++                      \r
++                      if (this.currentBlockIndex >= this.BlockFactor) \r
++                      {\r
++                              this.WriteRecord();\r
++                      }\r
++                      \r
++                      Array.Copy(buf, offset, this.recordBuffer, (this.currentBlockIndex * BlockSize), BlockSize);\r
++                      \r
++                      this.currentBlockIndex++;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write a TarBuffer record to the archive.\r
++              /// </summary>\r
++              void WriteRecord()\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine("Writerecord: record index = " + this.currentRecordIndex);\r
++                      }\r
++                      \r
++                      if (this.outputStream == null) \r
++                      {\r
++                              throw new ApplicationException("TarBuffer.WriteRecord no output stream defined");\r
++                      }\r
++                      \r
++                      this.outputStream.Write(this.recordBuffer, 0, RecordSize);\r
++                      this.outputStream.Flush();\r
++                      \r
++         this.currentBlockIndex = 0;\r
++         this.currentRecordIndex++;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Flush the current data block if it has any data in it.\r
++              /// </summary>\r
++              void Flush()\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine("TarBuffer.FlushBlock() called.");\r
++                      }\r
++                      \r
++                      if (this.outputStream == null) \r
++                      {\r
++                              throw new ApplicationException("TarBuffer.Flush no output stream defined");\r
++                      }\r
++                      \r
++                      if (this.currentBlockIndex > 0) \r
++                      {\r
++                              this.WriteRecord();\r
++                      }\r
++                      outputStream.Flush();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Close the TarBuffer. If this is an output buffer, also flush the\r
++              /// current block before closing.\r
++              /// </summary>\r
++              public void Close()\r
++              {\r
++                      if (this.debug) \r
++                      {\r
++                              //Console.WriteLine.WriteLine("TarBuffer.Close().");\r
++                      }\r
++                      \r
++                      if (outputStream != null)\r
++                      {\r
++                              Flush();\r
++      \r
++                              outputStream.Close();\r
++                              outputStream = null;\r
++                      } \r
++                      else if (inputStream != null) \r
++                      {\r
++                              inputStream.Close();\r
++                              inputStream = null;\r
++                      }\r
++              }\r
++      }\r
++}\r
++\r
++/* The original Java file had this header:\r
++      *\r
++      ** Authored by Timothy Gerard Endres\r
++      ** <mailto:time@gjt.org>  <http://www.trustice.com>\r
++      **\r
++      ** This work has been placed into the public domain.\r
++      ** You may use this work in any way and for any purpose you wish.\r
++      **\r
++      ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,\r
++      ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR\r
++      ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY\r
++      ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR\r
++      ** REDISTRIBUTION OF THIS SOFTWARE.\r
++      **\r
++      */\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a2c958fbf1dc4be6b345e14ff3bf003e1d40c4a5
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,567 @@@
++// TarEntry.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++using System.Text;\r
++\r
++namespace ICSharpCode.SharpZipLib.Tar \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class represents an entry in a Tar archive. It consists\r
++      /// of the entry's header, as well as the entry's File. Entries\r
++      /// can be instantiated in one of three ways, depending on how\r
++      /// they are to be used.\r
++      /// <p>\r
++      /// TarEntries that are created from the header bytes read from\r
++      /// an archive are instantiated with the TarEntry( byte[] )\r
++      /// constructor. These entries will be used when extracting from\r
++      /// or listing the contents of an archive. These entries have their\r
++      /// header filled in using the header bytes. They also set the File\r
++      /// to null, since they reference an archive entry not a file.</p>\r
++      /// <p>\r
++      /// TarEntries that are created from Files that are to be written\r
++      /// into an archive are instantiated with the TarEntry( File )\r
++      /// constructor. These entries have their header filled in using\r
++      /// the File's information. They also keep a reference to the File\r
++      /// for convenience when writing entries.</p>\r
++      /// <p>\r
++      /// Finally, TarEntries can be constructed from nothing but a name.\r
++      /// This allows the programmer to construct the entry by hand, for\r
++      /// instance when only an InputStream is available for writing to\r
++      /// the archive, and the header information is constructed from\r
++      /// other information. In this case the header fields are set to\r
++      /// defaults and the File is set to null.</p>\r
++      /// \r
++      /// <see cref="TarHeader"/>\r
++      /// </summary>\r
++      public class TarEntry\r
++      {\r
++              /// <summary>\r
++              /// If this entry represents a File, this references it.\r
++              /// </summary>\r
++              string    file;\r
++              \r
++              /// <summary>\r
++              /// This is the entry's header information.\r
++              /// </summary>\r
++              TarHeader       header;\r
++              \r
++              /// <summary>\r
++              /// Only Create Entries with the static CreateXYZ methods or a headerBuffer.\r
++              /// </summary>\r
++              private TarEntry()\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Construct an entry from an archive's header bytes. File is set\r
++              /// to null.\r
++              /// </summary>\r
++              /// <param name = "headerBuf">\r
++              /// The header bytes from a tar archive entry.\r
++              /// </param>\r
++              public TarEntry(byte[] headerBuf)\r
++              {\r
++                      this.Initialize();\r
++                      this.header.ParseBuffer(headerBuf);\r
++              }\r
++              \r
++\r
++      public TarEntry(TarHeader header)\r
++      {\r
++         file = null;\r
++         this.header = header;\r
++      }\r
++              \r
++              /// <summary>\r
++              /// Construct an entry with only a name. This allows the programmer\r
++              /// to construct the entry's header "by hand". File is set to null.\r
++              /// </summary>\r
++              public static TarEntry CreateTarEntry(string name)\r
++              {\r
++                      TarEntry entry = new TarEntry();\r
++                      entry.Initialize();\r
++                      entry.NameTarHeader(entry.header, name);\r
++                      return entry;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Construct an entry for a file. File is set to file, and the\r
++              /// header is constructed from information from the file.\r
++              /// </summary>\r
++              /// <param name = "fileName">\r
++              /// The file that the entry represents.\r
++              /// </param>\r
++              public static TarEntry CreateEntryFromFile(string fileName)\r
++              {\r
++                      TarEntry entry = new TarEntry();\r
++                      entry.Initialize();\r
++                      entry.GetFileTarHeader(entry.header, fileName);\r
++                      return entry;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Initialization code common to all pseudo constructors.\r
++              /// </summary>\r
++              void Initialize()\r
++              {\r
++                      this.file   = null;\r
++                      this.header = new TarHeader();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Determine if the two entries are equal. Equality is determined\r
++              /// by the header names being equal.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// True if the entries are equal.\r
++              /// </returns>\r
++              public override bool Equals(object it)\r
++              {\r
++                      if (!(it is TarEntry)) \r
++                      {\r
++                              return false;\r
++                      }\r
++                      return this.header.name.ToString().Equals(((TarEntry)it).header.name.ToString());\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Must be overridden when you override Equals.\r
++              /// </summary>\r
++              public override int GetHashCode()\r
++              {\r
++                      return this.header.name.ToString().GetHashCode();\r
++              }\r
++              \r
++              \r
++              /// <summary>\r
++              /// Determine if the given entry is a descendant of this entry.\r
++              /// Descendancy is determined by the name of the descendant\r
++              /// starting with this entry's name.\r
++              /// </summary>\r
++              /// <param name = "desc">\r
++              /// Entry to be checked as a descendent of this.\r
++              /// </param>\r
++              /// <returns>\r
++              /// True if entry is a descendant of this.\r
++              /// </returns>\r
++              public bool IsDescendent(TarEntry desc)\r
++              {\r
++                      return desc.header.name.ToString().StartsWith(this.header.name.ToString());\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get this entry's header.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// This entry's TarHeader.\r
++              /// </returns>\r
++              public TarHeader TarHeader \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get/Set this entry's name.\r
++              /// </summary>\r
++              public string Name \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header.name.ToString();\r
++                      }\r
++                      set \r
++                      {\r
++                              this.header.name = new StringBuilder(value);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get/set this entry's user id.\r
++              /// </summary>\r
++              public int UserId \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header.userId;\r
++                      }\r
++                      set \r
++                      {\r
++                              this.header.userId = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get/set this entry's group id.\r
++              /// </summary>\r
++              public int GroupId \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header.groupId;\r
++                      }\r
++                      set \r
++                      {\r
++                              this.header.groupId = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get/set this entry's user name.\r
++              /// </summary>\r
++              public string UserName \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header.userName.ToString();\r
++                      }\r
++                      set \r
++                      {\r
++                              this.header.userName = new StringBuilder(value);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get/set this entry's group name.\r
++              /// </summary>\r
++              public string GroupName \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header.groupName.ToString();\r
++                      }\r
++                      set \r
++                      {\r
++                              this.header.groupName = new StringBuilder(value);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Convenience method to set this entry's group and user ids.\r
++              /// </summary>\r
++              /// <param name="userId">\r
++              /// This entry's new user id.\r
++              /// </param>\r
++              /// <param name="groupId">\r
++              /// This entry's new group id.\r
++              /// </param>\r
++              public void SetIds(int userId, int groupId)\r
++              {\r
++                      UserId  = userId; \r
++                      GroupId = groupId;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Convenience method to set this entry's group and user names.\r
++              /// </summary>\r
++              /// <param name="userName">\r
++              /// This entry's new user name.\r
++              /// </param>\r
++              /// <param name="groupName">\r
++              /// This entry's new group name.\r
++              /// </param>\r
++              public void SetNames(string userName, string groupName)\r
++              {\r
++                      UserName  = userName;\r
++                      GroupName = groupName;\r
++              }\r
++\r
++              //      TODO :\r
++              //              /**\r
++              //              * Set this entry's modification time. The parameter passed\r
++              //              * to this method is in "Java time".\r
++              //              *\r
++              //              * @param time This entry's new modification time.\r
++              //              */\r
++              //              public void setModTime( long time )\r
++              //              {\r
++              //                      this.header.modTime = time / 1000;\r
++              //              }\r
++              \r
++              /// Convert time to DateTimes\r
++              /**\r
++              * Get/Set this entry's modification time.\r
++              *\r
++              * @param time This entry's new modification time.\r
++              */\r
++              public DateTime ModTime \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header.modTime;\r
++                      }\r
++                      set \r
++                      {\r
++                              this.header.modTime = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get this entry's file.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// This entry's file.\r
++              /// </returns>\r
++              public string File \r
++              {\r
++                      get \r
++                      {\r
++                              return this.file;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get/set this entry's file size.\r
++              /// </summary>\r
++              public long Size \r
++              {\r
++                      get \r
++                      {\r
++                              return this.header.size;\r
++                      }\r
++                      set \r
++                      {\r
++                              this.header.size = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Convenience method that will modify an entry's name directly\r
++              /// in place in an entry header buffer byte array.\r
++              /// </summary>\r
++              /// <param name="outbuf">\r
++              /// The buffer containing the entry header to modify.\r
++              /// </param>\r
++              /// <param name="newName">\r
++              /// The new name to place into the header buffer.\r
++              /// </param>\r
++              public void AdjustEntryName(byte[] outbuf, string newName)\r
++              {\r
++                      int offset = 0;\r
++                      offset = TarHeader.GetNameBytes(new StringBuilder(newName), outbuf, offset, TarHeader.NAMELEN);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Return whether or not this entry represents a directory.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// True if this entry is a directory.\r
++              /// </returns>\r
++              public bool IsDirectory\r
++              {\r
++                      get \r
++                      {\r
++                              if (this.file != null) \r
++                              {\r
++                                      return Directory.Exists(file);\r
++                              }\r
++                              \r
++                              if (this.header != null) \r
++                              {\r
++                                      if (this.header.typeFlag == TarHeader.LF_DIR || this.header.name.ToString().EndsWith( "/" )) \r
++                                      {\r
++                                              return true;\r
++                                      }\r
++                              }\r
++                              return false;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Fill in a TarHeader with information from a File.\r
++              /// </summary>\r
++              /// <param name="hdr">\r
++              /// The TarHeader to fill in.\r
++              /// </param>\r
++              /// <param name="file">\r
++              /// The file from which to get the header information.\r
++              /// </param>\r
++              public void GetFileTarHeader(TarHeader hdr, string file)\r
++              {\r
++                      this.file = file;\r
++\r
++                      // bugfix from torhovl from #D forum:\r
++                      string name = file;\r
++\r
++         // -jr- 23-Jan-2004 HAK HAK HAK, GnuTar allows device names in path where the name is not local to the current directory\r
++         if (Environment.CurrentDirectory == Path.GetDirectoryName(name))\r
++         {\r
++            name = Path.GetFileName(name);\r
++         }\r
++/*                    \r
++         if (Path.DirectorySeparatorChar == '\\') \r
++                      {  // check if the OS is Windows\r
++                              // Strip off drive letters!\r
++                              if (name.Length > 2) \r
++                              {\r
++                                      char ch1 = name[0];\r
++                                      char ch2 = name[1];\r
++                                      \r
++                                      if (ch2 == ':' && Char.IsLetter(ch1)) \r
++                                      {\r
++                                              name = name.Substring(2);\r
++                                      }\r
++                              }\r
++                      }\r
++*/\r
++                      \r
++                      name = name.Replace(Path.DirectorySeparatorChar, '/').ToLower();\r
++\r
++                      // No absolute pathnames\r
++                      // Windows (and Posix?) paths can start with UNC style "\\NetworkDrive\",\r
++                      // so we loop on starting /'s.\r
++                      while (name.StartsWith("/")) {\r
++                              name = name.Substring(1);\r
++                      }\r
++\r
++                      hdr.linkName = new StringBuilder(String.Empty);\r
++                      hdr.name     = new StringBuilder(name);\r
++                      \r
++                      if (Directory.Exists(file)) {\r
++                              hdr.mode     = 1003; // 01753 -jr- no octal constants!! 040755; // Magic number for security access for a UNIX filesystem\r
++                              hdr.typeFlag = TarHeader.LF_DIR;\r
++                              if (hdr.name.Length == 0 || hdr.name[hdr.name.Length - 1] != '/') {\r
++                                      hdr.name.Append("/");\r
++                              }\r
++                              \r
++                              hdr.size     = 0;\r
++                      } else {\r
++                              hdr.mode     = 33216; // 0100700 -jr-  // 0100644; // Magic number for security access for a UNIX filesystem\r
++                              hdr.typeFlag = TarHeader.LF_NORMAL;\r
++                              hdr.size     = new FileInfo(file.Replace('/', Path.DirectorySeparatorChar)).Length;\r
++                      }\r
++                      \r
++                      // UNDONE When File lets us get the userName, use it!\r
++         hdr.modTime = System.IO.File.GetLastWriteTimeUtc(file.Replace('/', Path.DirectorySeparatorChar)); // -jr- Unix times are in UTC\r
++         hdr.checkSum = 0;\r
++                      hdr.devMajor = 0;\r
++                      hdr.devMinor = 0;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// If this entry represents a file, and the file is a directory, return\r
++              /// an array of TarEntries for this entry's children.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// An array of TarEntry's for this entry's children.\r
++              /// </returns>\r
++              public TarEntry[] GetDirectoryEntries()\r
++              {\r
++                      if (this.file == null || !Directory.Exists(this.file)) \r
++                      {\r
++                              return new TarEntry[0];\r
++                      }\r
++                      \r
++                      string[]   list   = Directory.GetFileSystemEntries(this.file);\r
++                      TarEntry[] result = new TarEntry[list.Length];\r
++\r
++                      for (int i = 0; i < list.Length; ++i) \r
++                      {\r
++                              result[i] = TarEntry.CreateEntryFromFile(list[i]);\r
++                      }\r
++                      \r
++                      return result;\r
++              }\r
++              \r
++      /// <summary>\r
++              /// Write an entry's header information to a header buffer.\r
++              /// </summary>\r
++              /// <param name = "outbuf">\r
++              /// The tar entry header buffer to fill in.\r
++              /// </param>\r
++              public void WriteEntryHeader(byte[] outbuf)\r
++              {\r
++         this.header.WriteHeader(outbuf);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Fill in a TarHeader given only the entry's name.\r
++              /// </summary>\r
++              /// <param name="hdr">\r
++              /// The TarHeader to fill in.\r
++              /// </param>\r
++              /// <param name="name">\r
++              /// The tar entry name.\r
++              /// </param>\r
++              public void NameTarHeader(TarHeader hdr, string name)\r
++              {\r
++                      bool isDir = name.EndsWith("/");   // -jr- this is true for BSD tar but not all others I think?\r
++                      \r
++                      hdr.checkSum = 0;\r
++                      \r
++                      hdr.name = new StringBuilder(name);\r
++//                    hdr.mode = isDir ? 040755 : 0100644; // TODO : I think I've seen these magics before ...\r
++         hdr.mode = isDir ? 1003 : 33216;\r
++         hdr.userId   = 0;\r
++                      hdr.groupId  = 0;\r
++                      hdr.size     = 0;\r
++                      hdr.checkSum = 0;\r
++                      \r
++         hdr.modTime  = DateTime.UtcNow;        // -jr- 24-Jan-2004 Unix times are in utc!\r
++//                    hdr.modTime  = DateTime.Now;   // (new java.util.Date()).getTime() / 1000;\r
++                      \r
++                      hdr.typeFlag = isDir ? TarHeader.LF_DIR : TarHeader.LF_NORMAL;\r
++                      \r
++                      hdr.linkName  = new StringBuilder(String.Empty);\r
++                      hdr.userName  = new StringBuilder(String.Empty);\r
++                      hdr.groupName = new StringBuilder(String.Empty);\r
++                      \r
++                      hdr.devMajor = 0;\r
++                      hdr.devMinor = 0;\r
++              }\r
++      }\r
++}\r
++\r
++\r
++\r
++/* The original Java file had this header:\r
++      *\r
++      ** Authored by Timothy Gerard Endres\r
++      ** <mailto:time@gjt.org>  <http://www.trustice.com>\r
++      **\r
++      ** This work has been placed into the public domain.\r
++      ** You may use this work in any way and for any purpose you wish.\r
++      **\r
++      ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,\r
++      ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR\r
++      ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY\r
++      ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR\r
++      ** REDISTRIBUTION OF THIS SOFTWARE.\r
++      **\r
++      */\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..eb542452bcd556c11d6aae0949c482174ecf4673
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,753 @@@
++// TarHeader.cs\r
++//\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++\r
++/* The tar format and its POSIX successor PAX have a long history which makes for compatability\r
++   issues when creating and reading files...\r
++  \r
++This is the ustar (Posix 1003.1) header.\r
++\r
++struct header \r
++{\r
++   char t_name[100];          //   0 Filename               \r
++   char t_mode[8];            // 100 Permissions            \r
++   char t_uid[8];             // 108 Numerical User ID      \r
++   char t_gid[8];             // 116 Numerical Group ID     \r
++   char t_size[12];           // 124 Filesize               \r
++   char t_mtime[12];          // 136 st_mtime               \r
++   char t_chksum[8];          // 148 Checksum               \r
++   char t_typeflag;           // 156 Type of File            \r
++   char t_linkname[100];      // 157 Target of Links        \r
++   char t_magic[6];           // 257 "ustar"                \r
++   char t_version[2];         // 263 Version fixed to 00   \r
++   char t_uname[32];          // 265 User Name              \r
++   char t_gname[32];          // 297 Group Name             \r
++   char t_devmajor[8];        // 329 Major for devices      \r
++   char t_devminor[8];        // 337 Minor for devices      \r
++   char t_prefix[155];        // 345 Prefix for t_name      \r
++                              // 500 End                    \r
++   char t_mfill[12];          // 500 Filler up to 512       \r
++};\r
++\r
++*/\r
++\r
++using System;\r
++using System.Text;\r
++\r
++namespace ICSharpCode.SharpZipLib.Tar \r
++{\r
++      \r
++      \r
++      /// <summary>\r
++      /// This class encapsulates the Tar Entry Header used in Tar Archives.\r
++      /// The class also holds a number of tar constants, used mostly in headers.\r
++      /// </summary>\r
++      public class TarHeader : ICloneable\r
++      {\r
++              /// <summary>\r
++              /// The length of the name field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int NAMELEN = 100;\r
++              \r
++              /// <summary>\r
++              /// The length of the mode field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int MODELEN = 8;\r
++              \r
++              /// <summary>\r
++              /// The length of the user id field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int UIDLEN = 8;\r
++              \r
++              /// <summary>\r
++              /// The length of the group id field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int GIDLEN = 8;\r
++              \r
++              /// <summary>\r
++              /// The length of the checksum field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int CHKSUMLEN = 8;\r
++              \r
++              /// <summary>\r
++              /// The length of the size field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int SIZELEN = 12;\r
++              \r
++              /// <summary>\r
++              /// The length of the magic field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int MAGICLEN = 6;\r
++              \r
++      /// <summary>\r
++      /// The length of the version field in a header buffer.\r
++      /// </summary>\r
++      public readonly static int VERSIONLEN = 2;\r
++\r
++              /// <summary>\r
++              /// The length of the modification time field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int MODTIMELEN = 12;\r
++              \r
++              /// <summary>\r
++              /// The length of the user name field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int UNAMELEN = 32;\r
++              \r
++              /// <summary>\r
++              /// The length of the group name field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int GNAMELEN = 32;\r
++              \r
++              /// <summary>\r
++              /// The length of the devices field in a header buffer.\r
++              /// </summary>\r
++              public readonly static int DEVLEN = 8;\r
++              \r
++              /// <summary>\r
++              /// LF_ constants represents the "type" of an entry\r
++              /// </summary>\r
++              /// \r
++\r
++      /// <summary>\r
++      ///  This is the "old way" of indicating a normal file.\r
++      /// </summary>\r
++      public const byte       LF_OLDNORM      = 0;\r
++              \r
++              /// <summary>\r
++              /// Normal file type.\r
++              /// </summary>\r
++              public const byte       LF_NORMAL       = (byte) '0';\r
++              \r
++              /// <summary>\r
++              /// Link file type.\r
++              /// </summary>\r
++              public const byte       LF_LINK         = (byte) '1';\r
++              \r
++              /// <summary>\r
++              /// Symbolic link file type.\r
++              /// </summary>\r
++              public const byte       LF_SYMLINK      = (byte) '2';\r
++              \r
++              /// <summary>\r
++              /// Character device file type.\r
++              /// </summary>\r
++              public const byte       LF_CHR          = (byte) '3';\r
++              \r
++              /// <summary>\r
++              /// Block device file type.\r
++              /// </summary>\r
++              public const byte       LF_BLK          = (byte) '4';\r
++              \r
++              /// <summary>\r
++              /// Directory file type.\r
++              /// </summary>\r
++              public const byte       LF_DIR          = (byte) '5';\r
++              \r
++              /// <summary>\r
++              /// FIFO (pipe) file type.\r
++              /// </summary>\r
++              public const byte       LF_FIFO         = (byte) '6';\r
++              \r
++              /// <summary>\r
++              /// Contiguous file type.\r
++              /// </summary>\r
++              public const byte       LF_CONTIG       = (byte) '7';\r
++              \r
++              /// <summary>\r
++              /// Posix.1 2001 global extended header\r
++              /// </summary>\r
++              ///\r
++              public const byte   LF_GHDR    = (byte) 'g';\r
++              \r
++              /// <summary>\r
++              /// Posix.1 2001 extended header\r
++              /// </summary>\r
++              public readonly static byte   LF_XHDR    = (byte) 'x';\r
++              \r
++              \r
++              \r
++              \r
++              // POSIX allows for upper case ascii type as extensions\r
++              \r
++              // Solaris access control list\r
++              public const byte   LF_ACL            = (byte) 'A';\r
++              \r
++              // This is a dir entry that contains the names of files that were in the\r
++              // dir at the time the dump was made\r
++              public const byte   LF_GNU_DUMPDIR    = (byte) 'D';\r
++              \r
++              // Solaris Extended Attribute File\r
++              public const byte   LF_EXTATTR        = (byte) 'E' ;\r
++              \r
++              // Inode (metadata only) no file content\r
++              public const byte   LF_META           = (byte) 'I';\r
++              \r
++              // Identifies the next file on the tape as having a long link name\r
++              public const byte   LF_GNU_LONGLINK   = (byte) 'K';\r
++              \r
++              // Identifies the next file on the tape as having a long name\r
++              public const byte   LF_GNU_LONGNAME   = (byte) 'L';\r
++              \r
++              // Continuation of a file that began on another volume\r
++              public const byte   LF_GNU_MULTIVOL   = (byte) 'M';\r
++              \r
++              // For storing filenames that dont fit in the main header (old GNU)\r
++              public const byte   LF_GNU_NAMES      = (byte) 'N';\r
++              \r
++              // Sparse file\r
++              public const byte   LF_GNU_SPARSE     = (byte) 'S';\r
++              \r
++              // Tape/volume header ignore on extraction\r
++              public const byte   LF_GNU_VOLHDR     = (byte) 'V';\r
++              \r
++              /// <summary>\r
++              /// The magic tag representing a POSIX tar archive.  (includes trailing NULL)\r
++              /// </summary>\r
++              public readonly static string   TMAGIC          = "ustar ";\r
++              \r
++              /// <summary>\r
++              /// The magic tag representing an old GNU tar archive where version is included in magic and overwrites it\r
++              /// </summary>\r
++              public readonly static string   GNU_TMAGIC      = "ustar  ";\r
++              \r
++              /// <summary>\r
++              /// The entry's name.\r
++              /// </summary>\r
++              public StringBuilder name;\r
++              \r
++              /// <summary>\r
++              /// The entry's permission mode.\r
++              /// </summary>\r
++              public int mode;\r
++              \r
++              /// <summary>\r
++              /// The entry's user id.\r
++              /// </summary>\r
++              public int userId;\r
++              \r
++              /// <summary>\r
++              /// The entry's group id.\r
++              /// </summary>\r
++              public int groupId;\r
++              \r
++              /// <summary>\r
++              /// The entry's size.\r
++              /// </summary>\r
++              public long size;\r
++              \r
++              /// <summary>\r
++              /// The entry's modification time.\r
++              /// </summary>\r
++              public DateTime modTime;\r
++              \r
++              /// <summary>\r
++              /// The entry's checksum.\r
++              /// </summary>\r
++              public int checkSum;\r
++              \r
++              /// <summary>\r
++              /// The entry's type flag.\r
++              /// </summary>\r
++              public byte typeFlag;\r
++              \r
++              /// <summary>\r
++              /// The entry's link name.\r
++              /// </summary>\r
++              public StringBuilder linkName;\r
++              \r
++              /// <summary>\r
++              /// The entry's magic tag.\r
++              /// </summary>\r
++              public StringBuilder magic;\r
++              \r
++              /// <summary>\r
++              /// The entry's version.\r
++              /// </summary>\r
++              public StringBuilder version;\r
++              \r
++              /// <summary>\r
++              /// The entry's user name.\r
++              /// </summary>\r
++              public StringBuilder userName;\r
++              \r
++              /// <summary>\r
++              /// The entry's group name.\r
++              /// </summary>\r
++              public StringBuilder groupName;\r
++              \r
++              /// <summary>\r
++              /// The entry's major device number.\r
++              /// </summary>\r
++              public int devMajor;\r
++              \r
++              /// <summary>\r
++              /// The entry's minor device number.\r
++              /// </summary>\r
++              public int devMinor;\r
++              \r
++              public TarHeader()\r
++              {\r
++                      this.magic = new StringBuilder(TarHeader.TMAGIC);\r
++                      this.version = new StringBuilder(" ");\r
++                      \r
++                      this.name     = new StringBuilder();\r
++                      this.linkName = new StringBuilder();\r
++                      \r
++                      string user = Environment.UserName;\r
++                      //         string user = "PocketPC";\r
++                      //         string user = "Everyone";\r
++                      \r
++                      if (user.Length > 31) {\r
++                              user = user.Substring(0, 31);\r
++                      }\r
++                      \r
++                      this.userId    = 1003;  // -jr- was 0\r
++                      this.groupId   = 513;   // -jr- was 0\r
++                      this.userName  = new StringBuilder(user);\r
++// -jr-\r
++//                    this.groupName = new StringBuilder(String.Empty);\r
++//         this.groupName = new StringBuilder("Everyone");  Attempt2\r
++         this.groupName = new StringBuilder("None"); // Gnu compatible\r
++         this.size      = 0;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// TarHeaders can be cloned.\r
++              /// </summary>\r
++              public object Clone()\r
++              {\r
++                      TarHeader hdr = new TarHeader();\r
++                      \r
++                      hdr.name      = (this.name == null) ? null : new StringBuilder(this.name.ToString());\r
++                      hdr.mode      = this.mode;\r
++                      hdr.userId    = this.userId;\r
++                      hdr.groupId   = this.groupId;\r
++                      hdr.size      = this.size;\r
++                      hdr.modTime   = this.modTime;\r
++                      hdr.checkSum  = this.checkSum;\r
++                      hdr.typeFlag  = this.typeFlag;\r
++                      hdr.linkName  = (this.linkName == null)  ? null : new StringBuilder(this.linkName.ToString());\r
++                      hdr.magic     = (this.magic == null)     ? null : new StringBuilder(this.magic.ToString());\r
++         hdr.version   = (this.version == null)   ? null : new StringBuilder(this.version.ToString());\r
++                      hdr.userName  = (this.userName == null)  ? null : new StringBuilder(this.userName.ToString());\r
++                      hdr.groupName = (this.groupName == null) ? null : new StringBuilder(this.groupName.ToString());\r
++                      hdr.devMajor  = this.devMajor;\r
++                      hdr.devMinor  = this.devMinor;\r
++                      \r
++                      return hdr;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the name of this entry.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The entry's name.\r
++              /// </returns>\r
++              public string GetName()\r
++              {\r
++                      return this.name.ToString();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Parse an octal string from a header buffer. This is used for the\r
++              /// file permission mode value.\r
++              /// </summary>\r
++              /// <param name = "header">\r
++              /// The header buffer from which to parse.\r
++              /// </param>\r
++              /// <param name = "offset">\r
++              /// The offset into the buffer from which to parse.\r
++              /// </param>\r
++              /// <param name = "length">\r
++              /// The number of header bytes to parse.\r
++              /// </param>\r
++              /// <returns>\r
++              /// The long value of the octal string.\r
++              /// </returns>\r
++              public static long ParseOctal(byte[] header, int offset, int length)\r
++              {\r
++                      long result = 0;\r
++                      bool stillPadding = true;\r
++                      \r
++                      int end = offset + length;\r
++                      for (int i = offset; i < end ; ++i) \r
++                      {\r
++                              if (header[i] == 0) \r
++                              {\r
++                                      break;\r
++                              }\r
++                              \r
++                              if (header[i] == (byte)' ' || header[i] == '0') \r
++                              {\r
++                                      if (stillPadding) \r
++                                      {\r
++                                              continue;\r
++                                      }\r
++                                      \r
++                                      if (header[i] == (byte)' ') \r
++                                      {\r
++                                              break;\r
++                                      }\r
++                              }\r
++                              \r
++                              stillPadding = false;\r
++                              \r
++                              result = (result << 3) + (header[i] - '0');\r
++                      }\r
++                      \r
++                      return result;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Parse an entry name from a header buffer.\r
++              /// </summary>\r
++              /// <param name="header">\r
++              /// The header buffer from which to parse.\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// The offset into the buffer from which to parse.\r
++              /// </param>\r
++              /// <param name="length">\r
++              /// The number of header bytes to parse.\r
++              /// </param>\r
++              /// <returns>\r
++              /// The header's entry name.\r
++              /// </returns>\r
++              public static StringBuilder ParseName(byte[] header, int offset, int length)\r
++              {\r
++                      StringBuilder result = new StringBuilder(length);\r
++                      \r
++                      for (int i = offset; i < offset + length; ++i) \r
++                      {\r
++                              if (header[i] == 0) \r
++                              {\r
++                                      break;\r
++                              }\r
++                              result.Append((char)header[i]);\r
++                      }\r
++                      \r
++                      return result;\r
++              }\r
++              \r
++      public static int GetNameBytes(StringBuilder name, int nameOffset, byte[] buf, int bufferOffset, int length)\r
++      {\r
++         int i;\r
++                      \r
++         for (i = 0 ; i < length && nameOffset + i < name.Length; ++i) \r
++         {\r
++            buf[bufferOffset + i] = (byte)name[nameOffset + i];\r
++         }\r
++                      \r
++         for (; i < length ; ++i) \r
++         {\r
++            buf[bufferOffset + i] = 0;\r
++         }\r
++                      \r
++         return bufferOffset + length;\r
++      }\r
++\r
++      /// <summary>\r
++              /// Determine the number of bytes in an entry name.\r
++              /// </summary>\r
++              /// <param name="name">\r
++              /// </param>\r
++              /// <param name="buf">\r
++              /// The header buffer from which to parse.\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// The offset into the buffer from which to parse.\r
++              /// </param>\r
++              /// <param name="length">\r
++              /// The number of header bytes to parse.\r
++              /// </param>\r
++              /// <returns>\r
++              /// The number of bytes in a header's entry name.\r
++              /// </returns>\r
++              public static int GetNameBytes(StringBuilder name, byte[] buf, int offset, int length)\r
++              {\r
++         return GetNameBytes(name, 0, buf, offset, length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Parse an octal integer from a header buffer.\r
++              /// </summary>\r
++              /// <param name = "val">\r
++              /// </param>\r
++              /// <param name = "buf">\r
++              /// The header buffer from which to parse.\r
++              /// </param>\r
++              /// <param name = "offset">\r
++              /// The offset into the buffer from which to parse.\r
++              /// </param>\r
++              /// <param name = "length">\r
++              /// The number of header bytes to parse.\r
++              /// </param>\r
++              /// <returns>\r
++              /// The integer value of the octal bytes.\r
++              /// </returns>\r
++              public static int GetOctalBytes(long val, byte[] buf, int offset, int length)\r
++              {\r
++         // TODO check for values too large...\r
++\r
++                      int idx = length - 1;\r
++\r
++                      // Either a space or null is valid here.  We use NULL as per GNUTar\r
++                      buf[offset + idx] = 0;\r
++                      --idx;\r
++\r
++         if (val > 0)\r
++                      {\r
++                              for (long v = val; idx >= 0 && v > 0; --idx) \r
++                              {\r
++                                      buf[offset + idx] = (byte)((byte)'0' + (byte)(v & 7));\r
++                                      v >>= 3;\r
++                              }\r
++                      }\r
++                              \r
++                      for (; idx >= 0; --idx) \r
++                      {\r
++            buf[offset + idx] = (byte)'0';\r
++                      }\r
++                      \r
++                      return offset + length;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Parse an octal long integer from a header buffer.\r
++              /// </summary>\r
++              /// <param name = "val">\r
++              /// </param>\r
++              /// <param name = "buf">\r
++              /// The header buffer from which to parse.\r
++              /// </param>\r
++              /// <param name = "offset">\r
++              /// The offset into the buffer from which to parse.\r
++              /// </param>\r
++              /// <param name = "length">\r
++              /// The number of header bytes to parse.\r
++              /// </param>\r
++              /// <returns>\r
++              /// The long value of the octal bytes.\r
++              /// </returns>\r
++              public static int GetLongOctalBytes(long val, byte[] buf, int offset, int length)\r
++              {\r
++         return GetOctalBytes(val, buf, offset, length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Add the checksum octal integer to header buffer.\r
++              /// </summary>\r
++              /// <param name = "val">\r
++              /// </param>\r
++              /// <param name = "buf">\r
++              /// The header buffer to set the checksum for\r
++              /// </param>\r
++              /// <param name = "offset">\r
++              /// The offset into the buffer for the checksum\r
++              /// </param>\r
++              /// <param name = "length">\r
++              /// The number of header bytes to update.\r
++      /// It's formatted differently from the other fields: it has 6 digits, a\r
++      /// null, then a space -- rather than digits, a space, then a null.\r
++      /// The final space is already there, from checksumming\r
++\r
++              /// </param>\r
++              /// <returns>\r
++              /// The modified buffer offset\r
++              /// </returns>\r
++              private static int GetCheckSumOctalBytes(long val, byte[] buf, int offset, int length)\r
++              {\r
++                      TarHeader.GetOctalBytes(val, buf, offset, length - 1);\r
++//                    buf[offset + length - 1] = (byte)' ';  -jr- 23-Jan-2004 this causes failure!!!\r
++//                    buf[offset + length - 2] = 0;\r
++                      return offset + length;\r
++              }\r
++              \r
++      /// <summary>\r
++      /// Compute the checksum for a tar entry header.  \r
++      /// The checksum field must be all spaces prior to this happening\r
++      /// </summary>\r
++      /// <param name = "buf">\r
++      /// The tar entry's header buffer.\r
++      /// </param>\r
++      /// <returns>\r
++      /// The computed checksum.\r
++      /// </returns>\r
++      private static long ComputeCheckSum(byte[] buf)\r
++      {\r
++         long sum = 0;\r
++         for (int i = 0; i < buf.Length; ++i) \r
++         {\r
++            sum += buf[i];\r
++         }\r
++         return sum;\r
++      }\r
++\r
++      readonly static long     timeConversionFactor = 10000000L;                                    // -jr- 1 tick == 100 nanoseconds\r
++      readonly static DateTime datetTime1970        = new DateTime(1970, 1, 1, 0, 0, 0, 0); \r
++//      readonly static DateTime datetTime1970        = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime(); // -jr- Should be UTC?  doesnt match Gnutar if this is so though, why?\r
++              \r
++      static int GetCTime(System.DateTime dateTime)\r
++      {\r
++         return (int)((dateTime.Ticks - datetTime1970.Ticks) / timeConversionFactor);\r
++      }\r
++              \r
++      static DateTime GetDateTimeFromCTime(long ticks)\r
++      {\r
++         return new DateTime(datetTime1970.Ticks + ticks * timeConversionFactor);\r
++      }\r
++\r
++      /// <summary>\r
++      /// Parse TarHeader information from a header buffer.\r
++      /// </summary>\r
++      /// <param name = "header">\r
++      /// The tar entry header buffer to get information from.\r
++      /// </param>\r
++      public void ParseBuffer(byte[] header)\r
++      {\r
++         int offset = 0;\r
++                      \r
++         name = TarHeader.ParseName(header, offset, TarHeader.NAMELEN);\r
++         offset += TarHeader.NAMELEN;\r
++                      \r
++         mode = (int)TarHeader.ParseOctal(header, offset, TarHeader.MODELEN);\r
++         offset += TarHeader.MODELEN;\r
++                      \r
++         userId = (int)TarHeader.ParseOctal(header, offset, TarHeader.UIDLEN);\r
++         offset += TarHeader.UIDLEN;\r
++                      \r
++         groupId = (int)TarHeader.ParseOctal(header, offset, TarHeader.GIDLEN);\r
++         offset += TarHeader.GIDLEN;\r
++                      \r
++         size = TarHeader.ParseOctal(header, offset, TarHeader.SIZELEN);\r
++         offset += TarHeader.SIZELEN;\r
++                      \r
++         modTime = GetDateTimeFromCTime(TarHeader.ParseOctal(header, offset, TarHeader.MODTIMELEN));\r
++         offset += TarHeader.MODTIMELEN;\r
++                      \r
++         checkSum = (int)TarHeader.ParseOctal(header, offset, TarHeader.CHKSUMLEN);\r
++         offset += TarHeader.CHKSUMLEN;\r
++                      \r
++         typeFlag = header[ offset++ ];\r
++\r
++         linkName = TarHeader.ParseName(header, offset, TarHeader.NAMELEN);\r
++         offset += TarHeader.NAMELEN;\r
++                      \r
++         magic = TarHeader.ParseName(header, offset, TarHeader.MAGICLEN);\r
++         offset += TarHeader.MAGICLEN;\r
++\r
++         version = TarHeader.ParseName(header, offset, TarHeader.VERSIONLEN);\r
++         offset += TarHeader.VERSIONLEN;\r
++                      \r
++         userName = TarHeader.ParseName(header, offset, TarHeader.UNAMELEN);\r
++         offset += TarHeader.UNAMELEN;\r
++                      \r
++         groupName = TarHeader.ParseName(header, offset, TarHeader.GNAMELEN);\r
++         offset += TarHeader.GNAMELEN;\r
++                      \r
++         devMajor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);\r
++         offset += TarHeader.DEVLEN;\r
++                      \r
++         devMinor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);\r
++\r
++         // Fields past this point not currently parsed or used...\r
++      }\r
++\r
++      /// <summary>\r
++      /// 'Write' header information to buffer provided\r
++      /// </summary>\r
++      /// <param name="outbuf">output buffer for header information</param>\r
++      public void WriteHeader(byte[] outbuf)\r
++      {\r
++         int offset = 0;\r
++                      \r
++         offset = GetNameBytes(this.name, outbuf, offset, TarHeader.NAMELEN);\r
++         offset = GetOctalBytes(this.mode, outbuf, offset, TarHeader.MODELEN);\r
++         offset = GetOctalBytes(this.userId, outbuf, offset, TarHeader.UIDLEN);\r
++         offset = GetOctalBytes(this.groupId, outbuf, offset, TarHeader.GIDLEN);\r
++                      \r
++         long size = this.size;\r
++                      \r
++         offset = GetLongOctalBytes(size, outbuf, offset, TarHeader.SIZELEN);\r
++         offset = GetLongOctalBytes(GetCTime(this.modTime), outbuf, offset, TarHeader.MODTIMELEN);\r
++                      \r
++         int csOffset = offset;\r
++         for (int c = 0; c < TarHeader.CHKSUMLEN; ++c) \r
++         {\r
++            outbuf[offset++] = (byte)' ';\r
++         }\r
++                      \r
++         outbuf[offset++] = this.typeFlag;\r
++                      \r
++         offset = GetNameBytes(this.linkName, outbuf, offset, NAMELEN);\r
++         offset = GetNameBytes(this.magic, outbuf, offset, MAGICLEN);\r
++         offset = GetNameBytes(this.version, outbuf, offset, VERSIONLEN);\r
++         offset = GetNameBytes(this.userName, outbuf, offset, UNAMELEN);\r
++         offset = GetNameBytes(this.groupName, outbuf, offset, GNAMELEN);\r
++\r
++         if (this.typeFlag == LF_CHR || this.typeFlag == LF_BLK)\r
++         {\r
++            offset = GetOctalBytes(this.devMajor, outbuf, offset, DEVLEN);\r
++            offset = GetOctalBytes(this.devMinor, outbuf, offset, DEVLEN);\r
++         }\r
++                      \r
++         for ( ; offset < outbuf.Length; ) \r
++         {\r
++            outbuf[offset++] = 0;\r
++         }\r
++                      \r
++         long checkSum = ComputeCheckSum(outbuf);\r
++                      \r
++         GetCheckSumOctalBytes(checkSum, outbuf, csOffset, CHKSUMLEN);\r
++      }\r
++   }\r
++}\r
++\r
++/* The original Java file had this header:\r
++ * \r
++** Authored by Timothy Gerard Endres\r
++** <mailto:time@gjt.org>  <http://www.trustice.com>\r
++** \r
++** This work has been placed into the public domain.\r
++** You may use this work in any way and for any purpose you wish.\r
++**\r
++** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,\r
++** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR\r
++** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY\r
++** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR\r
++** REDISTRIBUTION OF THIS SOFTWARE. \r
++** \r
++*/\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..4ba1de45ea2cba5a26389303f370e1cea40db600
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,646 @@@
++// TarInputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++//\r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++using System.Text;\r
++\r
++namespace ICSharpCode.SharpZipLib.Tar \r
++{\r
++      \r
++      /// <summary>\r
++      /// The TarInputStream reads a UNIX tar archive as an InputStream.\r
++      /// methods are provided to position at each successive entry in\r
++      /// the archive, and the read each entry as a normal input stream\r
++      /// using read().\r
++      /// </summary>\r
++      public class TarInputStream : Stream\r
++      {\r
++              protected bool debug;\r
++              protected bool hasHitEOF;\r
++              \r
++              protected int entrySize;\r
++              protected int entryOffset;\r
++              \r
++              protected byte[] readBuf;\r
++              \r
++              protected TarBuffer buffer;\r
++              protected TarEntry  currEntry;\r
++              protected IEntryFactory eFactory;\r
++              \r
++              Stream inputStream;\r
++\r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanRead \r
++              {\r
++                      get \r
++                      {\r
++                              return inputStream.CanRead;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanSeek \r
++              {\r
++         // TODO is this valid?  should it return false?\r
++                      get \r
++                      {\r
++                              return inputStream.CanSeek;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanWrite \r
++              {\r
++                      get \r
++                      {\r
++                              return inputStream.CanWrite;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Length \r
++              {\r
++                      get \r
++                      {\r
++                              return inputStream.Length;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Position \r
++              {\r
++                      get \r
++                      {\r
++                              return inputStream.Position;\r
++                      }\r
++                      set \r
++                      {\r
++                              inputStream.Position = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Flushes the baseInputStream\r
++              /// </summary>\r
++              public override void Flush()\r
++              {\r
++                      inputStream.Flush();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Seek(long offset, SeekOrigin origin)\r
++              {\r
++         // TODO allow this?\r
++                      return inputStream.Seek(offset, origin);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void SetLength(long val)\r
++              {\r
++                      inputStream.SetLength(val);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void Write(byte[] array, int offset, int count)\r
++              {\r
++                      inputStream.Write(array, offset, count);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void WriteByte(byte val)\r
++              {\r
++                      inputStream.WriteByte(val);\r
++              }\r
++                      \r
++              \r
++              public TarInputStream(Stream inputStream) : this(inputStream, TarBuffer.DefaultBlockFactor)\r
++              {\r
++              }\r
++              \r
++              public TarInputStream(Stream inputStream, int blockFactor)\r
++              {\r
++                      this.inputStream = inputStream;\r
++                      this.buffer      = TarBuffer.CreateInputTarBuffer(inputStream, blockFactor);\r
++                      \r
++                      this.readBuf   = null;\r
++                      this.debug     = false;\r
++                      this.hasHitEOF = false;\r
++                      this.eFactory  = null;\r
++              }\r
++              \r
++              public void SetDebug(bool debugFlag)\r
++              {\r
++                      this.debug = debugFlag;\r
++                      SetBufferDebug(debugFlag);\r
++              }\r
++\r
++              public void SetBufferDebug(bool debug)\r
++              {\r
++                      this.buffer.SetDebug(debug);\r
++              }\r
++              \r
++              \r
++              \r
++              public void SetEntryFactory(IEntryFactory factory)\r
++              {\r
++                      this.eFactory = factory;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Closes this stream. Calls the TarBuffer's close() method.\r
++              /// The underlying stream is closed by the TarBuffer.\r
++              /// </summary>\r
++              public override void Close()\r
++              {\r
++                      this.buffer.Close();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the record size being used by this stream's TarBuffer.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// TarBuffer record size.\r
++              /// </returns>\r
++              public int GetRecordSize()\r
++              {\r
++                      return this.buffer.GetRecordSize();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the available data that can be read from the current\r
++              /// entry in the archive. This does not indicate how much data\r
++              /// is left in the entire archive, only in the current entry.\r
++              /// This value is determined from the entry's size header field\r
++              /// and the amount of data already read from the current entry.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The number of available bytes for the current entry.\r
++              /// </returns>\r
++              public int Available \r
++              {\r
++                      get \r
++                      {\r
++                              return this.entrySize - this.entryOffset;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Skip bytes in the input buffer. This skips bytes in the\r
++              /// current entry's data, not the entire archive, and will\r
++              /// stop at the end of the current entry's data if the number\r
++              /// to skip extends beyond that point.\r
++              /// </summary>\r
++              /// <param name="numToSkip">\r
++              /// The number of bytes to skip.\r
++              /// </param>\r
++              public void Skip(int numToSkip)\r
++              {\r
++                      // TODO REVIEW\r
++                      // This is horribly inefficient, but it ensures that we\r
++                      // properly skip over bytes via the TarBuffer...\r
++                      //\r
++                      byte[] skipBuf = new byte[8 * 1024];\r
++                      \r
++                      for (int num = numToSkip; num > 0;)\r
++                      {\r
++                              int numRead = this.Read(skipBuf, 0, (num > skipBuf.Length ? skipBuf.Length : num));\r
++                              \r
++                              if (numRead == -1) \r
++                              {\r
++                                      break;\r
++                              }\r
++                              \r
++                              num -= numRead;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Since we do not support marking just yet, we return false.\r
++              /// </summary>\r
++              public bool IsMarkSupported \r
++              {\r
++                      get \r
++                      {\r
++                              return false;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Since we do not support marking just yet, we do nothing.\r
++              /// </summary>\r
++              /// <param name ="markLimit">\r
++              /// The limit to mark.\r
++              /// </param>\r
++              public void Mark(int markLimit)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Since we do not support marking just yet, we do nothing.\r
++              /// </summary>\r
++              public void Reset()\r
++              {\r
++              }\r
++\r
++      void SkipToNextEntry()\r
++      {\r
++         int numToSkip = this.entrySize - this.entryOffset;\r
++                              \r
++         if (this.debug) \r
++         {\r
++            //Console.WriteLine.WriteLine("TarInputStream: SKIP currENTRY '" + this.currEntry.Name + "' SZ " + this.entrySize + " OFF " + this.entryOffset + "  skipping " + numToSkip + " bytes");\r
++         }\r
++                              \r
++         if (numToSkip > 0) \r
++         {\r
++            this.Skip(numToSkip);\r
++         }\r
++                              \r
++         this.readBuf = null;\r
++      }\r
++\r
++              /// <summary>\r
++              /// Get the next entry in this tar archive. This will skip\r
++              /// over any remaining data in the current entry, if there\r
++              /// is one, and place the input stream at the header of the\r
++              /// next entry, and read the header and instantiate a new\r
++              /// TarEntry from the header bytes and return that entry.\r
++              /// If there are no more entries in the archive, null will\r
++              /// be returned to indicate that the end of the archive has\r
++              /// been reached.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The next TarEntry in the archive, or null.\r
++              /// </returns>\r
++              public TarEntry GetNextEntry()\r
++              {\r
++                      if (this.hasHitEOF) \r
++                      {\r
++                              return null;\r
++                      }\r
++                      \r
++                      if (this.currEntry != null) \r
++                      {\r
++            SkipToNextEntry();\r
++                      }\r
++                      \r
++                      byte[] headerBuf = this.buffer.ReadBlock();\r
++                      \r
++                      if (headerBuf == null) \r
++                      {\r
++                              if (this.debug) \r
++                              {\r
++                                      //Console.WriteLine.WriteLine("READ NULL BLOCK");\r
++                              }\r
++                              \r
++                              this.hasHitEOF = true;\r
++                      } \r
++                      else if (this.buffer.IsEOFBlock(headerBuf)) \r
++                      {\r
++                              if (this.debug) \r
++                              {\r
++                                      //Console.WriteLine.WriteLine( "READ EOF BLOCK" );\r
++                              }\r
++                              \r
++                              this.hasHitEOF = true;\r
++                      }\r
++                      \r
++                      if (this.hasHitEOF) \r
++                      {\r
++                              this.currEntry = null;\r
++                      } \r
++                      else \r
++                      {\r
++                              try \r
++                              {\r
++               TarHeader header = new TarHeader();\r
++               header.ParseBuffer(headerBuf);\r
++               this.entryOffset = 0;\r
++               this.entrySize = (int)header.size;\r
++\r
++               StringBuilder longName = null;\r
++\r
++               if (header.typeFlag == TarHeader.LF_GNU_LONGNAME)\r
++               {\r
++                  Console.WriteLine("TarInputStream: Long name found '" + header.name + "' size = " + header.size); // DEBUG\r
++\r
++                  byte[] nameBuffer = new byte[TarBuffer.BlockSize];\r
++\r
++                  int numToRead = this.entrySize;\r
++\r
++                  longName = new StringBuilder();\r
++\r
++                  while (numToRead > 0)\r
++                  {\r
++                     int numRead = this.Read(nameBuffer, 0, (numToRead > nameBuffer.Length ? nameBuffer.Length : numToRead));\r
++                              \r
++                     if (numRead == -1) \r
++                     {\r
++                        throw new InvalidHeaderException("Failed to read long name entry");\r
++                     }\r
++                              \r
++                     longName.Append(TarHeader.ParseName(nameBuffer, 0, numRead).ToString());\r
++                     numToRead -= numRead;\r
++                  }\r
++\r
++                  Console.WriteLine("TarInputStream: Long name is '" + longName.ToString()); // DEBUG\r
++\r
++                  SkipToNextEntry();\r
++                  headerBuf = this.buffer.ReadBlock();\r
++               }\r
++               else if (header.typeFlag == TarHeader.LF_GHDR) // POSIX global extended header\r
++               {\r
++                  // Ignore things we dont understand completely for now\r
++                  SkipToNextEntry();\r
++                  headerBuf = this.buffer.ReadBlock();\r
++               }\r
++               else if (header.typeFlag == TarHeader.LF_XHDR)     // POSIX extended header\r
++               {\r
++                  // Ignore things we dont understand completely for now\r
++                  SkipToNextEntry();\r
++                  headerBuf = this.buffer.ReadBlock();\r
++               }\r
++               else if (header.typeFlag == TarHeader.LF_GNU_VOLHDR)\r
++               {\r
++                  // TODO could show volume name when verbose?\r
++                  SkipToNextEntry();\r
++                  headerBuf = this.buffer.ReadBlock();\r
++               }\r
++               else if (header.typeFlag != TarHeader.LF_NORMAL\r
++                  && header.typeFlag != TarHeader.LF_OLDNORM)\r
++               {\r
++                  // Ignore things we dont understand completely for now\r
++                  SkipToNextEntry();\r
++                  headerBuf = this.buffer.ReadBlock();\r
++               }\r
++\r
++               if (this.eFactory == null) \r
++                                      {\r
++                  this.currEntry = new TarEntry(headerBuf);\r
++                  if (longName != null)\r
++                  {\r
++                     this.currEntry.TarHeader.name.Length = 0;\r
++                     this.currEntry.TarHeader.name.Append(longName.ToString());\r
++                  }\r
++                                      } \r
++                                      else \r
++                                      {\r
++                  this.currEntry = this.eFactory.CreateEntry(headerBuf);\r
++                                      }\r
++\r
++                                      // TODO -jr- ustar is not the only magic possible by any means\r
++               // tar, xtar, ... \r
++                                      if (!(headerBuf[257] == 'u' && headerBuf[258] == 's' && headerBuf[259] == 't' && headerBuf[260] == 'a' && headerBuf[261] == 'r')) \r
++                                      {\r
++                                              throw new InvalidHeaderException("header magic is not 'ustar', but '" + headerBuf[257] + headerBuf[258] + headerBuf[259] + headerBuf[260] + headerBuf[261] + \r
++                                                      "', or (dec) " + ((int)headerBuf[257]) + ", " + ((int)headerBuf[258]) + ", " + ((int)headerBuf[259]) + ", " + ((int)headerBuf[260]) + ", " + ((int)headerBuf[261]));\r
++                                      }\r
++                                              \r
++                                      if (this.debug) \r
++                                      {\r
++                                              //Console.WriteLine.WriteLine("TarInputStream: SET CURRENTRY '" + this.currEntry.Name + "' size = " + this.currEntry.Size);\r
++                                      }\r
++                      \r
++                                      this.entryOffset = 0;\r
++                                      \r
++                                      // TODO REVIEW How do we resolve this discrepancy?!\r
++                                      this.entrySize = (int) this.currEntry.Size;\r
++                              } \r
++                              catch (InvalidHeaderException ex) \r
++                              {\r
++                                      this.entrySize = 0;\r
++                                      this.entryOffset = 0;\r
++                                      this.currEntry = null;\r
++                                      throw new InvalidHeaderException("bad header in record " + this.buffer.GetCurrentBlockNum() + " block " + this.buffer.GetCurrentBlockNum() + ", " + ex.Message);\r
++                              }\r
++                      }\r
++                      return this.currEntry;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Reads a byte from the current tar archive entry.\r
++              /// This method simply calls read(byte[], int, int).\r
++              /// </summary>\r
++              public override int ReadByte()\r
++              {\r
++                      byte[] oneByteBuffer = new byte[1];\r
++                      int num = this.Read(oneByteBuffer, 0, 1);\r
++                      if (num <= 0)               // return -1 to indicate that no byte was read.\r
++                      {\r
++                              return -1;\r
++                      }\r
++                      return (int)oneByteBuffer[0];\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Reads bytes from the current tar archive entry.\r
++              /// \r
++              /// This method is aware of the boundaries of the current\r
++              /// entry in the archive and will deal with them appropriately\r
++              /// </summary>\r
++              /// <param name="outputBuffer">\r
++              /// The buffer into which to place bytes read.\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// The offset at which to place bytes read.\r
++              /// </param>\r
++              /// <param name="numToRead">\r
++              /// The number of bytes to read.\r
++              /// </param>\r
++              /// <returns>\r
++              /// The number of bytes read, or 0 at end of stream/EOF.\r
++              /// </returns>\r
++              public override int Read(byte[] outputBuffer, int offset, int numToRead)\r
++              {\r
++                      int totalRead = 0;\r
++                      \r
++                      if (this.entryOffset >= this.entrySize) \r
++                      {\r
++                              return 0;\r
++                      }\r
++                      \r
++                      if ((numToRead + this.entryOffset) > this.entrySize) \r
++                      {\r
++                              numToRead = this.entrySize - this.entryOffset;\r
++                      }\r
++                      \r
++                      if (this.readBuf != null) \r
++                      {\r
++                              int sz = (numToRead > this.readBuf.Length) ? this.readBuf.Length : numToRead;\r
++                              \r
++                              Array.Copy(this.readBuf, 0, outputBuffer, offset, sz);\r
++                              \r
++                              if (sz >= this.readBuf.Length) \r
++                              {\r
++                                      this.readBuf = null;\r
++                              } \r
++                              else \r
++                              {\r
++                                      int newLen = this.readBuf.Length - sz;\r
++                                      byte[] newBuf = new byte[newLen];\r
++                                      Array.Copy(this.readBuf, sz, newBuf, 0, newLen);\r
++                                      this.readBuf = newBuf;\r
++                              }\r
++                              \r
++                              totalRead += sz;\r
++                              numToRead -= sz;\r
++                              offset += sz;\r
++                      }\r
++                      \r
++                      while (numToRead > 0) \r
++                      {\r
++                              byte[] rec = this.buffer.ReadBlock();\r
++                              if (rec == null) \r
++                              {\r
++                                      // Unexpected EOF!\r
++                                      throw new IOException("unexpected EOF with " + numToRead + " bytes unread");\r
++                              }\r
++                              \r
++                              int sz     = numToRead;\r
++                              int recLen = rec.Length;\r
++                              \r
++                              if (recLen > sz) \r
++                              {\r
++                                      Array.Copy(rec, 0, outputBuffer, offset, sz);\r
++                                      this.readBuf = new byte[recLen - sz];\r
++                                      Array.Copy(rec, sz, this.readBuf, 0, recLen - sz);\r
++                              } \r
++                              else \r
++                              {\r
++                                      sz = recLen;\r
++                                      Array.Copy(rec, 0, outputBuffer, offset, recLen);\r
++                              }\r
++                              \r
++                              totalRead += sz;\r
++                              numToRead -= sz;\r
++                              offset += sz;\r
++                      }\r
++                      \r
++                      this.entryOffset += totalRead;\r
++                      \r
++                      return totalRead;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Copies the contents of the current tar archive entry directly into\r
++              /// an output stream.\r
++              /// </summary>\r
++              /// <param name="outputStream">\r
++              /// The OutputStream into which to write the entry's data.\r
++              /// </param>\r
++              public void CopyEntryContents(Stream outputStream)\r
++              {\r
++                      byte[] buf = new byte[32 * 1024];\r
++                      \r
++                      while (true) \r
++                      {\r
++                              int numRead = this.Read(buf, 0, buf.Length);\r
++                              if (numRead <= 0) \r
++                              {\r
++                                      break;\r
++                              }\r
++                              outputStream.Write(buf, 0, numRead);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// This interface is provided, with the method setEntryFactory(), to allow\r
++              /// the programmer to have their own TarEntry subclass instantiated for the\r
++              /// entries return from getNextEntry().\r
++              /// </summary>\r
++              public interface IEntryFactory\r
++              {\r
++                      TarEntry CreateEntry(string name);\r
++                      \r
++                      TarEntry CreateEntryFromFile(string fileName);\r
++                      \r
++                      TarEntry CreateEntry(byte[] headerBuf);\r
++              }\r
++              \r
++              public class EntryFactoryAdapter : IEntryFactory\r
++              {\r
++                      public TarEntry CreateEntry(string name)\r
++                      {\r
++                              return TarEntry.CreateTarEntry(name);\r
++                      }\r
++                      \r
++                      public TarEntry CreateEntryFromFile(string fileName)\r
++                      {\r
++                              return TarEntry.CreateEntryFromFile(fileName);\r
++                      }\r
++                      \r
++                      public TarEntry CreateEntry(byte[] headerBuf)\r
++                      {\r
++                              return new TarEntry(headerBuf);\r
++                      }\r
++              }\r
++      }\r
++      \r
++      \r
++}\r
++\r
++/* The original Java file had this header:\r
++      ** Authored by Timothy Gerard Endres\r
++      ** <mailto:time@gjt.org>  <http://www.trustice.com>\r
++      **\r
++      ** This work has been placed into the public domain.\r
++      ** You may use this work in any way and for any purpose you wish.\r
++      **\r
++      ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,\r
++      ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR\r
++      ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY\r
++      ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR\r
++      ** REDISTRIBUTION OF THIS SOFTWARE.\r
++      **\r
++      */\r
++      \r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..632bed33adc7ba098deacbfb0b2a80f102df664a
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,422 @@@
++// TarOutputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++using System.Text;\r
++\r
++namespace ICSharpCode.SharpZipLib.Tar \r
++{\r
++      \r
++      /// <summary>\r
++      /// The TarOutputStream writes a UNIX tar archive as an OutputStream.\r
++      /// Methods are provided to put entries, and then write their contents\r
++      /// by writing to this stream using write().\r
++      /// </summary>\r
++      /// public\r
++      public class TarOutputStream : Stream\r
++      {\r
++              protected bool   debug;\r
++              protected int    currSize;\r
++              protected int    currBytes;\r
++              protected byte[] blockBuf;        \r
++              protected int    assemLen;\r
++              protected byte[] assemBuf;\r
++              \r
++              protected TarBuffer buffer;\r
++              protected Stream    outputStream;\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanRead \r
++              {\r
++                      get \r
++                      {\r
++                              return outputStream.CanRead;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanSeek \r
++              {\r
++                      get \r
++                      {\r
++                              return outputStream.CanSeek;     // -jr- Should be false?\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanWrite \r
++              {\r
++                      get \r
++                      {\r
++                              return outputStream.CanWrite;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Length \r
++              {\r
++                      get \r
++                      {\r
++                              return outputStream.Length;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Position \r
++              {\r
++                      get \r
++                      {\r
++                              return outputStream.Position;\r
++                      }\r
++                      set \r
++                      {\r
++                              outputStream.Position = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Seek(long offset, SeekOrigin origin)\r
++              {\r
++                      return outputStream.Seek(offset, origin);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void SetLength(long val)\r
++              {\r
++                      outputStream.SetLength(val);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override int ReadByte()\r
++              {\r
++                      return outputStream.ReadByte();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override int Read(byte[] b, int off, int len)\r
++              {\r
++                      return outputStream.Read(b, off, len);\r
++              }\r
++              \r
++              public override void Flush()\r
++              {\r
++                      outputStream.Flush();\r
++              }\r
++                              \r
++              public TarOutputStream(Stream outputStream) : this(outputStream, TarBuffer.DefaultBlockFactor)\r
++              {\r
++              }\r
++              \r
++              public TarOutputStream(Stream outputStream, int blockFactor)\r
++              {\r
++                      this.outputStream = outputStream;\r
++                      this.buffer       = TarBuffer.CreateOutputTarBuffer(outputStream, blockFactor);\r
++                      \r
++                      this.debug     = false;\r
++                      this.assemLen  = 0;\r
++                      this.assemBuf  = new byte[TarBuffer.BlockSize];\r
++                      this.blockBuf = new byte[TarBuffer.BlockSize];\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the debugging flag.\r
++              /// </summary>\r
++              /// <param name = "debugFlag">\r
++              /// True to turn on debugging.\r
++              /// </param>\r
++              public void SetDebug(bool debugFlag)\r
++              {\r
++                      this.debug = debugFlag;\r
++                      SetBufferDebug(debugFlag);\r
++              }\r
++              \r
++              public void SetBufferDebug(bool debug)\r
++              {\r
++                      this.buffer.SetDebug(debug);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Ends the TAR archive without closing the underlying OutputStream.\r
++              /// The result is that the EOF record of nulls is written.\r
++              /// </summary>\r
++              public void Finish()\r
++              {\r
++                      this.WriteEOFRecord();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Ends the TAR archive and closes the underlying OutputStream.\r
++              /// This means that finish() is called followed by calling the\r
++              /// TarBuffer's close().\r
++              /// </summary>\r
++              public override void Close()\r
++              {\r
++                      this.Finish();\r
++                      this.buffer.Close();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Get the record size being used by this stream's TarBuffer.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// The TarBuffer record size.\r
++              /// </returns>\r
++              public int GetRecordSize()\r
++              {\r
++                      return this.buffer.GetRecordSize();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Put an entry on the output stream. This writes the entry's\r
++              /// header and positions the output stream for writing\r
++              /// the contents of the entry. Once this method is called, the\r
++              /// stream is ready for calls to write() to write the entry's\r
++              /// contents. Once the contents are written, closeEntry()\r
++              /// <B>MUST</B> be called to ensure that all buffered data\r
++              /// is completely written to the output stream.\r
++              /// </summary>\r
++              /// <param name="entry">\r
++              /// The TarEntry to be written to the archive.\r
++              /// </param>\r
++              public void PutNextEntry(TarEntry entry)\r
++              {\r
++                      if (entry.TarHeader.name.Length > TarHeader.NAMELEN) \r
++                      {\r
++            TarHeader longHeader = new TarHeader();\r
++            longHeader.typeFlag = TarHeader.LF_GNU_LONGNAME;\r
++            longHeader.name.Append("././@LongLink");\r
++            longHeader.userId = 0;\r
++            longHeader.groupId = 0;\r
++            longHeader.groupName.Length = 0;\r
++            longHeader.userName.Length = 0;\r
++            longHeader.linkName.Length = 0;\r
++\r
++            longHeader.size = entry.TarHeader.name.Length;\r
++\r
++            Console.WriteLine("TarOutputStream: PutNext entry Long name found size = " + longHeader.size); // DEBUG\r
++\r
++            longHeader.WriteHeader(this.blockBuf);\r
++            this.buffer.WriteBlock(this.blockBuf);  // Add special long filename header block\r
++\r
++            int nameCharIndex = 0;\r
++\r
++            while (nameCharIndex < entry.TarHeader.name.Length)\r
++            {\r
++                      TarHeader.GetNameBytes(entry.TarHeader.name, nameCharIndex, this.blockBuf, 0, TarBuffer.BlockSize);\r
++               nameCharIndex += TarBuffer.BlockSize;\r
++               this.buffer.WriteBlock(this.blockBuf);\r
++            }\r
++                      }\r
++                      \r
++                      entry.WriteEntryHeader(this.blockBuf);\r
++                      this.buffer.WriteBlock(this.blockBuf);\r
++                      \r
++                      this.currBytes = 0;\r
++                      \r
++                      this.currSize = entry.IsDirectory ? 0 : (int)entry.Size;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Close an entry. This method MUST be called for all file\r
++              /// entries that contain data. The reason is that we must\r
++              /// buffer data written to the stream in order to satisfy\r
++              /// the buffer's block based writes. Thus, there may be\r
++              /// data fragments still being assembled that must be written\r
++              /// to the output stream before this entry is closed and the\r
++              /// next entry written.\r
++              /// </summary>\r
++              public void CloseEntry()\r
++              {\r
++                      if (this.assemLen > 0) \r
++                      {\r
++                              for (int i = this.assemLen; i < this.assemBuf.Length; ++i) \r
++                              {\r
++                                      this.assemBuf[i] = 0;\r
++                              }\r
++                              \r
++                              this.buffer.WriteBlock(this.assemBuf);\r
++                              \r
++                              this.currBytes += this.assemLen;\r
++                              this.assemLen = 0;\r
++                      }\r
++                      \r
++                      if (this.currBytes < this.currSize) \r
++                      {\r
++                              throw new IOException("entry closed at '" + this.currBytes + "' before the '" + this.currSize + "' bytes specified in the header were written");\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Writes a byte to the current tar archive entry.\r
++              /// This method simply calls Write(byte[], int, int).\r
++              /// </summary>\r
++              /// <param name="b">\r
++              /// The byte written.\r
++              /// </param>\r
++              public override void WriteByte(byte b)\r
++              {\r
++                      this.Write(new byte[] { b }, 0, 1);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Writes bytes to the current tar archive entry. This method\r
++              /// is aware of the current entry and will throw an exception if\r
++              /// you attempt to write bytes past the length specified for the\r
++              /// current entry. The method is also (painfully) aware of the\r
++              /// record buffering required by TarBuffer, and manages buffers\r
++              /// that are not a multiple of recordsize in length, including\r
++              /// assembling records from small buffers.\r
++              /// </summary>\r
++              /// <param name = "wBuf">\r
++              /// The buffer to write to the archive.\r
++              /// </param>\r
++              /// <param name = "wOffset">\r
++              /// The offset in the buffer from which to get bytes.\r
++              /// </param>\r
++              /// <param name = "numToWrite">\r
++              /// The number of bytes to write.\r
++              /// </param>\r
++              public override void Write(byte[] wBuf, int wOffset, int numToWrite)\r
++              {\r
++                      if ((this.currBytes + numToWrite) > this.currSize) \r
++                      {\r
++                              throw new IOException("request to write '" + numToWrite + "' bytes exceeds size in header of '" + this.currSize + "' bytes");\r
++                      }\r
++                      \r
++                      //\r
++                      // We have to deal with assembly!!!\r
++                      // The programmer can be writing little 32 byte chunks for all\r
++                      // we know, and we must assemble complete records for writing.\r
++                      // REVIEW Maybe this should be in TarBuffer? Could that help to\r
++                      //        eliminate some of the buffer copying.\r
++                      //\r
++                      if (this.assemLen > 0) \r
++                      {\r
++                              if ((this.assemLen + numToWrite ) >= this.blockBuf.Length) \r
++                              {\r
++                                      int aLen = this.blockBuf.Length - this.assemLen;\r
++                                      \r
++                                      Array.Copy(this.assemBuf, 0, this.blockBuf, 0, this.assemLen);\r
++                                      \r
++                                      Array.Copy(wBuf, wOffset, this.blockBuf, this.assemLen, aLen);\r
++                                      \r
++                                      this.buffer.WriteBlock(this.blockBuf);\r
++                                      \r
++                                      this.currBytes += this.blockBuf.Length;\r
++                                      \r
++                                      wOffset    += aLen;\r
++                                      numToWrite -= aLen;\r
++                                      \r
++                                      this.assemLen = 0;\r
++                              } \r
++                              else \r
++                              {// ( (this.assemLen + numToWrite ) < this.blockBuf.length )\r
++                                      Array.Copy(wBuf, wOffset, this.assemBuf, this.assemLen, numToWrite);\r
++                                      wOffset       += numToWrite;\r
++                                      this.assemLen += numToWrite;\r
++                                      numToWrite -= numToWrite;\r
++                              }\r
++                      }\r
++                      \r
++                      //\r
++                      // When we get here we have EITHER:\r
++                      //   o An empty "assemble" buffer.\r
++                      //   o No bytes to write (numToWrite == 0)\r
++                      //\r
++                      while (numToWrite > 0) \r
++                      {\r
++                              if (numToWrite < this.blockBuf.Length) \r
++                              {\r
++                                      Array.Copy(wBuf, wOffset, this.assemBuf, this.assemLen, numToWrite);\r
++                                      this.assemLen += numToWrite;\r
++                                      break;\r
++                              }\r
++                              \r
++                              this.buffer.WriteBlock(wBuf, wOffset);\r
++                              \r
++                              int num = this.blockBuf.Length;\r
++                              this.currBytes += num;\r
++                              numToWrite     -= num;\r
++                              wOffset        += num;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write an EOF (end of archive) record to the tar archive.\r
++              /// An EOF record consists of a record of all zeros.\r
++              /// </summary>\r
++              void WriteEOFRecord()\r
++              {\r
++                      for (int i = 0; i < this.blockBuf.Length; ++i) \r
++                      {\r
++                              this.blockBuf[i] = 0;\r
++                      }\r
++                      this.buffer.WriteBlock(this.blockBuf);\r
++              }\r
++      }\r
++}\r
++\r
++/* The original Java file had this header:\r
++      ** Authored by Timothy Gerard Endres\r
++      ** <mailto:time@gjt.org>  <http://www.trustice.com>\r
++      **\r
++      ** This work has been placed into the public domain.\r
++      ** You may use this work in any way and for any purpose you wish.\r
++      **\r
++      ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,\r
++      ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR\r
++      ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY\r
++      ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR\r
++      ** REDISTRIBUTION OF THIS SOFTWARE.\r
++      **\r
++      */\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..bb8d4cc3ca81ab2a3126f9b3697070aee222c1e0
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,542 @@@
++// Deflater.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      /// <summary>\r
++      /// This is the Deflater class.  The deflater class compresses input\r
++      /// with the deflate algorithm described in RFC 1951.  It has several\r
++      /// compression levels and three different strategies described below.\r
++      ///\r
++      /// This class is <i>not</i> thread safe.  This is inherent in the API, due\r
++      /// to the split of deflate and setInput.\r
++      /// \r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      public class Deflater\r
++      {\r
++              /// <summary>\r
++              /// The best and slowest compression level.  This tries to find very\r
++              /// long and distant string repetitions.\r
++              /// </summary>\r
++              public static  int BEST_COMPRESSION = 9;\r
++              \r
++              /// <summary>\r
++              /// The worst but fastest compression level.\r
++              /// </summary>\r
++              public static  int BEST_SPEED = 1;\r
++              \r
++              /// <summary>\r
++              /// The default compression level.\r
++              /// </summary>\r
++              public static  int DEFAULT_COMPRESSION = -1;\r
++              \r
++              /// <summary>\r
++              /// This level won't compress at all but output uncompressed blocks.\r
++              /// </summary>\r
++              public static  int NO_COMPRESSION = 0;\r
++                              \r
++              /// <summary>\r
++              /// The compression method.  This is the only method supported so far.\r
++              /// There is no need to use this constant at all.\r
++              /// </summary>\r
++              public static  int DEFLATED = 8;\r
++              \r
++              /*\r
++              * The Deflater can do the following state transitions:\r
++                      *\r
++                      * (1) -> INIT_STATE   ----> INIT_FINISHING_STATE ---.\r
++                      *        /  | (2)      (5)                         |\r
++                      *       /   v          (5)                         |\r
++                      *   (3)| SETDICT_STATE ---> SETDICT_FINISHING_STATE |(3)\r
++                      *       \   | (3)                 |        ,-------'\r
++                      *        |  |                     | (3)   /\r
++                      *        v  v          (5)        v      v\r
++                      * (1) -> BUSY_STATE   ----> FINISHING_STATE\r
++                      *                                | (6)\r
++                      *                                v\r
++                      *                           FINISHED_STATE\r
++                      *    \_____________________________________/\r
++                      *          | (7)\r
++                      *          v\r
++                      *        CLOSED_STATE\r
++                      *\r
++                      * (1) If we should produce a header we start in INIT_STATE, otherwise\r
++                      *     we start in BUSY_STATE.\r
++                      * (2) A dictionary may be set only when we are in INIT_STATE, then\r
++                      *     we change the state as indicated.\r
++                      * (3) Whether a dictionary is set or not, on the first call of deflate\r
++                      *     we change to BUSY_STATE.\r
++                      * (4) -- intentionally left blank -- :)\r
++                      * (5) FINISHING_STATE is entered, when flush() is called to indicate that\r
++                      *     there is no more INPUT.  There are also states indicating, that\r
++                      *     the header wasn't written yet.\r
++                      * (6) FINISHED_STATE is entered, when everything has been flushed to the\r
++                      *     internal pending output buffer.\r
++                      * (7) At any time (7)\r
++                      *\r
++                      */\r
++                      \r
++              private static  int IS_SETDICT              = 0x01;\r
++              private static  int IS_FLUSHING             = 0x04;\r
++              private static  int IS_FINISHING            = 0x08;\r
++              \r
++              private static  int INIT_STATE              = 0x00;\r
++              private static  int SETDICT_STATE           = 0x01;\r
++              //              private static  int INIT_FINISHING_STATE    = 0x08;\r
++              //              private static  int SETDICT_FINISHING_STATE = 0x09;\r
++              private static  int BUSY_STATE              = 0x10;\r
++              private static  int FLUSHING_STATE          = 0x14;\r
++              private static  int FINISHING_STATE         = 0x1c;\r
++              private static  int FINISHED_STATE          = 0x1e;\r
++              private static  int CLOSED_STATE            = 0x7f;\r
++              \r
++              /// <summary>\r
++              /// Compression level.\r
++              /// </summary>\r
++              private int level;\r
++              \r
++              /// <summary>\r
++              /// should we include a header.\r
++              /// </summary>\r
++              private bool noHeader;\r
++              \r
++              //              /// <summary>\r
++              //              /// Compression strategy.\r
++              //              /// </summary>\r
++              //              private int strategy;\r
++              \r
++              /// <summary>\r
++              /// The current state.\r
++              /// </summary>\r
++              private int state;\r
++              \r
++              /// <summary>\r
++              /// The total bytes of output written.\r
++              /// </summary>\r
++              private int totalOut;\r
++              \r
++              /// <summary>\r
++              /// The pending output.\r
++              /// </summary>\r
++              private DeflaterPending pending;\r
++              \r
++              /// <summary>\r
++              /// The deflater engine.\r
++              /// </summary>\r
++              private DeflaterEngine engine;\r
++              \r
++              /// <summary>\r
++              /// Creates a new deflater with default compression level.\r
++              /// </summary>\r
++              public Deflater() : this(DEFAULT_COMPRESSION, false)\r
++              {\r
++                      \r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new deflater with given compression level.\r
++              /// </summary>\r
++              /// <param name="lvl">\r
++              /// the compression level, a value between NO_COMPRESSION\r
++              /// and BEST_COMPRESSION, or DEFAULT_COMPRESSION.\r
++              /// </param>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">if lvl is out of range.</exception>\r
++              public Deflater(int lvl) : this(lvl, false)\r
++              {\r
++                      \r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new deflater with given compression level.\r
++              /// </summary>\r
++              /// <param name="lvl">\r
++              /// the compression level, a value between NO_COMPRESSION\r
++              /// and BEST_COMPRESSION.\r
++              /// </param>\r
++              /// <param name="nowrap">\r
++              /// true, if we should suppress the deflate header at the\r
++              /// beginning and the adler checksum at the end of the output.  This is\r
++              /// useful for the GZIP format.\r
++              /// </param>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">if lvl is out of range.</exception>\r
++              public Deflater(int lvl, bool nowrap)\r
++              {\r
++                      if (lvl == DEFAULT_COMPRESSION) {\r
++                              lvl = 6;\r
++                      } else if (lvl < NO_COMPRESSION || lvl > BEST_COMPRESSION) {\r
++                              throw new ArgumentOutOfRangeException("lvl");\r
++                      }\r
++                      \r
++                      pending = new DeflaterPending();\r
++                      engine = new DeflaterEngine(pending);\r
++                      this.noHeader = nowrap;\r
++                      SetStrategy(DeflateStrategy.Default);\r
++                      SetLevel(lvl);\r
++                      Reset();\r
++              }\r
++              \r
++              \r
++              /// <summary>\r
++              /// Resets the deflater.  The deflater acts afterwards as if it was\r
++              /// just created with the same compression level and strategy as it\r
++              /// had before.\r
++              /// </summary>\r
++              public void Reset()\r
++              {\r
++                      state = (noHeader ? BUSY_STATE : INIT_STATE);\r
++                      totalOut = 0;\r
++                      pending.Reset();\r
++                      engine.Reset();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the current adler checksum of the data that was processed so far.\r
++              /// </summary>\r
++              public int Adler {\r
++                      get {\r
++                              return engine.Adler;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the number of input bytes processed so far.\r
++              /// </summary>\r
++              public int TotalIn {\r
++                      get {\r
++                              return engine.TotalIn;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the number of output bytes so far.\r
++              /// </summary>\r
++              public int TotalOut {\r
++                      get {\r
++                              return totalOut;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Flushes the current input block.  Further calls to deflate() will\r
++              /// produce enough output to inflate everything in the current input\r
++              /// block.  This is not part of Sun's JDK so I have made it package\r
++              /// private.  It is used by DeflaterOutputStream to implement\r
++              /// flush().\r
++              /// </summary>\r
++              public void Flush() \r
++              {\r
++                      state |= IS_FLUSHING;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Finishes the deflater with the current input block.  It is an error\r
++              /// to give more input after this method was called.  This method must\r
++              /// be called to force all bytes to be flushed.\r
++              /// </summary>\r
++              public void Finish() \r
++              {\r
++                      state |= IS_FLUSHING | IS_FINISHING;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns true if the stream was finished and no more output bytes\r
++              /// are available.\r
++              /// </summary>\r
++              public bool IsFinished {\r
++                      get {\r
++                              return state == FINISHED_STATE && pending.IsFlushed;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns true, if the input buffer is empty.\r
++              /// You should then call setInput(). \r
++              /// NOTE: This method can also return true when the stream\r
++              /// was finished.\r
++              /// </summary>\r
++              public bool IsNeedingInput {\r
++                      get {\r
++                              return engine.NeedsInput();\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the data which should be compressed next.  This should be only\r
++              /// called when needsInput indicates that more input is needed.\r
++              /// If you call setInput when needsInput() returns false, the\r
++              /// previous input that is still pending will be thrown away.\r
++              /// The given byte array should not be changed, before needsInput() returns\r
++              /// true again.\r
++              /// This call is equivalent to <code>setInput(input, 0, input.length)</code>.\r
++              /// </summary>\r
++              /// <param name="input">\r
++              /// the buffer containing the input data.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if the buffer was finished() or ended().\r
++              /// </exception>\r
++              public void SetInput(byte[] input)\r
++              {\r
++                      SetInput(input, 0, input.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the data which should be compressed next.  This should be\r
++              /// only called when needsInput indicates that more input is needed.\r
++              /// The given byte array should not be changed, before needsInput() returns\r
++              /// true again.\r
++              /// </summary>\r
++              /// <param name="input">\r
++              /// the buffer containing the input data.\r
++              /// </param>\r
++              /// <param name="off">\r
++              /// the start of the data.\r
++              /// </param>\r
++              /// <param name="len">\r
++              /// the length of the data.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if the buffer was finished() or ended() or if previous input is still pending.\r
++              /// </exception>\r
++              public void SetInput(byte[] input, int off, int len)\r
++              {\r
++                      if ((state & IS_FINISHING) != 0) {\r
++                              throw new InvalidOperationException("finish()/end() already called");\r
++                      }\r
++                      engine.SetInput(input, off, len);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the compression level.  There is no guarantee of the exact\r
++              /// position of the change, but if you call this when needsInput is\r
++              /// true the change of compression level will occur somewhere near\r
++              /// before the end of the so far given input.\r
++              /// </summary>\r
++              /// <param name="lvl">\r
++              /// the new compression level.\r
++              /// </param>\r
++              public void SetLevel(int lvl)\r
++              {\r
++                      if (lvl == DEFAULT_COMPRESSION) {\r
++                              lvl = 6;\r
++                      } else if (lvl < NO_COMPRESSION || lvl > BEST_COMPRESSION) {\r
++                              throw new ArgumentOutOfRangeException("lvl");\r
++                      }\r
++                      \r
++                      if (level != lvl) {\r
++                              level = lvl;\r
++                              engine.SetLevel(lvl);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the compression strategy. Strategy is one of\r
++              /// DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED.  For the exact\r
++              /// position where the strategy is changed, the same as for\r
++              /// setLevel() applies.\r
++              /// </summary>\r
++              /// <param name="stgy">\r
++              /// the new compression strategy.\r
++              /// </param>\r
++              public void SetStrategy(DeflateStrategy stgy)\r
++              {\r
++                      engine.Strategy = stgy;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Deflates the current input block to the given array.  It returns\r
++              /// the number of bytes compressed, or 0 if either\r
++              /// needsInput() or finished() returns true or length is zero.\r
++              /// </summary>\r
++              /// <param name="output">\r
++              /// the buffer where to write the compressed data.\r
++              /// </param>\r
++              public int Deflate(byte[] output)\r
++              {\r
++                      return Deflate(output, 0, output.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Deflates the current input block to the given array.  It returns\r
++              /// the number of bytes compressed, or 0 if either\r
++              /// needsInput() or finished() returns true or length is zero.\r
++              /// </summary>\r
++              /// <param name="output">\r
++              /// the buffer where to write the compressed data.\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// the offset into the output array.\r
++              /// </param>\r
++              /// <param name="length">\r
++              /// the maximum number of bytes that may be written.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if end() was called.\r
++              /// </exception>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if offset and/or length don't match the array length.\r
++              /// </exception>\r
++              public int Deflate(byte[] output, int offset, int length)\r
++              {\r
++                      int origLength = length;\r
++                      \r
++                      if (state == CLOSED_STATE) {\r
++                              throw new InvalidOperationException("Deflater closed");\r
++                      }\r
++                      \r
++                      if (state < BUSY_STATE) {\r
++                              /* output header */\r
++                              int header = (DEFLATED +\r
++                                      ((DeflaterConstants.MAX_WBITS - 8) << 4)) << 8;\r
++                              int level_flags = (level - 1) >> 1;\r
++                              if (level_flags < 0 || level_flags > 3) {\r
++                                      level_flags = 3;\r
++                              }\r
++                              header |= level_flags << 6;\r
++                              if ((state & IS_SETDICT) != 0) {\r
++                                      /* Dictionary was set */\r
++                                      header |= DeflaterConstants.PRESET_DICT;\r
++                              }\r
++                              header += 31 - (header % 31);\r
++                              \r
++                              \r
++                              pending.WriteShortMSB(header);\r
++                              if ((state & IS_SETDICT) != 0) {\r
++                                      int chksum = engine.Adler;\r
++                                      engine.ResetAdler();\r
++                                      pending.WriteShortMSB(chksum >> 16);\r
++                                      pending.WriteShortMSB(chksum & 0xffff);\r
++                              }\r
++                              \r
++                              state = BUSY_STATE | (state & (IS_FLUSHING | IS_FINISHING));\r
++                      }\r
++                      \r
++                      for (;;) {\r
++                              int count = pending.Flush(output, offset, length);\r
++                              offset   += count;\r
++                              totalOut += count;\r
++                              length   -= count;\r
++                              \r
++                              if (length == 0 || state == FINISHED_STATE) {\r
++                                      break;\r
++                              }\r
++                              \r
++                              if (!engine.Deflate((state & IS_FLUSHING) != 0, (state & IS_FINISHING) != 0)) {\r
++                                      if (state == BUSY_STATE) {\r
++                                              /* We need more input now */\r
++                                              return origLength - length;\r
++                                      } else if (state == FLUSHING_STATE) {\r
++                                              if (level != NO_COMPRESSION) {\r
++                                                      /* We have to supply some lookahead.  8 bit lookahead\r
++                                                       * are needed by the zlib inflater, and we must fill\r
++                                                       * the next byte, so that all bits are flushed.\r
++                                                       */\r
++                                                      int neededbits = 8 + ((-pending.BitCount) & 7);\r
++                                                      while (neededbits > 0) {\r
++                                                              /* write a static tree block consisting solely of\r
++                                                               * an EOF:\r
++                                                               */\r
++                                                              pending.WriteBits(2, 10);\r
++                                                              neededbits -= 10;\r
++                                                      }\r
++                                              }\r
++                                              state = BUSY_STATE;\r
++                                      } else if (state == FINISHING_STATE) {\r
++                                              pending.AlignToByte();\r
++                                              /* We have completed the stream */\r
++                                              if (!noHeader) {\r
++                                                      int adler = engine.Adler;\r
++                                                      pending.WriteShortMSB(adler >> 16);\r
++                                                      pending.WriteShortMSB(adler & 0xffff);\r
++                                              }\r
++                                              state = FINISHED_STATE;\r
++                                      }\r
++                              }\r
++                      }\r
++                      return origLength - length;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the dictionary which should be used in the deflate process.\r
++              /// This call is equivalent to <code>setDictionary(dict, 0, dict.Length)</code>.\r
++              /// </summary>\r
++              /// <param name="dict">\r
++              /// the dictionary.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if setInput () or deflate () were already called or another dictionary was already set.\r
++              /// </exception>\r
++              public void SetDictionary(byte[] dict)\r
++              {\r
++                      SetDictionary(dict, 0, dict.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the dictionary which should be used in the deflate process.\r
++              /// The dictionary should be a byte array containing strings that are\r
++              /// likely to occur in the data which should be compressed.  The\r
++              /// dictionary is not stored in the compressed output, only a\r
++              /// checksum.  To decompress the output you need to supply the same\r
++              /// dictionary again.\r
++              /// </summary>\r
++              /// <param name="dict">\r
++              /// the dictionary.\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// an offset into the dictionary.\r
++              /// </param>\r
++              /// <param name="length">\r
++              /// the length of the dictionary.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if setInput () or deflate () were already called or another dictionary was already set.\r
++              /// </exception>\r
++              public void SetDictionary(byte[] dict, int offset, int length)\r
++              {\r
++                      if (state != INIT_STATE) {\r
++                              throw new InvalidOperationException();\r
++                      }\r
++                      \r
++                      state = SETDICT_STATE;\r
++                      engine.SetDictionary(dict, offset, length);\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..8e2be6e21ca3333688431706c026da327927303e
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,85 @@@
++// DeflaterConstants.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class contains constants used for the deflater.\r
++      /// </summary>\r
++      public class DeflaterConstants \r
++      {\r
++              public const bool DEBUGGING = false;\r
++              \r
++              public const int STORED_BLOCK = 0;\r
++              public const int STATIC_TREES = 1;\r
++              public const int DYN_TREES    = 2;\r
++              public const int PRESET_DICT  = 0x20;\r
++              \r
++              public const int DEFAULT_MEM_LEVEL = 8;\r
++              \r
++              public const int MAX_MATCH = 258;\r
++              public const int MIN_MATCH = 3;\r
++              \r
++              public const int MAX_WBITS = 15;\r
++              public const int WSIZE = 1 << MAX_WBITS;\r
++              public const int WMASK = WSIZE - 1;\r
++              \r
++              public const int HASH_BITS = DEFAULT_MEM_LEVEL + 7;\r
++              public const int HASH_SIZE = 1 << HASH_BITS;\r
++              public const int HASH_MASK = HASH_SIZE - 1;\r
++              public const int HASH_SHIFT = (HASH_BITS + MIN_MATCH - 1) / MIN_MATCH;\r
++              \r
++              public const int MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;\r
++              public const int MAX_DIST = WSIZE - MIN_LOOKAHEAD;\r
++              \r
++              public const int PENDING_BUF_SIZE = 1 << (DEFAULT_MEM_LEVEL + 8);\r
++              public static int MAX_BLOCK_SIZE = Math.Min(65535, PENDING_BUF_SIZE-5);\r
++              \r
++              public const int DEFLATE_STORED = 0;\r
++              public const int DEFLATE_FAST   = 1;\r
++              public const int DEFLATE_SLOW   = 2;\r
++              \r
++              public static int[] GOOD_LENGTH = { 0, 4, 4, 4, 4, 8,  8,  8,  32,  32 };\r
++              public static int[] MAX_LAZY    = { 0, 4, 5, 6, 4,16, 16, 32, 128, 258 };\r
++              public static int[] NICE_LENGTH = { 0, 8,16,32,16,32,128,128, 258, 258 };\r
++              public static int[] MAX_CHAIN   = { 0, 4, 8,32,16,32,128,256,1024,4096 };\r
++              public static int[] COMPR_FUNC  = { 0, 1, 1, 1, 1, 2,  2,  2,   2,   2 };\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..c543f8509808875aa9c8618b128a3d6652d3ff8b
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,653 @@@
++// DeflaterEngine.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      public enum DeflateStrategy \r
++      {\r
++              // The default strategy.\r
++              Default  = 0,\r
++              \r
++              // This strategy will only allow longer string repetitions.  It is\r
++              // useful for random data with a small character set.\r
++              Filtered = 1,\r
++              \r
++              // This strategy will not look for string repetitions at all.  It\r
++              // only encodes with Huffman trees (which means, that more common\r
++              // characters get a smaller encoding.\r
++              HuffmanOnly = 2\r
++      }\r
++      \r
++      public class DeflaterEngine : DeflaterConstants \r
++      {\r
++              static int TOO_FAR = 4096;\r
++              \r
++              int ins_h;\r
++              //              private byte[] buffer;\r
++              short[] head;\r
++              short[] prev;\r
++              \r
++              int    matchStart, matchLen;\r
++              bool   prevAvailable;\r
++              int    blockStart;\r
++              int    strstart, lookahead;\r
++              byte[] window;\r
++              \r
++              DeflateStrategy strategy;\r
++              int max_chain, max_lazy, niceLength, goodLength;\r
++              \r
++              /// <summary>\r
++              /// The current compression function.\r
++              /// </summary>\r
++              int comprFunc;\r
++              \r
++              /// <summary>\r
++              /// The input data for compression.\r
++              /// </summary>\r
++              byte[] inputBuf;\r
++              \r
++              /// <summary>\r
++              /// The total bytes of input read.\r
++              /// </summary>\r
++              int totalIn;\r
++              \r
++              /// <summary>\r
++              /// The offset into inputBuf, where input data starts.\r
++              /// </summary>\r
++              int inputOff;\r
++              \r
++              /// <summary>\r
++              /// The end offset of the input data.\r
++              /// </summary>\r
++              int inputEnd;\r
++              \r
++              DeflaterPending pending;\r
++              DeflaterHuffman huffman;\r
++              \r
++              /// <summary>\r
++              /// The adler checksum\r
++              /// </summary>\r
++              Adler32 adler;\r
++              \r
++              public DeflaterEngine(DeflaterPending pending) \r
++              {\r
++                      this.pending = pending;\r
++                      huffman = new DeflaterHuffman(pending);\r
++                      adler = new Adler32();\r
++                      \r
++                      window = new byte[2 * WSIZE];\r
++                      head   = new short[HASH_SIZE];\r
++                      prev   = new short[WSIZE];\r
++                      \r
++                      /* We start at index 1, to avoid a implementation deficiency, that\r
++                      * we cannot build a repeat pattern at index 0.\r
++                      */\r
++                      blockStart = strstart = 1;\r
++              }\r
++              \r
++              public void Reset()\r
++              {\r
++                      huffman.Reset();\r
++                      adler.Reset();\r
++                      blockStart = strstart = 1;\r
++                      lookahead = 0;\r
++                      totalIn   = 0;\r
++                      prevAvailable = false;\r
++                      matchLen = MIN_MATCH - 1;\r
++                      \r
++                      for (int i = 0; i < HASH_SIZE; i++) {\r
++                              head[i] = 0;\r
++                      }\r
++                      \r
++                      for (int i = 0; i < WSIZE; i++) {\r
++                              prev[i] = 0;\r
++                      }\r
++              }\r
++              \r
++              public void ResetAdler()\r
++              {\r
++                      adler.Reset();\r
++              }\r
++              \r
++              public int Adler {\r
++                      get {\r
++                              return (int)adler.Value;\r
++                      }\r
++              }\r
++              \r
++              public int TotalIn {\r
++                      get {\r
++                              return totalIn;\r
++                      }\r
++              }\r
++              \r
++              public DeflateStrategy Strategy {\r
++                      get {\r
++                              return strategy;\r
++                      }\r
++                      set {\r
++                              strategy = value;\r
++                      }\r
++              }\r
++              \r
++              public void SetLevel(int lvl)\r
++              {\r
++                      goodLength = DeflaterConstants.GOOD_LENGTH[lvl];\r
++                      max_lazy   = DeflaterConstants.MAX_LAZY[lvl];\r
++                      niceLength = DeflaterConstants.NICE_LENGTH[lvl];\r
++                      max_chain  = DeflaterConstants.MAX_CHAIN[lvl];\r
++                      \r
++                      if (DeflaterConstants.COMPR_FUNC[lvl] != comprFunc) {\r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      //Console.WriteLine("Change from "+comprFunc +" to "\r
++                              //                                                        + DeflaterConstants.COMPR_FUNC[lvl]);\r
++                              //                              }\r
++                              switch (comprFunc) {\r
++                                      case DEFLATE_STORED:\r
++                                              if (strstart > blockStart) {\r
++                                                      huffman.FlushStoredBlock(window, blockStart,\r
++                                                              strstart - blockStart, false);\r
++                                                      blockStart = strstart;\r
++                                              }\r
++                                              UpdateHash();\r
++                                              break;\r
++                                      case DEFLATE_FAST:\r
++                                              if (strstart > blockStart) {\r
++                                                      huffman.FlushBlock(window, blockStart, strstart - blockStart,\r
++                                                              false);\r
++                                                      blockStart = strstart;\r
++                                              }\r
++                                              break;\r
++                                      case DEFLATE_SLOW:\r
++                                              if (prevAvailable) {\r
++                                                      huffman.TallyLit(window[strstart-1] & 0xff);\r
++                                              }\r
++                                              if (strstart > blockStart) {\r
++                                                      huffman.FlushBlock(window, blockStart, strstart - blockStart, false);\r
++                                                      blockStart = strstart;\r
++                                              }\r
++                                              prevAvailable = false;\r
++                                              matchLen = MIN_MATCH - 1;\r
++                                              break;\r
++                              }\r
++                              comprFunc = COMPR_FUNC[lvl];\r
++                      }\r
++              }\r
++              \r
++              void UpdateHash() \r
++              {\r
++                      //                      if (DEBUGGING) {\r
++                      //                              //Console.WriteLine("updateHash: "+strstart);\r
++                      //                      }\r
++                      ins_h = (window[strstart] << HASH_SHIFT) ^ window[strstart + 1];\r
++              }\r
++              \r
++              int InsertString() \r
++              {\r
++                      short match;\r
++                      int hash = ((ins_h << HASH_SHIFT) ^ window[strstart + (MIN_MATCH -1)]) & HASH_MASK;\r
++                      \r
++                      //                      if (DEBUGGING) {\r
++                      //                              if (hash != (((window[strstart] << (2*HASH_SHIFT)) ^ \r
++                      //                                            (window[strstart + 1] << HASH_SHIFT) ^ \r
++                      //                                            (window[strstart + 2])) & HASH_MASK)) {\r
++                      //                                              throw new Exception("hash inconsistent: "+hash+"/"\r
++                      //                                                                  +window[strstart]+","\r
++                      //                                                                  +window[strstart+1]+","\r
++                      //                                                                  +window[strstart+2]+","+HASH_SHIFT);\r
++                      //                                      }\r
++                      //                      }\r
++                      \r
++                      prev[strstart & WMASK] = match = head[hash];\r
++                      head[hash] = (short)strstart;\r
++                      ins_h = hash;\r
++                      return match & 0xffff;\r
++              }\r
++              \r
++              void SlideWindow()\r
++              {\r
++                      Array.Copy(window, WSIZE, window, 0, WSIZE);\r
++                      matchStart -= WSIZE;\r
++                      strstart   -= WSIZE;\r
++                      blockStart -= WSIZE;\r
++                      \r
++                      /* Slide the hash table (could be avoided with 32 bit values\r
++                       * at the expense of memory usage).\r
++                       */\r
++                      for (int i = 0; i < HASH_SIZE; ++i) {\r
++                              int m = head[i] & 0xffff;\r
++                              head[i] = (short)(m >= WSIZE ? (m - WSIZE) : 0);\r
++                      }\r
++                      \r
++                      /* Slide the prev table. */\r
++                      for (int i = 0; i < WSIZE; i++) {\r
++                              int m = prev[i] & 0xffff;\r
++                              prev[i] = (short)(m >= WSIZE ? (m - WSIZE) : 0);\r
++                      }\r
++              }\r
++              \r
++              public void FillWindow()\r
++              {\r
++                      /* If the window is almost full and there is insufficient lookahead,\r
++                       * move the upper half to the lower one to make room in the upper half.\r
++                       */\r
++                      if (strstart >= WSIZE + MAX_DIST) {\r
++                              SlideWindow();\r
++                      }\r
++                      \r
++                      /* If there is not enough lookahead, but still some input left,\r
++                       * read in the input\r
++                       */\r
++                      while (lookahead < DeflaterConstants.MIN_LOOKAHEAD && inputOff < inputEnd) {\r
++                              int more = 2 * WSIZE - lookahead - strstart;\r
++                              \r
++                              if (more > inputEnd - inputOff) {\r
++                                      more = inputEnd - inputOff;\r
++                              }\r
++                              \r
++                              System.Array.Copy(inputBuf, inputOff, window, strstart + lookahead, more);\r
++                              adler.Update(inputBuf, inputOff, more);\r
++                              \r
++                              inputOff += more;\r
++                              totalIn  += more;\r
++                              lookahead += more;\r
++                      }\r
++                      \r
++                      if (lookahead >= MIN_MATCH) {\r
++                              UpdateHash();\r
++                      }\r
++              }\r
++              \r
++              bool FindLongestMatch(int curMatch) \r
++              {\r
++                      int chainLength = this.max_chain;\r
++                      int niceLength  = this.niceLength;\r
++                      short[] prev    = this.prev;\r
++                      int scan        = this.strstart;\r
++                      int match;\r
++                      int best_end = this.strstart + matchLen;\r
++                      int best_len = Math.Max(matchLen, MIN_MATCH - 1);\r
++                      \r
++                      int limit = Math.Max(strstart - MAX_DIST, 0);\r
++                      \r
++                      int strend = strstart + MAX_MATCH - 1;\r
++                      byte scan_end1 = window[best_end - 1];\r
++                      byte scan_end  = window[best_end];\r
++                      \r
++                      /* Do not waste too much time if we already have a good match: */\r
++                      if (best_len >= this.goodLength) {\r
++                              chainLength >>= 2;\r
++                      }\r
++                      \r
++                      /* Do not look for matches beyond the end of the input. This is necessary\r
++                      * to make deflate deterministic.\r
++                      */\r
++                      if (niceLength > lookahead) {\r
++                              niceLength = lookahead;\r
++                      }\r
++                      \r
++                      if (DeflaterConstants.DEBUGGING && strstart > 2 * WSIZE - MIN_LOOKAHEAD) {\r
++                              throw new InvalidOperationException("need lookahead");\r
++                      }\r
++                      \r
++                      do {\r
++                              if (DeflaterConstants.DEBUGGING && curMatch >= strstart) {\r
++                                      throw new InvalidOperationException("future match");\r
++                              }\r
++                              if (window[curMatch + best_len] != scan_end      || \r
++                                      window[curMatch + best_len - 1] != scan_end1 || \r
++                                      window[curMatch] != window[scan]             || \r
++                                      window[curMatch + 1] != window[scan + 1]) {\r
++                                      continue;\r
++                              }\r
++                              \r
++                              match = curMatch + 2;\r
++                              scan += 2;\r
++                              \r
++                              /* We check for insufficient lookahead only every 8th comparison;\r
++                              * the 256th check will be made at strstart+258.\r
++                              */\r
++                      while (window[++scan] == window[++match] && \r
++                              window[++scan] == window[++match] && \r
++                              window[++scan] == window[++match] && \r
++                              window[++scan] == window[++match] && \r
++                              window[++scan] == window[++match] && \r
++                              window[++scan] == window[++match] && \r
++                              window[++scan] == window[++match] && \r
++                              window[++scan] == window[++match] && scan < strend) ;\r
++                              \r
++                              if (scan > best_end) {\r
++                                      //      if (DeflaterConstants.DEBUGGING && ins_h == 0)\r
++                                      //        System.err.println("Found match: "+curMatch+"-"+(scan-strstart));\r
++                                      matchStart = curMatch;\r
++                                      best_end = scan;\r
++                                      best_len = scan - strstart;\r
++                                      \r
++                                      if (best_len >= niceLength) {\r
++                                              break;\r
++                                      }\r
++                                      \r
++                                      scan_end1  = window[best_end - 1];\r
++                                      scan_end   = window[best_end];\r
++                              }\r
++                              scan = strstart;\r
++                      } while ((curMatch = (prev[curMatch & WMASK] & 0xffff)) > limit && --chainLength != 0);\r
++                      \r
++                      matchLen = Math.Min(best_len, lookahead);\r
++                      return matchLen >= MIN_MATCH;\r
++              }\r
++              \r
++              public void SetDictionary(byte[] buffer, int offset, int length) \r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && strstart != 1) {\r
++                              throw new InvalidOperationException("strstart not 1");\r
++                      }\r
++                      adler.Update(buffer, offset, length);\r
++                      if (length < MIN_MATCH) {\r
++                              return;\r
++                      }\r
++                      if (length > MAX_DIST) {\r
++                              offset += length - MAX_DIST;\r
++                              length = MAX_DIST;\r
++                      }\r
++                      \r
++                      System.Array.Copy(buffer, offset, window, strstart, length);\r
++                      \r
++                      UpdateHash();\r
++                      --length;\r
++                      while (--length > 0) {\r
++                              InsertString();\r
++                              strstart++;\r
++                      }\r
++                      strstart += 2;\r
++                      blockStart = strstart;\r
++              }\r
++              \r
++              bool DeflateStored(bool flush, bool finish)\r
++              {\r
++                      if (!flush && lookahead == 0) {\r
++                              return false;\r
++                      }\r
++                      \r
++                      strstart += lookahead;\r
++                      lookahead = 0;\r
++                      \r
++                      int storedLen = strstart - blockStart;\r
++                      \r
++                      if ((storedLen >= DeflaterConstants.MAX_BLOCK_SIZE) || /* Block is full */\r
++                              (blockStart < WSIZE && storedLen >= MAX_DIST) ||   /* Block may move out of window */\r
++                              flush) {\r
++                              bool lastBlock = finish;\r
++                              if (storedLen > DeflaterConstants.MAX_BLOCK_SIZE) {\r
++                                      storedLen = DeflaterConstants.MAX_BLOCK_SIZE;\r
++                                      lastBlock = false;\r
++                              }\r
++                              \r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      //Console.WriteLine("storedBlock["+storedLen+","+lastBlock+"]");\r
++                              //                              }\r
++                                      \r
++                              huffman.FlushStoredBlock(window, blockStart, storedLen, lastBlock);\r
++                              blockStart += storedLen;\r
++                              return !lastBlock;\r
++                      }\r
++                      return true;\r
++              }\r
++              \r
++              private bool DeflateFast(bool flush, bool finish)\r
++              {\r
++                      if (lookahead < MIN_LOOKAHEAD && !flush) {\r
++                              return false;\r
++                      }\r
++                      \r
++                      while (lookahead >= MIN_LOOKAHEAD || flush) {\r
++                              if (lookahead == 0) {\r
++                                      /* We are flushing everything */\r
++                                      huffman.FlushBlock(window, blockStart, strstart - blockStart, finish);\r
++                                      blockStart = strstart;\r
++                                      return false;\r
++                              }\r
++                              \r
++                              if (strstart > 2 * WSIZE - MIN_LOOKAHEAD) {\r
++                                      /* slide window, as findLongestMatch need this.\r
++                                       * This should only happen when flushing and the window\r
++                                       * is almost full.\r
++                                       */\r
++                                      SlideWindow();\r
++                              }\r
++                              \r
++                              int hashHead;\r
++                              if (lookahead >= MIN_MATCH && \r
++                                      (hashHead = InsertString()) != 0 && \r
++                                      strategy != DeflateStrategy.HuffmanOnly &&\r
++                                      strstart - hashHead <= MAX_DIST && \r
++                                      FindLongestMatch(hashHead)) {\r
++                                      /* longestMatch sets matchStart and matchLen */\r
++                                      //                                      if (DeflaterConstants.DEBUGGING) {\r
++                                      //                                              for (int i = 0 ; i < matchLen; i++) {\r
++                                      //                                                      if (window[strstart+i] != window[matchStart + i]) {\r
++                                      //                                                              throw new Exception();\r
++                                      //                                                      }\r
++                                      //                                              }\r
++                                      //                                      }\r
++                                      \r
++                                      // -jr- Hak hak hak this stops problems with fast/low compression and index out of range\r
++                                      if (huffman.TallyDist(strstart - matchStart, matchLen)) {\r
++                                              bool lastBlock = finish && lookahead == 0;\r
++                                              huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock);\r
++                                              blockStart = strstart;\r
++                                      }\r
++                                      \r
++                                      lookahead -= matchLen;\r
++                                      if (matchLen <= max_lazy && lookahead >= MIN_MATCH) {\r
++                                              while (--matchLen > 0) {\r
++                                                      ++strstart;\r
++                                                      InsertString();\r
++                                              }\r
++                                              ++strstart;\r
++                                      } else {\r
++                                              strstart += matchLen;\r
++                                              if (lookahead >= MIN_MATCH - 1) {\r
++                                                      UpdateHash();\r
++                                              }\r
++                                      }\r
++                                      matchLen = MIN_MATCH - 1;\r
++                                      continue;\r
++                              } else {\r
++                                      /* No match found */\r
++                                      huffman.TallyLit(window[strstart] & 0xff);\r
++                                      ++strstart;\r
++                                      --lookahead;\r
++                              }\r
++                              \r
++                              if (huffman.IsFull()) {\r
++                                      bool lastBlock = finish && lookahead == 0;\r
++                                      huffman.FlushBlock(window, blockStart, strstart - blockStart, lastBlock);\r
++                                      blockStart = strstart;\r
++                                      return !lastBlock;\r
++                              }\r
++                      }\r
++                      return true;\r
++              }\r
++              \r
++              bool DeflateSlow(bool flush, bool finish)\r
++              {\r
++                      if (lookahead < MIN_LOOKAHEAD && !flush) {\r
++                              return false;\r
++                      }\r
++                      \r
++                      while (lookahead >= MIN_LOOKAHEAD || flush) {\r
++                              if (lookahead == 0) {\r
++                                      if (prevAvailable) {\r
++                                              huffman.TallyLit(window[strstart-1] & 0xff);\r
++                                      }\r
++                                      prevAvailable = false;\r
++                                      \r
++                                      /* We are flushing everything */\r
++                                      if (DeflaterConstants.DEBUGGING && !flush) {\r
++                                              throw new Exception("Not flushing, but no lookahead");\r
++                                      }\r
++                                      huffman.FlushBlock(window, blockStart, strstart - blockStart,\r
++                                              finish);\r
++                                      blockStart = strstart;\r
++                                      return false;\r
++                              }\r
++                              \r
++                              if (strstart >= 2 * WSIZE - MIN_LOOKAHEAD) {\r
++                                      /* slide window, as findLongestMatch need this.\r
++                                       * This should only happen when flushing and the window\r
++                                       * is almost full.\r
++                                       */\r
++                                      SlideWindow();\r
++                              }\r
++                              \r
++                              int prevMatch = matchStart;\r
++                              int prevLen = matchLen;\r
++                              if (lookahead >= MIN_MATCH) {\r
++                                      int hashHead = InsertString();\r
++                                      if (strategy != DeflateStrategy.HuffmanOnly && hashHead != 0 && strstart - hashHead <= MAX_DIST && FindLongestMatch(hashHead)) {\r
++                                              /* longestMatch sets matchStart and matchLen */\r
++                                                      \r
++                                              /* Discard match if too small and too far away */\r
++                                              if (matchLen <= 5 && (strategy == DeflateStrategy.Filtered || (matchLen == MIN_MATCH && strstart - matchStart > TOO_FAR))) {\r
++                                                      matchLen = MIN_MATCH - 1;\r
++                                              }\r
++                                      }\r
++                              }\r
++                              \r
++                              /* previous match was better */\r
++                              if (prevLen >= MIN_MATCH && matchLen <= prevLen) {\r
++                                      //                                      if (DeflaterConstants.DEBUGGING) {\r
++                                      //                                              for (int i = 0 ; i < matchLen; i++) {\r
++                                      //                                                      if (window[strstart-1+i] != window[prevMatch + i])\r
++                                      //                                                              throw new Exception();\r
++                                      //                                              }\r
++                                      //                                      }\r
++                                      huffman.TallyDist(strstart - 1 - prevMatch, prevLen);\r
++                                      prevLen -= 2;\r
++                                      do {\r
++                                              strstart++;\r
++                                              lookahead--;\r
++                                              if (lookahead >= MIN_MATCH) {\r
++                                                      InsertString();\r
++                                              }\r
++                                      } while (--prevLen > 0);\r
++                                      strstart ++;\r
++                                      lookahead--;\r
++                                      prevAvailable = false;\r
++                                      matchLen = MIN_MATCH - 1;\r
++                              } else {\r
++                                      if (prevAvailable) {\r
++                                              huffman.TallyLit(window[strstart-1] & 0xff);\r
++                                      }\r
++                                      prevAvailable = true;\r
++                                      strstart++;\r
++                                      lookahead--;\r
++                              }\r
++                              \r
++                              if (huffman.IsFull()) {\r
++                                      int len = strstart - blockStart;\r
++                                      if (prevAvailable) {\r
++                                              len--;\r
++                                      }\r
++                                      bool lastBlock = (finish && lookahead == 0 && !prevAvailable);\r
++                                      huffman.FlushBlock(window, blockStart, len, lastBlock);\r
++                                      blockStart += len;\r
++                                      return !lastBlock;\r
++                              }\r
++                      }\r
++                      return true;\r
++              }\r
++              \r
++              public bool Deflate(bool flush, bool finish)\r
++              {\r
++                      bool progress;\r
++                      do {\r
++                              FillWindow();\r
++                              bool canFlush = flush && inputOff == inputEnd;\r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      //Console.WriteLine("window: ["+blockStart+","+strstart+","\r
++                              //                                                        +lookahead+"], "+comprFunc+","+canFlush);\r
++                              //                              }\r
++                              switch (comprFunc) {\r
++                                      case DEFLATE_STORED:\r
++                                              progress = DeflateStored(canFlush, finish);\r
++                                              break;\r
++                                      case DEFLATE_FAST:\r
++                                              progress = DeflateFast(canFlush, finish);\r
++                                              break;\r
++                                      case DEFLATE_SLOW:\r
++                                              progress = DeflateSlow(canFlush, finish);\r
++                                              break;\r
++                                      default:\r
++                                              throw new InvalidOperationException("unknown comprFunc");\r
++                              }\r
++                      } while (pending.IsFlushed && progress); /* repeat while we have no pending output and progress was made */\r
++                      return progress;\r
++              }\r
++              \r
++              public void SetInput(byte[] buf, int off, int len)\r
++              {\r
++                      if (inputOff < inputEnd) {\r
++                              throw new InvalidOperationException("Old input was not completely processed");\r
++                      }\r
++                      \r
++                      int end = off + len;\r
++                      \r
++                      /* We want to throw an ArrayIndexOutOfBoundsException early.  The\r
++                      * check is very tricky: it also handles integer wrap around.\r
++                      */\r
++                      if (0 > off || off > end || end > buf.Length) {\r
++                              throw new ArgumentOutOfRangeException();\r
++                      }\r
++                      \r
++                      inputBuf = buf;\r
++                      inputOff = off;\r
++                      inputEnd = end;\r
++              }\r
++              \r
++              public bool NeedsInput()\r
++              {\r
++                      return inputEnd == inputOff;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..ebf9beade3779fa2ce016b05f258e2b1ba8705f2
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,780 @@@
++// DeflaterHuffman.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      /// <summary>\r
++      /// This is the DeflaterHuffman class.\r
++      /// \r
++      /// This class is <i>not</i> thread safe.  This is inherent in the API, due\r
++      /// to the split of deflate and setInput.\r
++      /// \r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      public class DeflaterHuffman\r
++      {\r
++              private static  int BUFSIZE = 1 << (DeflaterConstants.DEFAULT_MEM_LEVEL + 6);\r
++              private static  int LITERAL_NUM = 286;\r
++              private static  int DIST_NUM = 30;\r
++              private static  int BITLEN_NUM = 19;\r
++              private static  int REP_3_6    = 16;\r
++              private static  int REP_3_10   = 17;\r
++              private static  int REP_11_138 = 18;\r
++              private static  int EOF_SYMBOL = 256;\r
++              private static  int[] BL_ORDER = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };\r
++              \r
++              private static byte[] bit4Reverse = {\r
++                      0,\r
++                      8,\r
++                      4,\r
++                      12,\r
++                      2,\r
++                      10,\r
++                      6,\r
++                      14,\r
++                      1,\r
++                      9,\r
++                      5,\r
++                      13,\r
++                      3,\r
++                      11,\r
++                      7,\r
++                      15\r
++              };\r
++              \r
++              public class Tree \r
++              {\r
++                      public short[] freqs;\r
++                      public byte[]  length;\r
++                      public int     minNumCodes, numCodes;\r
++                      \r
++                      short[] codes;\r
++                      int[]   bl_counts;\r
++                      int     maxLength;\r
++                      DeflaterHuffman dh;\r
++                      \r
++                      public Tree(DeflaterHuffman dh, int elems, int minCodes, int maxLength) \r
++                      {\r
++                              this.dh =  dh;\r
++                              this.minNumCodes = minCodes;\r
++                              this.maxLength  = maxLength;\r
++                              freqs  = new short[elems];\r
++                              bl_counts = new int[maxLength];\r
++                      }\r
++                      \r
++                      public void Reset() \r
++                      {\r
++                              for (int i = 0; i < freqs.Length; i++) {\r
++                                      freqs[i] = 0;\r
++                              }\r
++                              codes = null;\r
++                              length = null;\r
++                      }\r
++                      \r
++                      public void WriteSymbol(int code)\r
++                      {\r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      freqs[code]--;\r
++                              //                                      //        Console.Write("writeSymbol("+freqs.length+","+code+"): ");\r
++                              //                              }\r
++                              dh.pending.WriteBits(codes[code] & 0xffff, length[code]);\r
++                      }\r
++                      \r
++                      public void CheckEmpty()\r
++                      {\r
++                              bool empty = true;\r
++                              for (int i = 0; i < freqs.Length; i++) {\r
++                                      if (freqs[i] != 0) {\r
++                                              //Console.WriteLine("freqs["+i+"] == "+freqs[i]);\r
++                                              empty = false;\r
++                                      }\r
++                              }\r
++                              if (!empty) {\r
++                                      throw new Exception();\r
++                              }\r
++                              //Console.WriteLine("checkEmpty suceeded!");\r
++                      }\r
++                      \r
++                      public void SetStaticCodes(short[] stCodes, byte[] stLength)\r
++                      {\r
++                              codes = stCodes;\r
++                              length = stLength;\r
++                      }\r
++                      \r
++                      public void BuildCodes() \r
++                      {\r
++                              int numSymbols = freqs.Length;\r
++                              int[] nextCode = new int[maxLength];\r
++                              int code = 0;\r
++                              codes = new short[freqs.Length];\r
++                              \r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      //Console.WriteLine("buildCodes: "+freqs.Length);\r
++                              //                              }\r
++                              \r
++                              for (int bits = 0; bits < maxLength; bits++) {\r
++                                      nextCode[bits] = code;\r
++                                      code += bl_counts[bits] << (15 - bits);\r
++                                      //                                      if (DeflaterConstants.DEBUGGING) {\r
++                                      //                                              //Console.WriteLine("bits: "+(bits+1)+" count: "+bl_counts[bits]\r
++                                      //                                                                +" nextCode: "+code); // HACK : Integer.toHexString(\r
++                                      //                                      }\r
++                              }\r
++                              if (DeflaterConstants.DEBUGGING && code != 65536) {\r
++                                      throw new Exception("Inconsistent bl_counts!");\r
++                              }\r
++                              \r
++                              for (int i=0; i < numCodes; i++) {\r
++                                      int bits = length[i];\r
++                                      if (bits > 0) {\r
++                                              //                                              if (DeflaterConstants.DEBUGGING) {\r
++                                              //                                                              //Console.WriteLine("codes["+i+"] = rev(" + nextCode[bits-1]+")," // HACK : Integer.toHexString(\r
++                                              //                                                                                +bits);\r
++                                              //                                              }\r
++                                              codes[i] = BitReverse(nextCode[bits-1]);\r
++                                              nextCode[bits-1] += 1 << (16 - bits);\r
++                                      }\r
++                              }\r
++                      }\r
++                      \r
++                      void BuildLength(int[] childs)\r
++                      {\r
++                              this.length = new byte [freqs.Length];\r
++                              int numNodes = childs.Length / 2;\r
++                              int numLeafs = (numNodes + 1) / 2;\r
++                              int overflow = 0;\r
++                              \r
++                              for (int i = 0; i < maxLength; i++) {\r
++                                      bl_counts[i] = 0;\r
++                              }\r
++                              \r
++                              /* First calculate optimal bit lengths */\r
++                              int[] lengths = new int[numNodes];\r
++                              lengths[numNodes-1] = 0;\r
++                              \r
++                              for (int i = numNodes - 1; i >= 0; i--) {\r
++                                      if (childs[2*i+1] != -1) {\r
++                                              int bitLength = lengths[i] + 1;\r
++                                              if (bitLength > maxLength) {\r
++                                                      bitLength = maxLength;\r
++                                                      overflow++;\r
++                                              }\r
++                                              lengths[childs[2*i]] = lengths[childs[2*i+1]] = bitLength;\r
++                                      } else {\r
++                                              /* A leaf node */\r
++                                              int bitLength = lengths[i];\r
++                                              bl_counts[bitLength - 1]++;\r
++                                              this.length[childs[2*i]] = (byte) lengths[i];\r
++                                      }\r
++                              }\r
++                              \r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      //Console.WriteLine("Tree "+freqs.Length+" lengths:");\r
++                              //                                      for (int i=0; i < numLeafs; i++) {\r
++                              //                                              //Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]\r
++                              //                                                                + " len: "+length[childs[2*i]]);\r
++                              //                                      }\r
++                              //                              }\r
++                              \r
++                              if (overflow == 0) {\r
++                                      return;\r
++                              }\r
++                              \r
++                              int incrBitLen = maxLength - 1;\r
++                              do {\r
++                                      /* Find the first bit length which could increase: */\r
++                                      while (bl_counts[--incrBitLen] == 0)\r
++                                              ;\r
++                                      \r
++                                      /* Move this node one down and remove a corresponding\r
++                                      * amount of overflow nodes.\r
++                                      */\r
++                                      do {\r
++                                              bl_counts[incrBitLen]--;\r
++                                              bl_counts[++incrBitLen]++;\r
++                                              overflow -= 1 << (maxLength - 1 - incrBitLen);\r
++                                      } while (overflow > 0 && incrBitLen < maxLength - 1);\r
++                              } while (overflow > 0);\r
++                              \r
++                              /* We may have overshot above.  Move some nodes from maxLength to\r
++                              * maxLength-1 in that case.\r
++                              */\r
++                              bl_counts[maxLength-1] += overflow;\r
++                              bl_counts[maxLength-2] -= overflow;\r
++                              \r
++                              /* Now recompute all bit lengths, scanning in increasing\r
++                              * frequency.  It is simpler to reconstruct all lengths instead of\r
++                              * fixing only the wrong ones. This idea is taken from 'ar'\r
++                              * written by Haruhiko Okumura.\r
++                              *\r
++                              * The nodes were inserted with decreasing frequency into the childs\r
++                              * array.\r
++                              */\r
++                              int nodePtr = 2 * numLeafs;\r
++                              for (int bits = maxLength; bits != 0; bits--) {\r
++                                      int n = bl_counts[bits-1];\r
++                                      while (n > 0) {\r
++                                              int childPtr = 2*childs[nodePtr++];\r
++                                              if (childs[childPtr + 1] == -1) {\r
++                                                      /* We found another leaf */\r
++                                                      length[childs[childPtr]] = (byte) bits;\r
++                                                      n--;\r
++                                              }\r
++                                      }\r
++                              }\r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      //Console.WriteLine("*** After overflow elimination. ***");\r
++                              //                                      for (int i=0; i < numLeafs; i++) {\r
++                              //                                              //Console.WriteLine("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]\r
++                              //                                                                + " len: "+length[childs[2*i]]);\r
++                              //                                      }\r
++                              //                              }\r
++                      }\r
++                      \r
++                      public void BuildTree()\r
++                      {\r
++                              int numSymbols = freqs.Length;\r
++                              \r
++                              /* heap is a priority queue, sorted by frequency, least frequent\r
++                              * nodes first.  The heap is a binary tree, with the property, that\r
++                              * the parent node is smaller than both child nodes.  This assures\r
++                              * that the smallest node is the first parent.\r
++                              *\r
++                              * The binary tree is encoded in an array:  0 is root node and\r
++                              * the nodes 2*n+1, 2*n+2 are the child nodes of node n.\r
++                              */\r
++                              int[] heap = new int[numSymbols];\r
++                              int heapLen = 0;\r
++                              int maxCode = 0;\r
++                              for (int n = 0; n < numSymbols; n++) {\r
++                                      int freq = freqs[n];\r
++                                      if (freq != 0) {\r
++                                              /* Insert n into heap */\r
++                                              int pos = heapLen++;\r
++                                              int ppos;\r
++                                              while (pos > 0 && freqs[heap[ppos = (pos - 1) / 2]] > freq) {\r
++                                                      heap[pos] = heap[ppos];\r
++                                                      pos = ppos;\r
++                                              }\r
++                                              heap[pos] = n;\r
++                                              \r
++                                              maxCode = n;\r
++                                      }\r
++                              }\r
++                              \r
++                              /* We could encode a single literal with 0 bits but then we\r
++                              * don't see the literals.  Therefore we force at least two\r
++                              * literals to avoid this case.  We don't care about order in\r
++                              * this case, both literals get a 1 bit code.\r
++                              */\r
++                              while (heapLen < 2) {\r
++                                      int node = maxCode < 2 ? ++maxCode : 0;\r
++                                      heap[heapLen++] = node;\r
++                              }\r
++                              \r
++                              numCodes = Math.Max(maxCode + 1, minNumCodes);\r
++                              \r
++                              int numLeafs = heapLen;\r
++                              int[] childs = new int[4*heapLen - 2];\r
++                              int[] values = new int[2*heapLen - 1];\r
++                              int numNodes = numLeafs;\r
++                              for (int i = 0; i < heapLen; i++) {\r
++                                      int node = heap[i];\r
++                                      childs[2*i]   = node;\r
++                                      childs[2*i+1] = -1;\r
++                                      values[i] = freqs[node] << 8;\r
++                                      heap[i] = i;\r
++                              }\r
++                              \r
++                              /* Construct the Huffman tree by repeatedly combining the least two\r
++                              * frequent nodes.\r
++                              */\r
++                              do {\r
++                                      int first = heap[0];\r
++                                      int last  = heap[--heapLen];\r
++                                      \r
++                                      /* Propagate the hole to the leafs of the heap */\r
++                                      int ppos = 0;\r
++                                      int path = 1;\r
++                                      \r
++                                      while (path < heapLen) {\r
++                                              if (path + 1 < heapLen && values[heap[path]] > values[heap[path+1]]) {\r
++                                                      path++;\r
++                                              }\r
++                                                      \r
++                                              heap[ppos] = heap[path];\r
++                                              ppos = path;\r
++                                              path = path * 2 + 1;\r
++                                      }\r
++                                              \r
++                                      /* Now propagate the last element down along path.  Normally\r
++                                      * it shouldn't go too deep.\r
++                                      */\r
++                                      int lastVal = values[last];\r
++                                      while ((path = ppos) > 0 && values[heap[ppos = (path - 1)/2]] > lastVal) {\r
++                                              heap[path] = heap[ppos];\r
++                                      }\r
++                                      heap[path] = last;\r
++                                      \r
++                                      \r
++                                      int second = heap[0];\r
++                                      \r
++                                      /* Create a new node father of first and second */\r
++                                      last = numNodes++;\r
++                                      childs[2*last] = first;\r
++                                      childs[2*last+1] = second;\r
++                                      int mindepth = Math.Min(values[first] & 0xff, values[second] & 0xff);\r
++                                      values[last] = lastVal = values[first] + values[second] - mindepth + 1;\r
++                                      \r
++                                      /* Again, propagate the hole to the leafs */\r
++                                      ppos = 0;\r
++                                      path = 1;\r
++                                      \r
++                                      while (path < heapLen) {\r
++                                              if (path + 1 < heapLen && values[heap[path]] > values[heap[path+1]]) {\r
++                                                      path++;\r
++                                              }\r
++                                                      \r
++                                              heap[ppos] = heap[path];\r
++                                              ppos = path;\r
++                                              path = ppos * 2 + 1;\r
++                                      }\r
++                                              \r
++                                      /* Now propagate the new element down along path */\r
++                                      while ((path = ppos) > 0 && values[heap[ppos = (path - 1)/2]] > lastVal) {\r
++                                              heap[path] = heap[ppos];\r
++                                      }\r
++                                      heap[path] = last;\r
++                              } while (heapLen > 1);\r
++                              \r
++                              if (heap[0] != childs.Length / 2 - 1) {\r
++                                      throw new Exception("Weird!");\r
++                              }\r
++                              BuildLength(childs);\r
++                      }\r
++                      \r
++                      public int GetEncodedLength()\r
++                      {\r
++                              int len = 0;\r
++                              for (int i = 0; i < freqs.Length; i++) {\r
++                                      len += freqs[i] * length[i];\r
++                              }\r
++                              return len;\r
++                      }\r
++                      \r
++                      public void CalcBLFreq(Tree blTree) \r
++                      {\r
++                              int max_count;               /* max repeat count */\r
++                              int min_count;               /* min repeat count */\r
++                              int count;                   /* repeat count of the current code */\r
++                              int curlen = -1;             /* length of current code */\r
++                              \r
++                              int i = 0;\r
++                              while (i < numCodes) {\r
++                                      count = 1;\r
++                                      int nextlen = length[i];\r
++                                      if (nextlen == 0) {\r
++                                              max_count = 138;\r
++                                              min_count = 3;\r
++                                      } else {\r
++                                              max_count = 6;\r
++                                              min_count = 3;\r
++                                              if (curlen != nextlen) {\r
++                                                      blTree.freqs[nextlen]++;\r
++                                                      count = 0;\r
++                                              }\r
++                                      }\r
++                                      curlen = nextlen;\r
++                                      i++;\r
++                                      \r
++                                      while (i < numCodes && curlen == length[i]) {\r
++                                              i++;\r
++                                              if (++count >= max_count) {\r
++                                                      break;\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      if (count < min_count) {\r
++                                              blTree.freqs[curlen] += (short)count;\r
++                                      } else if (curlen != 0) {\r
++                                              blTree.freqs[REP_3_6]++;\r
++                                      } else if (count <= 10) {\r
++                                              blTree.freqs[REP_3_10]++;\r
++                                      } else {\r
++                                              blTree.freqs[REP_11_138]++;\r
++                                      }\r
++                              }\r
++                      }\r
++                      \r
++                      public void WriteTree(Tree blTree)\r
++                      {\r
++                              int max_count;               /* max repeat count */\r
++                              int min_count;               /* min repeat count */\r
++                              int count;                   /* repeat count of the current code */\r
++                              int curlen = -1;             /* length of current code */\r
++                              \r
++                              int i = 0;\r
++                              while (i < numCodes) {\r
++                                      count = 1;\r
++                                      int nextlen = length[i];\r
++                                      if (nextlen == 0) {\r
++                                              max_count = 138;\r
++                                              min_count = 3;\r
++                                      } else {\r
++                                              max_count = 6;\r
++                                              min_count = 3;\r
++                                              if (curlen != nextlen) {\r
++                                                      blTree.WriteSymbol(nextlen);\r
++                                                      count = 0;\r
++                                              }\r
++                                      }\r
++                                      curlen = nextlen;\r
++                                      i++;\r
++                                      \r
++                                      while (i < numCodes && curlen == length[i]) {\r
++                                              i++;\r
++                                              if (++count >= max_count) {\r
++                                                      break;\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      if (count < min_count) {\r
++                                              while (count-- > 0) {\r
++                                                      blTree.WriteSymbol(curlen);\r
++                                              }\r
++                                      } else if (curlen != 0) {\r
++                                              blTree.WriteSymbol(REP_3_6);\r
++                                              dh.pending.WriteBits(count - 3, 2);\r
++                                      } else if (count <= 10) {\r
++                                              blTree.WriteSymbol(REP_3_10);\r
++                                              dh.pending.WriteBits(count - 3, 3);\r
++                                      } else {\r
++                                              blTree.WriteSymbol(REP_11_138);\r
++                                              dh.pending.WriteBits(count - 11, 7);\r
++                                      }\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              public DeflaterPending pending;\r
++              private Tree literalTree, distTree, blTree;\r
++              \r
++              private short[] d_buf;\r
++              private byte[]  l_buf;\r
++              private int last_lit;\r
++              private int extra_bits;\r
++              \r
++              private static short[] staticLCodes;\r
++              private static byte[]  staticLLength;\r
++              private static short[] staticDCodes;\r
++              private static byte[]  staticDLength;\r
++              \r
++              /// <summary>\r
++              /// Reverse the bits of a 16 bit value.\r
++              /// </summary>\r
++              public static short BitReverse(int value) \r
++              {\r
++                      return (short) (bit4Reverse[value & 0xF] << 12 | \r
++                                      bit4Reverse[(value >> 4) & 0xF] << 8 | \r
++                                      bit4Reverse[(value >> 8) & 0xF] << 4 |\r
++                                      bit4Reverse[value >> 12]);\r
++              }\r
++              \r
++              \r
++              static DeflaterHuffman() \r
++              {\r
++                      /* See RFC 1951 3.2.6 */\r
++                      /* Literal codes */\r
++                      staticLCodes = new short[LITERAL_NUM];\r
++                      staticLLength = new byte[LITERAL_NUM];\r
++                      int i = 0;\r
++                      while (i < 144) {\r
++                              staticLCodes[i] = BitReverse((0x030 + i) << 8);\r
++                              staticLLength[i++] = 8;\r
++                      }\r
++                      while (i < 256) {\r
++                              staticLCodes[i] = BitReverse((0x190 - 144 + i) << 7);\r
++                              staticLLength[i++] = 9;\r
++                      }\r
++                      while (i < 280) {\r
++                              staticLCodes[i] = BitReverse((0x000 - 256 + i) << 9);\r
++                              staticLLength[i++] = 7;\r
++                      }\r
++                      while (i < LITERAL_NUM) {\r
++                              staticLCodes[i] = BitReverse((0x0c0 - 280 + i)  << 8);\r
++                              staticLLength[i++] = 8;\r
++                      }\r
++                      \r
++                      /* Distant codes */\r
++                      staticDCodes = new short[DIST_NUM];\r
++                      staticDLength = new byte[DIST_NUM];\r
++                      for (i = 0; i < DIST_NUM; i++) {\r
++                              staticDCodes[i] = BitReverse(i << 11);\r
++                              staticDLength[i] = 5;\r
++                      }\r
++              }\r
++              \r
++              public DeflaterHuffman(DeflaterPending pending)\r
++              {\r
++                      this.pending = pending;\r
++                      \r
++                      literalTree = new Tree(this, LITERAL_NUM, 257, 15);\r
++                      distTree    = new Tree(this, DIST_NUM, 1, 15);\r
++                      blTree      = new Tree(this, BITLEN_NUM, 4, 7);\r
++                      \r
++                      d_buf = new short[BUFSIZE];\r
++                      l_buf = new byte [BUFSIZE];\r
++              }\r
++              \r
++              public void Reset() \r
++              {\r
++                      last_lit = 0;\r
++                      extra_bits = 0;\r
++                      literalTree.Reset();\r
++                      distTree.Reset();\r
++                      blTree.Reset();\r
++              }\r
++              \r
++              int Lcode(int len) \r
++              {\r
++                      if (len == 255) {\r
++                              return 285;\r
++                      }\r
++                      \r
++                      int code = 257;\r
++                      while (len >= 8) {\r
++                              code += 4;\r
++                              len >>= 1;\r
++                      }\r
++                      return code + len;\r
++              }\r
++              \r
++              int Dcode(int distance) \r
++              {\r
++                      int code = 0;\r
++                      while (distance >= 4) {\r
++                              code += 2;\r
++                              distance >>= 1;\r
++                      }\r
++                      return code + distance;\r
++              }\r
++              \r
++              public void SendAllTrees(int blTreeCodes)\r
++              {\r
++                      blTree.BuildCodes();\r
++                      literalTree.BuildCodes();\r
++                      distTree.BuildCodes();\r
++                      pending.WriteBits(literalTree.numCodes - 257, 5);\r
++                      pending.WriteBits(distTree.numCodes - 1, 5);\r
++                      pending.WriteBits(blTreeCodes - 4, 4);\r
++                      for (int rank = 0; rank < blTreeCodes; rank++) {\r
++                              pending.WriteBits(blTree.length[BL_ORDER[rank]], 3);\r
++                      }\r
++                      literalTree.WriteTree(blTree);\r
++                      distTree.WriteTree(blTree);\r
++                      //                      if (DeflaterConstants.DEBUGGING) {\r
++                      //                              blTree.CheckEmpty();\r
++                      //                      }\r
++              }\r
++              \r
++              public void CompressBlock()\r
++              {\r
++                      for (int i = 0; i < last_lit; i++) {\r
++                              int litlen = l_buf[i] & 0xff;\r
++                              int dist = d_buf[i];\r
++                              if (dist-- != 0) {\r
++                                      //                                      if (DeflaterConstants.DEBUGGING) {\r
++                                      //                                              Console.Write("["+(dist+1)+","+(litlen+3)+"]: ");\r
++                                      //                                      }\r
++                                      \r
++                                      int lc = Lcode(litlen);\r
++                                      literalTree.WriteSymbol(lc);\r
++                                      \r
++                                      int bits = (lc - 261) / 4;\r
++                                      if (bits > 0 && bits <= 5) {\r
++                                              pending.WriteBits(litlen & ((1 << bits) - 1), bits);\r
++                                      }\r
++                                      \r
++                                      int dc = Dcode(dist);\r
++                                      distTree.WriteSymbol(dc);\r
++                                      \r
++                                      bits = dc / 2 - 1;\r
++                                      if (bits > 0) {\r
++                                              pending.WriteBits(dist & ((1 << bits) - 1), bits);\r
++                                      }\r
++                              } else {\r
++                                      //                                      if (DeflaterConstants.DEBUGGING) {\r
++                                      //                                              if (litlen > 32 && litlen < 127) {\r
++                                      //                                                      Console.Write("("+(char)litlen+"): ");\r
++                                      //                                              } else {\r
++                                      //                                                      Console.Write("{"+litlen+"}: ");\r
++                                      //                                              }\r
++                                      //                                      }\r
++                                      literalTree.WriteSymbol(litlen);\r
++                              }\r
++                      }\r
++                      //                      if (DeflaterConstants.DEBUGGING) {\r
++                      //                              Console.Write("EOF: ");\r
++                      //                      }\r
++                      literalTree.WriteSymbol(EOF_SYMBOL);\r
++                      //                      if (DeflaterConstants.DEBUGGING) {\r
++                      //                              literalTree.CheckEmpty();\r
++                      //                              distTree.CheckEmpty();\r
++                      //                      }\r
++              }\r
++              \r
++              public void FlushStoredBlock(byte[] stored, int storedOffset, int storedLength, bool lastBlock)\r
++              {\r
++                      //                      if (DeflaterConstants.DEBUGGING) {\r
++                      //                              //Console.WriteLine("Flushing stored block "+ storedLength);\r
++                      //                      }\r
++                      pending.WriteBits((DeflaterConstants.STORED_BLOCK << 1) + (lastBlock ? 1 : 0), 3);\r
++                      pending.AlignToByte();\r
++                      pending.WriteShort(storedLength);\r
++                      pending.WriteShort(~storedLength);\r
++                      pending.WriteBlock(stored, storedOffset, storedLength);\r
++                      Reset();\r
++              }\r
++              \r
++              public void FlushBlock(byte[] stored, int storedOffset, int storedLength, bool lastBlock)\r
++              {\r
++                      literalTree.freqs[EOF_SYMBOL]++;\r
++                      \r
++                      /* Build trees */\r
++                      literalTree.BuildTree();\r
++                      distTree.BuildTree();\r
++                      \r
++                      /* Calculate bitlen frequency */\r
++                      literalTree.CalcBLFreq(blTree);\r
++                      distTree.CalcBLFreq(blTree);\r
++                      \r
++                      /* Build bitlen tree */\r
++                      blTree.BuildTree();\r
++                      \r
++                      int blTreeCodes = 4;\r
++                      for (int i = 18; i > blTreeCodes; i--) {\r
++                              if (blTree.length[BL_ORDER[i]] > 0) {\r
++                                      blTreeCodes = i+1;\r
++                              }\r
++                      }\r
++                      int opt_len = 14 + blTreeCodes * 3 + blTree.GetEncodedLength() + \r
++                              literalTree.GetEncodedLength() + distTree.GetEncodedLength() + \r
++                              extra_bits;\r
++                      \r
++                      int static_len = extra_bits;\r
++                      for (int i = 0; i < LITERAL_NUM; i++) {\r
++                              static_len += literalTree.freqs[i] * staticLLength[i];\r
++                      }\r
++                      for (int i = 0; i < DIST_NUM; i++) {\r
++                              static_len += distTree.freqs[i] * staticDLength[i];\r
++                      }\r
++                      if (opt_len >= static_len) {\r
++                              /* Force static trees */\r
++                              opt_len = static_len;\r
++                      }\r
++                      \r
++                      if ((storedOffset >= 0) && (storedLength + 4 < (opt_len >> 3))) {\r
++                              /* Store Block */\r
++                              //                              if (DeflaterConstants.DEBUGGING) {\r
++                              //                                      //Console.WriteLine("Storing, since " + storedLength + " < " + opt_len\r
++                              //                                                        + " <= " + static_len);\r
++                              //                              }\r
++                              FlushStoredBlock(stored, storedOffset, storedLength, lastBlock);\r
++                      } else if (opt_len == static_len) {\r
++                              /* Encode with static tree */\r
++                              pending.WriteBits((DeflaterConstants.STATIC_TREES << 1) + (lastBlock ? 1 : 0), 3);\r
++                              literalTree.SetStaticCodes(staticLCodes, staticLLength);\r
++                              distTree.SetStaticCodes(staticDCodes, staticDLength);\r
++                              CompressBlock();\r
++                              Reset();\r
++                      } else {\r
++                              /* Encode with dynamic tree */\r
++                              pending.WriteBits((DeflaterConstants.DYN_TREES << 1) + (lastBlock ? 1 : 0), 3);\r
++                              SendAllTrees(blTreeCodes);\r
++                              CompressBlock();\r
++                              Reset();\r
++                      }\r
++              }\r
++              \r
++              public bool IsFull()\r
++              {\r
++//                    return last_lit + 16 >= BUFSIZE; // HACK: This was == 'last_lit == BUFSIZE', but errors occured with DeflateFast\r
++                      return last_lit >= BUFSIZE; // -jr- This is the correct form!\r
++              }\r
++              \r
++              public bool TallyLit(int lit)\r
++              {\r
++                      //                      if (DeflaterConstants.DEBUGGING) {\r
++                      //                              if (lit > 32 && lit < 127) {\r
++                      //                                      //Console.WriteLine("("+(char)lit+")");\r
++                      //                              } else {\r
++                      //                                      //Console.WriteLine("{"+lit+"}");\r
++                      //                              }\r
++                      //                      }\r
++                      d_buf[last_lit] = 0;\r
++                      l_buf[last_lit++] = (byte)lit;\r
++                      literalTree.freqs[lit]++;\r
++                      return IsFull();\r
++              }\r
++              \r
++              public bool TallyDist(int dist, int len)\r
++              {\r
++                      //                      if (DeflaterConstants.DEBUGGING) {\r
++                      //                              //Console.WriteLine("["+dist+","+len+"]");\r
++                      //                      }\r
++                      \r
++                      d_buf[last_lit]   = (short)dist;\r
++                      l_buf[last_lit++] = (byte)(len - 3);\r
++                      \r
++                      int lc = Lcode(len - 3);\r
++                      literalTree.freqs[lc]++;\r
++                      if (lc >= 265 && lc < 285) {\r
++                              extra_bits += (lc - 261) / 4;\r
++                      }\r
++                      \r
++                      int dc = Dcode(dist - 1);\r
++                      distTree.freqs[dc]++;\r
++                      if (dc >= 4) {\r
++                              extra_bits += dc / 2 - 1;\r
++                      }\r
++                      return IsFull();\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..8144ff35e61913a8bc08b4fe389341e8aa0b8ee2
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,52 @@@
++// DeflaterPending.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class stores the pending output of the Deflater.\r
++      /// \r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      public class DeflaterPending : PendingBuffer\r
++      {\r
++              public DeflaterPending() : base(DeflaterConstants.PENDING_BUF_SIZE)\r
++              {\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b915c8ffe7db35b1aff6b5999489017e4628f893
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,782 @@@
++// Inflater.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      /// <summary>\r
++      /// Inflater is used to decompress data that has been compressed according\r
++      /// to the "deflate" standard described in rfc1950.\r
++      ///\r
++      /// The usage is as following.  First you have to set some input with\r
++      /// <code>setInput()</code>, then inflate() it.  If inflate doesn't\r
++      /// inflate any bytes there may be three reasons:\r
++      /// <ul>\r
++      /// <li>needsInput() returns true because the input buffer is empty.\r
++      /// You have to provide more input with <code>setInput()</code>.\r
++      /// NOTE: needsInput() also returns true when, the stream is finished.\r
++      /// </li>\r
++      /// <li>needsDictionary() returns true, you have to provide a preset\r
++      ///    dictionary with <code>setDictionary()</code>.</li>\r
++      /// <li>finished() returns true, the inflater has finished.</li>\r
++      /// </ul>\r
++      /// Once the first output byte is produced, a dictionary will not be\r
++      /// needed at a later stage.\r
++      ///\r
++      /// author of the original java version : John Leuner, Jochen Hoenicke\r
++      /// </summary>\r
++      public class Inflater\r
++      {\r
++              /// <summary>\r
++              /// Copy lengths for literal codes 257..285\r
++              /// </summary>\r
++              private static int[] CPLENS = {\r
++                                                                                3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,\r
++                                                                                35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258\r
++                                                                        };\r
++              \r
++              /// <summary>\r
++              /// Extra bits for literal codes 257..285\r
++              /// </summary>\r
++              private static int[] CPLEXT = {\r
++                                                                                0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,\r
++                                                                                3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0\r
++                                                                        };\r
++              \r
++              /// <summary>\r
++              /// Copy offsets for distance codes 0..29\r
++              /// </summary>\r
++              private static int[] CPDIST = {\r
++                                                                                1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,\r
++                                                                                257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,\r
++                                                                                8193, 12289, 16385, 24577\r
++                                                                        };\r
++              \r
++              /// <summary>\r
++              /// Extra bits for distance codes\r
++              /// </summary>\r
++              private static int[] CPDEXT = {\r
++                                                                                0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,\r
++                                                                                7, 7, 8, 8, 9, 9, 10, 10, 11, 11,\r
++                                                                                12, 12, 13, 13\r
++                                                                        };\r
++              \r
++              /// <summary>\r
++              /// This are the state in which the inflater can be.\r
++              /// </summary>\r
++              private const int DECODE_HEADER           = 0;\r
++              private const int DECODE_DICT             = 1;\r
++              private const int DECODE_BLOCKS           = 2;\r
++              private const int DECODE_STORED_LEN1      = 3;\r
++              private const int DECODE_STORED_LEN2      = 4;\r
++              private const int DECODE_STORED           = 5;\r
++              private const int DECODE_DYN_HEADER       = 6;\r
++              private const int DECODE_HUFFMAN          = 7;\r
++              private const int DECODE_HUFFMAN_LENBITS  = 8;\r
++              private const int DECODE_HUFFMAN_DIST     = 9;\r
++              private const int DECODE_HUFFMAN_DISTBITS = 10;\r
++              private const int DECODE_CHKSUM           = 11;\r
++              private const int FINISHED                = 12;\r
++              \r
++              /// <summary>\r
++              /// This variable contains the current state.\r
++              /// </summary>\r
++              private int mode;\r
++              \r
++              /// <summary>\r
++              /// The adler checksum of the dictionary or of the decompressed\r
++              /// stream, as it is written in the header resp. footer of the\r
++              /// compressed stream. \r
++              /// Only valid if mode is DECODE_DICT or DECODE_CHKSUM.\r
++              /// </summary>\r
++              private int readAdler;\r
++              \r
++              /// <summary>\r
++              /// The number of bits needed to complete the current state.  This\r
++              /// is valid, if mode is DECODE_DICT, DECODE_CHKSUM,\r
++              /// DECODE_HUFFMAN_LENBITS or DECODE_HUFFMAN_DISTBITS.\r
++              /// </summary>\r
++              private int neededBits;\r
++              private int repLength, repDist;\r
++              private int uncomprLen;\r
++              \r
++              /// <summary>\r
++              /// True, if the last block flag was set in the last block of the\r
++              /// inflated stream.  This means that the stream ends after the\r
++              /// current block.\r
++              /// </summary>\r
++              private bool isLastBlock;\r
++              \r
++              /// <summary>\r
++              /// The total number of inflated bytes.\r
++              /// </summary>\r
++              private int totalOut;\r
++              \r
++              /// <summary>\r
++              /// The total number of bytes set with setInput().  This is not the\r
++              /// value returned by getTotalIn(), since this also includes the\r
++              /// unprocessed input.\r
++              /// </summary>\r
++              private int totalIn;\r
++              \r
++              /// <summary>\r
++              /// This variable stores the nowrap flag that was given to the constructor.\r
++              /// True means, that the inflated stream doesn't contain a header nor the\r
++              /// checksum in the footer.\r
++              /// </summary>\r
++              private bool nowrap;\r
++              \r
++              private StreamManipulator input;\r
++              private OutputWindow outputWindow;\r
++              private InflaterDynHeader dynHeader;\r
++              private InflaterHuffmanTree litlenTree, distTree;\r
++              private Adler32 adler;\r
++              \r
++              /// <summary>\r
++              /// Creates a new inflater.\r
++              /// </summary>\r
++              public Inflater() : this(false)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new inflater.\r
++              /// </summary>\r
++              /// <param name="nowrap">\r
++              /// true if no header and checksum field appears in the\r
++              /// stream.  This is used for GZIPed input.  For compatibility with\r
++              /// Sun JDK you should provide one byte of input more than needed in\r
++              /// this case.\r
++              /// </param>\r
++              public Inflater(bool nowrap)\r
++              {\r
++                      this.nowrap = nowrap;\r
++                      this.adler = new Adler32();\r
++                      input = new StreamManipulator();\r
++                      outputWindow = new OutputWindow();\r
++                      mode = nowrap ? DECODE_BLOCKS : DECODE_HEADER;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Resets the inflater so that a new stream can be decompressed.  All\r
++              /// pending input and output will be discarded.\r
++              /// </summary>\r
++              public void Reset()\r
++              {\r
++                      mode = nowrap ? DECODE_BLOCKS : DECODE_HEADER;\r
++                      totalIn = totalOut = 0;\r
++                      input.Reset();\r
++                      outputWindow.Reset();\r
++                      dynHeader = null;\r
++                      litlenTree = null;\r
++                      distTree = null;\r
++                      isLastBlock = false;\r
++                      adler.Reset();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Decodes the deflate header.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// false if more input is needed.\r
++              /// </returns>\r
++              /// <exception cref="System.FormatException">\r
++              /// if header is invalid.\r
++              /// </exception>\r
++              private bool DecodeHeader()\r
++              {\r
++                      int header = input.PeekBits(16);\r
++                      if (header < 0) {\r
++                              return false;\r
++                      }\r
++                      input.DropBits(16);\r
++                      /* The header is written in "wrong" byte order */\r
++                      header = ((header << 8) | (header >> 8)) & 0xffff;\r
++                      if (header % 31 != 0) {\r
++                              throw new FormatException("Header checksum illegal");\r
++                      }\r
++                      \r
++                      if ((header & 0x0f00) != (Deflater.DEFLATED << 8)) {\r
++                              throw new FormatException("Compression Method unknown");\r
++                      }\r
++                      \r
++                      /* Maximum size of the backwards window in bits.\r
++                      * We currently ignore this, but we could use it to make the\r
++                      * inflater window more space efficient. On the other hand the\r
++                      * full window (15 bits) is needed most times, anyway.\r
++                      int max_wbits = ((header & 0x7000) >> 12) + 8;\r
++                      */\r
++                      \r
++                      if ((header & 0x0020) == 0) { // Dictionary flag?\r
++                              mode = DECODE_BLOCKS;\r
++                      } else {\r
++                              mode = DECODE_DICT;\r
++                              neededBits = 32;\r
++                      }\r
++                      return true;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Decodes the dictionary checksum after the deflate header.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// false if more input is needed.\r
++              /// </returns>\r
++              private bool DecodeDict()\r
++              {\r
++                      while (neededBits > 0) {\r
++                              int dictByte = input.PeekBits(8);\r
++                              if (dictByte < 0) {\r
++                                      return false;\r
++                              }\r
++                              input.DropBits(8);\r
++                              readAdler = (readAdler << 8) | dictByte;\r
++                              neededBits -= 8;\r
++                      }\r
++                      return false;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Decodes the huffman encoded symbols in the input stream.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// false if more input is needed, true if output window is\r
++              /// full or the current block ends.\r
++              /// </returns>\r
++              /// <exception cref="System.FormatException">\r
++              /// if deflated stream is invalid.\r
++              /// </exception>\r
++              private bool DecodeHuffman()\r
++              {\r
++                      int free = outputWindow.GetFreeSpace();\r
++                      while (free >= 258) {\r
++                              int symbol;\r
++                              switch (mode) {\r
++                                      case DECODE_HUFFMAN:\r
++                                              /* This is the inner loop so it is optimized a bit */\r
++                                              while (((symbol = litlenTree.GetSymbol(input)) & ~0xff) == 0) {\r
++                                                      outputWindow.Write(symbol);\r
++                                                      if (--free < 258) {\r
++                                                              return true;\r
++                                                      }\r
++                                              }\r
++                                              if (symbol < 257) {\r
++                                                      if (symbol < 0) {\r
++                                                              return false;\r
++                                                      } else {\r
++                                                              /* symbol == 256: end of block */\r
++                                                              distTree = null;\r
++                                                              litlenTree = null;\r
++                                                              mode = DECODE_BLOCKS;\r
++                                                              return true;\r
++                                                      }\r
++                                              }\r
++                                              \r
++                                              try {\r
++                                                      repLength = CPLENS[symbol - 257];\r
++                                                      neededBits = CPLEXT[symbol - 257];\r
++                                              } catch (Exception) {\r
++                                                      throw new FormatException("Illegal rep length code");\r
++                                              }\r
++                                              goto case DECODE_HUFFMAN_LENBITS;/* fall through */\r
++                                      case DECODE_HUFFMAN_LENBITS:\r
++                                              if (neededBits > 0) {\r
++                                                      mode = DECODE_HUFFMAN_LENBITS;\r
++                                                      int i = input.PeekBits(neededBits);\r
++                                                      if (i < 0) {\r
++                                                              return false;\r
++                                                      }\r
++                                                      input.DropBits(neededBits);\r
++                                                      repLength += i;\r
++                                              }\r
++                                              mode = DECODE_HUFFMAN_DIST;\r
++                                              goto case DECODE_HUFFMAN_DIST;/* fall through */\r
++                                      case DECODE_HUFFMAN_DIST:\r
++                                              symbol = distTree.GetSymbol(input);\r
++                                              if (symbol < 0) {\r
++                                                      return false;\r
++                                              }\r
++                                              try {\r
++                                                      repDist = CPDIST[symbol];\r
++                                                      neededBits = CPDEXT[symbol];\r
++                                              } catch (Exception) {\r
++                                                      throw new FormatException("Illegal rep dist code");\r
++                                              }\r
++                                              \r
++                                              goto case DECODE_HUFFMAN_DISTBITS;/* fall through */\r
++                                      case DECODE_HUFFMAN_DISTBITS:\r
++                                              if (neededBits > 0) {\r
++                                                      mode = DECODE_HUFFMAN_DISTBITS;\r
++                                                      int i = input.PeekBits(neededBits);\r
++                                                      if (i < 0) {\r
++                                                              return false;\r
++                                                      }\r
++                                                      input.DropBits(neededBits);\r
++                                                      repDist += i;\r
++                                              }\r
++                                              outputWindow.Repeat(repLength, repDist);\r
++                                              free -= repLength;\r
++                                              mode = DECODE_HUFFMAN;\r
++                                              break;\r
++                                      default:\r
++                                              throw new FormatException();\r
++                              }\r
++                      }\r
++                      return true;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Decodes the adler checksum after the deflate stream.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// false if more input is needed.\r
++              /// </returns>\r
++              /// <exception cref="System.FormatException">\r
++              /// DataFormatException, if checksum doesn't match.\r
++              /// </exception>\r
++              private bool DecodeChksum()\r
++              {\r
++                      while (neededBits > 0) {\r
++                              int chkByte = input.PeekBits(8);\r
++                              if (chkByte < 0) {\r
++                                      return false;\r
++                              }\r
++                              input.DropBits(8);\r
++                              readAdler = (readAdler << 8) | chkByte;\r
++                              neededBits -= 8;\r
++                      }\r
++                      if ((int) adler.Value != readAdler) {\r
++                              throw new FormatException("Adler chksum doesn't match: " + (int)adler.Value + " vs. " + readAdler);\r
++                      }\r
++                      mode = FINISHED;\r
++                      return false;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Decodes the deflated stream.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// false if more input is needed, or if finished.\r
++              /// </returns>\r
++              /// <exception cref="System.FormatException">\r
++              /// DataFormatException, if deflated stream is invalid.\r
++              /// </exception>\r
++              private bool Decode()\r
++              {\r
++                      switch (mode) {\r
++                              case DECODE_HEADER:\r
++                                      return DecodeHeader();\r
++                              case DECODE_DICT:\r
++                                      return DecodeDict();\r
++                              case DECODE_CHKSUM:\r
++                                      return DecodeChksum();\r
++                              \r
++                              case DECODE_BLOCKS:\r
++                                      if (isLastBlock) {\r
++                                              if (nowrap) {\r
++                                                      mode = FINISHED;\r
++                                                      return false;\r
++                                              } else {\r
++                                                      input.SkipToByteBoundary();\r
++                                                      neededBits = 32;\r
++                                                      mode = DECODE_CHKSUM;\r
++                                                      return true;\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      int type = input.PeekBits(3);\r
++                                      if (type < 0) {\r
++                                              return false;\r
++                                      }\r
++                                      input.DropBits(3);\r
++                                      \r
++                                      if ((type & 1) != 0) {\r
++                                              isLastBlock = true;\r
++                                      }\r
++                                      switch (type >> 1){\r
++                                              case DeflaterConstants.STORED_BLOCK:\r
++                                                      input.SkipToByteBoundary();\r
++                                                      mode = DECODE_STORED_LEN1;\r
++                                                      break;\r
++                                              case DeflaterConstants.STATIC_TREES:\r
++                                                      litlenTree = InflaterHuffmanTree.defLitLenTree;\r
++                                                      distTree = InflaterHuffmanTree.defDistTree;\r
++                                                      mode = DECODE_HUFFMAN;\r
++                                                      break;\r
++                                              case DeflaterConstants.DYN_TREES:\r
++                                                      dynHeader = new InflaterDynHeader();\r
++                                                      mode = DECODE_DYN_HEADER;\r
++                                                      break;\r
++                                              default:\r
++                                                      throw new FormatException("Unknown block type "+type);\r
++                                      }\r
++                                      return true;\r
++                              \r
++                              case DECODE_STORED_LEN1: \r
++                              {\r
++                                      if ((uncomprLen = input.PeekBits(16)) < 0) {\r
++                                              return false;\r
++                                      }\r
++                                      input.DropBits(16);\r
++                                      mode = DECODE_STORED_LEN2;\r
++                              }\r
++                                      goto case DECODE_STORED_LEN2; /* fall through */\r
++                              case DECODE_STORED_LEN2: \r
++                              {\r
++                                      int nlen = input.PeekBits(16);\r
++                                      if (nlen < 0) {\r
++                                              return false;\r
++                                      }\r
++                                      input.DropBits(16);\r
++                                      if (nlen != (uncomprLen ^ 0xffff)) {\r
++                                              throw new FormatException("broken uncompressed block");\r
++                                      }\r
++                                      mode = DECODE_STORED;\r
++                              }\r
++                                      goto case DECODE_STORED;/* fall through */\r
++                              case DECODE_STORED: \r
++                              {\r
++                                      int more = outputWindow.CopyStored(input, uncomprLen);\r
++                                      uncomprLen -= more;\r
++                                      if (uncomprLen == 0) {\r
++                                              mode = DECODE_BLOCKS;\r
++                                              return true;\r
++                                      }\r
++                                      return !input.IsNeedingInput;\r
++                              }\r
++                              \r
++                              case DECODE_DYN_HEADER:\r
++                                      if (!dynHeader.Decode(input)) {\r
++                                              return false;\r
++                                      }\r
++                                      \r
++                                      litlenTree = dynHeader.BuildLitLenTree();\r
++                                      distTree = dynHeader.BuildDistTree();\r
++                                      mode = DECODE_HUFFMAN;\r
++                                      goto case DECODE_HUFFMAN; /* fall through */\r
++                              case DECODE_HUFFMAN:\r
++                              case DECODE_HUFFMAN_LENBITS:\r
++                              case DECODE_HUFFMAN_DIST:\r
++                              case DECODE_HUFFMAN_DISTBITS:\r
++                                      return DecodeHuffman();\r
++                              case FINISHED:\r
++                                      return false;\r
++                              default:\r
++                                      throw new FormatException();\r
++                      }\r
++              }\r
++                      \r
++              /// <summary>\r
++              /// Sets the preset dictionary.  This should only be called, if\r
++              /// needsDictionary() returns true and it should set the same\r
++              /// dictionary, that was used for deflating.  The getAdler()\r
++              /// function returns the checksum of the dictionary needed.\r
++              /// </summary>\r
++              /// <param name="buffer">\r
++              /// the dictionary.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if no dictionary is needed.\r
++              /// </exception>\r
++              /// <exception cref="System.ArgumentException">\r
++              /// if the dictionary checksum is wrong.\r
++              /// </exception>\r
++              public void SetDictionary(byte[] buffer)\r
++              {\r
++                      SetDictionary(buffer, 0, buffer.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the preset dictionary.  This should only be called, if\r
++              /// needsDictionary() returns true and it should set the same\r
++              /// dictionary, that was used for deflating.  The getAdler()\r
++              /// function returns the checksum of the dictionary needed.\r
++              /// </summary>\r
++              /// <param name="buffer">\r
++              /// the dictionary.\r
++              /// </param>\r
++              /// <param name="off">\r
++              /// the offset into buffer where the dictionary starts.\r
++              /// </param>\r
++              /// <param name="len">\r
++              /// the length of the dictionary.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if no dictionary is needed.\r
++              /// </exception>\r
++              /// <exception cref="System.ArgumentException">\r
++              /// if the dictionary checksum is wrong.\r
++              /// </exception>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if the off and/or len are wrong.\r
++              /// </exception>\r
++              public void SetDictionary(byte[] buffer, int off, int len)\r
++              {\r
++                      if (!IsNeedingDictionary) {\r
++                              throw new InvalidOperationException();\r
++                      }\r
++                      \r
++                      adler.Update(buffer, off, len);\r
++                      if ((int)adler.Value != readAdler) {\r
++                              throw new ArgumentException("Wrong adler checksum");\r
++                      }\r
++                      adler.Reset();\r
++                      outputWindow.CopyDict(buffer, off, len);\r
++                      mode = DECODE_BLOCKS;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the input.  This should only be called, if needsInput()\r
++              /// returns true.\r
++              /// </summary>\r
++              /// <param name="buf">\r
++              /// the input.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if no input is needed.\r
++              /// </exception>\r
++              public void SetInput(byte[] buf)\r
++              {\r
++                      SetInput(buf, 0, buf.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets the input.  This should only be called, if needsInput()\r
++              /// returns true.\r
++              /// </summary>\r
++              /// <param name="buf">\r
++              /// the input.\r
++              /// </param>\r
++              /// <param name="off">\r
++              /// the offset into buffer where the input starts.\r
++              /// </param>\r
++              /// <param name="len">\r
++              /// the length of the input.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if no input is needed.\r
++              /// </exception>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if the off and/or len are wrong.\r
++              /// </exception>\r
++              public void SetInput(byte[] buf, int off, int len)\r
++              {\r
++                      input.SetInput(buf, off, len);\r
++                      totalIn += len;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Inflates the compressed stream to the output buffer.  If this\r
++              /// returns 0, you should check, whether needsDictionary(),\r
++              /// needsInput() or finished() returns true, to determine why no\r
++              /// further output is produced.\r
++              /// </summary>\r
++              /// <param name = "buf">\r
++              /// the output buffer.\r
++              /// </param>\r
++              /// <returns>\r
++              /// the number of bytes written to the buffer, 0 if no further\r
++              /// output can be produced.\r
++              /// </returns>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if buf has length 0.\r
++              /// </exception>\r
++              /// <exception cref="System.FormatException">\r
++              /// if deflated stream is invalid.\r
++              /// </exception>\r
++              public int Inflate(byte[] buf)\r
++              {\r
++                      return Inflate(buf, 0, buf.Length);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Inflates the compressed stream to the output buffer.  If this\r
++              /// returns 0, you should check, whether needsDictionary(),\r
++              /// needsInput() or finished() returns true, to determine why no\r
++              /// further output is produced.\r
++              /// </summary>\r
++              /// <param name = "buf">\r
++              /// the output buffer.\r
++              /// </param>\r
++              /// <param name = "off">\r
++              /// the offset into buffer where the output should start.\r
++              /// </param>\r
++              /// <param name = "len">\r
++              /// the maximum length of the output.\r
++              /// </param>\r
++              /// <returns>\r
++              /// the number of bytes written to the buffer, 0 if no further output can be produced.\r
++              /// </returns>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if len is &lt;= 0.\r
++              /// </exception>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if the off and/or len are wrong.\r
++              /// </exception>\r
++              /// <exception cref="System.FormatException">\r
++              /// if deflated stream is invalid.\r
++              /// </exception>\r
++              public int Inflate(byte[] buf, int off, int len)\r
++              {\r
++                      if (len < 0) {\r
++                              throw new ArgumentOutOfRangeException("len < 0");\r
++                      }\r
++                      // Special case: len may be zero\r
++                      if (len == 0) {\r
++                              if (IsFinished == false) {// -jr- 08-Nov-2003 INFLATE_BUG fix..\r
++                                      Decode();\r
++                              }\r
++                              return 0;\r
++                      }\r
++                      /*                      // Check for correct buff, off, len triple\r
++                                              if (off < 0 || off + len >= buf.Length) {\r
++                                                      throw new ArgumentException("off/len outside buf bounds");\r
++                                              }*/\r
++                      int count = 0;\r
++                      int more;\r
++                      do {\r
++                              if (mode != DECODE_CHKSUM) {\r
++                                      /* Don't give away any output, if we are waiting for the\r
++                                      * checksum in the input stream.\r
++                                      *\r
++                                      * With this trick we have always:\r
++                                      *   needsInput() and not finished()\r
++                                      *   implies more output can be produced.\r
++                                      */\r
++                                      more = outputWindow.CopyOutput(buf, off, len);\r
++                                      adler.Update(buf, off, more);\r
++                                      off += more;\r
++                                      count += more;\r
++                                      totalOut += more;\r
++                                      len -= more;\r
++                                      if (len == 0) {\r
++                                              return count;\r
++                                      }\r
++                              }\r
++                      } while (Decode() || (outputWindow.GetAvailable() > 0 && mode != DECODE_CHKSUM));\r
++                      return count;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns true, if the input buffer is empty.\r
++              /// You should then call setInput(). \r
++              /// NOTE: This method also returns true when the stream is finished.\r
++              /// </summary>\r
++              public bool IsNeedingInput {\r
++                      get {\r
++                              return input.IsNeedingInput;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns true, if a preset dictionary is needed to inflate the input.\r
++              /// </summary>\r
++              public bool IsNeedingDictionary {\r
++                      get {\r
++                              return mode == DECODE_DICT && neededBits == 0;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns true, if the inflater has finished.  This means, that no\r
++              /// input is needed and no output can be produced.\r
++              /// </summary>\r
++              public bool IsFinished {\r
++                      get {\r
++                              return mode == FINISHED && outputWindow.GetAvailable() == 0;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the adler checksum.  This is either the checksum of all\r
++              /// uncompressed bytes returned by inflate(), or if needsDictionary()\r
++              /// returns true (and thus no output was yet produced) this is the\r
++              /// adler checksum of the expected dictionary.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the adler checksum.\r
++              /// </returns>\r
++              public int Adler {\r
++                      get {\r
++                              return IsNeedingDictionary ? readAdler : (int) adler.Value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the total number of output bytes returned by inflate().\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the total number of output bytes.\r
++              /// </returns>\r
++              public int TotalOut {\r
++                      get {\r
++                              return totalOut;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the total number of processed compressed input bytes.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the total number of bytes of processed input bytes.\r
++              /// </returns>\r
++              public int TotalIn {\r
++                      get {\r
++                              return totalIn - RemainingInput;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the number of unprocessed input.  Useful, if the end of the\r
++              /// stream is reached and you want to further process the bytes after\r
++              /// the deflate stream.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the number of bytes of the input which were not processed.\r
++              /// </returns>\r
++              public int RemainingInput {\r
++                      get {\r
++                              return input.AvailableBytes;\r
++                      }\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..653c7847cea575e3f1e43cdfd1527ef914322ebf
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,207 @@@
++// InflaterDynHeader.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++//\r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      class InflaterDynHeader\r
++      {\r
++              const int LNUM   = 0;\r
++              const int DNUM   = 1;\r
++              const int BLNUM  = 2;\r
++              const int BLLENS = 3;\r
++              const int LENS   = 4;\r
++              const int REPS   = 5;\r
++              \r
++              static readonly int[] repMin  = { 3, 3, 11 };\r
++              static readonly int[] repBits = { 2, 3,  7 };\r
++              \r
++              byte[] blLens;\r
++              byte[] litdistLens;\r
++              \r
++              InflaterHuffmanTree blTree;\r
++              \r
++              int mode;\r
++              int lnum, dnum, blnum, num;\r
++              int repSymbol;\r
++              byte lastLen;\r
++              int ptr;\r
++              \r
++              static readonly int[] BL_ORDER = \r
++              { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };\r
++              \r
++              public InflaterDynHeader()\r
++              {\r
++              }\r
++              \r
++              public bool Decode(StreamManipulator input)\r
++              {\r
++                      decode_loop:\r
++                              for (;;) {\r
++                                      switch (mode) {\r
++                                              case LNUM:\r
++                                                      lnum = input.PeekBits(5);\r
++                                                      if (lnum < 0) {\r
++                                                              return false;\r
++                                                      }\r
++                                                      lnum += 257;\r
++                                                      input.DropBits(5);\r
++                                                      //          System.err.println("LNUM: "+lnum);\r
++                                                      mode = DNUM;\r
++                                                      goto case DNUM; // fall through\r
++                                              case DNUM:\r
++                                                      dnum = input.PeekBits(5);\r
++                                                      if (dnum < 0) {\r
++                                                              return false;\r
++                                                      }\r
++                                                      dnum++;\r
++                                                      input.DropBits(5);\r
++                                                      //          System.err.println("DNUM: "+dnum);\r
++                                                      num = lnum+dnum;\r
++                                                      litdistLens = new byte[num];\r
++                                                      mode = BLNUM;\r
++                                                      goto case BLNUM; // fall through\r
++                                              case BLNUM:\r
++                                                      blnum = input.PeekBits(4);\r
++                                                      if (blnum < 0) {\r
++                                                              return false;\r
++                                                      }\r
++                                                      blnum += 4;\r
++                                                      input.DropBits(4);\r
++                                                      blLens = new byte[19];\r
++                                                      ptr = 0;\r
++                                                      //          System.err.println("BLNUM: "+blnum);\r
++                                                      mode = BLLENS;\r
++                                                      goto case BLLENS; // fall through\r
++                                              case BLLENS:\r
++                                                      while (ptr < blnum) {\r
++                                                              int len = input.PeekBits(3);\r
++                                                              if (len < 0) {\r
++                                                                      return false;\r
++                                                              }\r
++                                                              input.DropBits(3);\r
++                                                              //              System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);\r
++                                                              blLens[BL_ORDER[ptr]] = (byte) len;\r
++                                                              ptr++;\r
++                                                      }\r
++                                                      blTree = new InflaterHuffmanTree(blLens);\r
++                                                      blLens = null;\r
++                                                      ptr = 0;\r
++                                                      mode = LENS;\r
++                                                      goto case LENS; // fall through\r
++                                              case LENS: \r
++                                              {\r
++                                                      int symbol;\r
++                                                      while (((symbol = blTree.GetSymbol(input)) & ~15) == 0) {\r
++                                                              /* Normal case: symbol in [0..15] */\r
++                                                      \r
++                                                              //                System.err.println("litdistLens["+ptr+"]: "+symbol);\r
++                                                              litdistLens[ptr++] = lastLen = (byte)symbol;\r
++                                                      \r
++                                                              if (ptr == num) {\r
++                                                                      /* Finished */\r
++                                                                      return true;\r
++                                                              }\r
++                                                      }\r
++                                              \r
++                                                      /* need more input ? */\r
++                                                      if (symbol < 0) {\r
++                                                              return false;\r
++                                                      }\r
++                                              \r
++                                                      /* otherwise repeat code */\r
++                                                      if (symbol >= 17) {\r
++                                                              /* repeat zero */\r
++                                                              //                System.err.println("repeating zero");\r
++                                                              lastLen = 0;\r
++                                                      } else {\r
++                                                              if (ptr == 0) {\r
++                                                                      throw new Exception();\r
++                                                              }\r
++                                                      }\r
++                                                      repSymbol = symbol-16;\r
++                                              }\r
++                                                      mode = REPS;\r
++                                                      goto case REPS; // fall through\r
++                                              case REPS:\r
++                                              {\r
++                                                      int bits = repBits[repSymbol];\r
++                                                      int count = input.PeekBits(bits);\r
++                                                      if (count < 0) {\r
++                                                              return false;\r
++                                                      }\r
++                                                      input.DropBits(bits);\r
++                                                      count += repMin[repSymbol];\r
++                                                      //            System.err.println("litdistLens repeated: "+count);\r
++                                                      \r
++                                                      if (ptr + count > num) {\r
++                                                              throw new Exception();\r
++                                                      }\r
++                                                      while (count-- > 0) {\r
++                                                              litdistLens[ptr++] = lastLen;\r
++                                                      }\r
++                                                      \r
++                                                      if (ptr == num) {\r
++                                                              /* Finished */\r
++                                                              return true;\r
++                                                      }\r
++                                              }\r
++                                                      mode = LENS;\r
++                                                      goto decode_loop;\r
++                                      }\r
++                              }\r
++              }\r
++              \r
++              public InflaterHuffmanTree BuildLitLenTree()\r
++              {\r
++                      byte[] litlenLens = new byte[lnum];\r
++                      Array.Copy(litdistLens, 0, litlenLens, 0, lnum);\r
++                      return new InflaterHuffmanTree(litlenLens);\r
++              }\r
++              \r
++              public InflaterHuffmanTree BuildDistTree()\r
++              {\r
++                      byte[] distLens = new byte[dnum];\r
++                      Array.Copy(litdistLens, lnum, distLens, 0, dnum);\r
++                      return new InflaterHuffmanTree(distLens);\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..02beb60a34c8273facc804a35e61c54afaa717aa
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,213 @@@
++// InflaterHuffmanTree.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      public class InflaterHuffmanTree \r
++      {\r
++              private static int MAX_BITLEN = 15;\r
++              private short[] tree;\r
++              \r
++              public static InflaterHuffmanTree defLitLenTree, defDistTree;\r
++              \r
++              static InflaterHuffmanTree()\r
++              {\r
++                      try {\r
++                              byte[] codeLengths = new byte[288];\r
++                              int i = 0;\r
++                              while (i < 144) {\r
++                                      codeLengths[i++] = 8;\r
++                              }\r
++                              while (i < 256) {\r
++                                      codeLengths[i++] = 9;\r
++                              }\r
++                              while (i < 280) {\r
++                                      codeLengths[i++] = 7;\r
++                              }\r
++                              while (i < 288) {\r
++                                      codeLengths[i++] = 8;\r
++                              }\r
++                              defLitLenTree = new InflaterHuffmanTree(codeLengths);\r
++                              \r
++                              codeLengths = new byte[32];\r
++                              i = 0;\r
++                              while (i < 32) {\r
++                                      codeLengths[i++] = 5;\r
++                              }\r
++                              defDistTree = new InflaterHuffmanTree(codeLengths);\r
++                      } catch (Exception) {\r
++                              throw new ApplicationException("InflaterHuffmanTree: static tree length illegal");\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Constructs a Huffman tree from the array of code lengths.\r
++              /// </summary>\r
++              /// <param name = "codeLengths">\r
++              /// the array of code lengths\r
++              /// </param>\r
++              public InflaterHuffmanTree(byte[] codeLengths)\r
++              {\r
++                      BuildTree(codeLengths);\r
++              }\r
++              \r
++              private void BuildTree(byte[] codeLengths)\r
++              {\r
++                      int[] blCount  = new int[MAX_BITLEN + 1];\r
++                      int[] nextCode = new int[MAX_BITLEN + 1];\r
++                      \r
++                      for (int i = 0; i < codeLengths.Length; i++) {\r
++                              int bits = codeLengths[i];\r
++                              if (bits > 0) {\r
++                                      blCount[bits]++;\r
++                              }\r
++                      }\r
++                      \r
++                      int code = 0;\r
++                      int treeSize = 512;\r
++                      for (int bits = 1; bits <= MAX_BITLEN; bits++) {\r
++                              nextCode[bits] = code;\r
++                              code += blCount[bits] << (16 - bits);\r
++                              if (bits >= 10) {\r
++                                      /* We need an extra table for bit lengths >= 10. */\r
++                                      int start = nextCode[bits] & 0x1ff80;\r
++                                      int end   = code & 0x1ff80;\r
++                                      treeSize += (end - start) >> (16 - bits);\r
++                              }\r
++                      }\r
++/* -jr comment this out! doesnt work for dynamic trees and pkzip 2.04g\r
++                      if (code != 65536) \r
++                      {\r
++                              throw new Exception("Code lengths don't add up properly.");\r
++                      }\r
++*/\r
++                      /* Now create and fill the extra tables from longest to shortest\r
++                      * bit len.  This way the sub trees will be aligned.\r
++                      */\r
++                      tree = new short[treeSize];\r
++                      int treePtr = 512;\r
++                      for (int bits = MAX_BITLEN; bits >= 10; bits--) {\r
++                              int end   = code & 0x1ff80;\r
++                              code -= blCount[bits] << (16 - bits);\r
++                              int start = code & 0x1ff80;\r
++                              for (int i = start; i < end; i += 1 << 7) {\r
++                                      tree[DeflaterHuffman.BitReverse(i)] = (short) ((-treePtr << 4) | bits);\r
++                                      treePtr += 1 << (bits-9);\r
++                              }\r
++                      }\r
++                      \r
++                      for (int i = 0; i < codeLengths.Length; i++) {\r
++                              int bits = codeLengths[i];\r
++                              if (bits == 0) {\r
++                                      continue;\r
++                              }\r
++                              code = nextCode[bits];\r
++                              int revcode = DeflaterHuffman.BitReverse(code);\r
++                              if (bits <= 9) {\r
++                                      do {\r
++                                              tree[revcode] = (short) ((i << 4) | bits);\r
++                                              revcode += 1 << bits;\r
++                                      } while (revcode < 512);\r
++                              } else {\r
++                                      int subTree = tree[revcode & 511];\r
++                                      int treeLen = 1 << (subTree & 15);\r
++                                      subTree = -(subTree >> 4);\r
++                                      do {\r
++                                              tree[subTree | (revcode >> 9)] = (short) ((i << 4) | bits);\r
++                                              revcode += 1 << bits;\r
++                                      } while (revcode < treeLen);\r
++                              }\r
++                              nextCode[bits] = code + (1 << (16 - bits));\r
++                      }\r
++                      \r
++              }\r
++              \r
++              /// <summary>\r
++              /// Reads the next symbol from input.  The symbol is encoded using the\r
++              /// huffman tree.\r
++              /// </summary>\r
++              /// <param name="input">\r
++              /// input the input source.\r
++              /// </param>\r
++              /// <returns>\r
++              /// the next symbol, or -1 if not enough input is available.\r
++              /// </returns>\r
++              public int GetSymbol(StreamManipulator input)\r
++              {\r
++                      int lookahead, symbol;\r
++                      if ((lookahead = input.PeekBits(9)) >= 0) {\r
++                              if ((symbol = tree[lookahead]) >= 0) {\r
++                                      input.DropBits(symbol & 15);\r
++                                      return symbol >> 4;\r
++                              }\r
++                              int subtree = -(symbol >> 4);\r
++                              int bitlen = symbol & 15;\r
++                              if ((lookahead = input.PeekBits(bitlen)) >= 0) {\r
++                                      symbol = tree[subtree | (lookahead >> 9)];\r
++                                      input.DropBits(symbol & 15);\r
++                                      return symbol >> 4;\r
++                              } else {\r
++                                      int bits = input.AvailableBits;\r
++                                      lookahead = input.PeekBits(bits);\r
++                                      symbol = tree[subtree | (lookahead >> 9)];\r
++                                      if ((symbol & 15) <= bits) {\r
++                                              input.DropBits(symbol & 15);\r
++                                              return symbol >> 4;\r
++                                      } else {\r
++                                              return -1;\r
++                                      }\r
++                              }\r
++                      } else {\r
++                              int bits = input.AvailableBits;\r
++                              lookahead = input.PeekBits(bits);\r
++                              symbol = tree[lookahead];\r
++                              if (symbol >= 0 && (symbol & 15) <= bits) {\r
++                                      input.DropBits(symbol & 15);\r
++                                      return symbol >> 4;\r
++                              } else {\r
++                                      return -1;\r
++                              }\r
++                      }\r
++              }\r
++      }\r
++}\r
++\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..e0bc96b919208d1951c344ef8259d86020f5bea5
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,210 @@@
++// PendingBuffer.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class is general purpose class for writing data to a buffer.\r
++      /// \r
++      /// It allows you to write bits as well as bytes\r
++      /// Based on DeflaterPending.java\r
++      /// \r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      public class PendingBuffer\r
++      {\r
++              protected byte[] buf;\r
++              int    start;\r
++              int    end;\r
++              \r
++              uint    bits;\r
++              int    bitCount;\r
++              \r
++              public PendingBuffer() : this( 4096 )\r
++              {\r
++                      \r
++              }\r
++              \r
++              public PendingBuffer(int bufsize)\r
++              {\r
++                      buf = new byte[bufsize];\r
++              }\r
++              \r
++              public void Reset() \r
++              {\r
++                      start = end = bitCount = 0;\r
++              }\r
++              \r
++              public void WriteByte(int b)\r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && start != 0) {\r
++                              throw new Exception();\r
++                      }\r
++                      buf[end++] = (byte) b;\r
++              }\r
++              \r
++              public void WriteShort(int s)\r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && start != 0) {\r
++                              throw new Exception();\r
++                      }\r
++                      buf[end++] = (byte) s;\r
++                      buf[end++] = (byte) (s >> 8);\r
++              }\r
++              \r
++              public void WriteInt(int s)\r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && start != 0) {\r
++                              throw new Exception();\r
++                      }\r
++                      buf[end++] = (byte) s;\r
++                      buf[end++] = (byte) (s >> 8);\r
++                      buf[end++] = (byte) (s >> 16);\r
++                      buf[end++] = (byte) (s >> 24);\r
++              }\r
++              \r
++              public void WriteBlock(byte[] block, int offset, int len)\r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && start != 0) {\r
++                              throw new Exception();\r
++                      }\r
++                      System.Array.Copy(block, offset, buf, end, len);\r
++                      end += len;\r
++              }\r
++              \r
++              public int BitCount {\r
++                      get {\r
++                              return bitCount;\r
++                      }\r
++              }\r
++              \r
++              public void AlignToByte() \r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && start != 0) {\r
++                              throw new Exception();\r
++                      }\r
++                      if (bitCount > 0) {\r
++                              buf[end++] = (byte) bits;\r
++                              if (bitCount > 8) {\r
++                                      buf[end++] = (byte) (bits >> 8);\r
++                              }\r
++                      }\r
++                      bits = 0;\r
++                      bitCount = 0;\r
++              }\r
++              \r
++              public void WriteBits(int b, int count)\r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && start != 0) {\r
++                              throw new Exception();\r
++                      }\r
++                      //                      if (DeflaterConstants.DEBUGGING) {\r
++                      //                              //Console.WriteLine("writeBits("+b+","+count+")");\r
++                      //                      }\r
++                      bits |= (uint)(b << bitCount);\r
++                      bitCount += count;\r
++                      if (bitCount >= 16) {\r
++                              buf[end++] = (byte) bits;\r
++                              buf[end++] = (byte) (bits >> 8);\r
++                              bits >>= 16;\r
++                              bitCount -= 16;\r
++                      }\r
++              }\r
++              \r
++              public void WriteShortMSB(int s) \r
++              {\r
++                      if (DeflaterConstants.DEBUGGING && start != 0) {\r
++                              throw new Exception();\r
++                      }\r
++                      buf[end++] = (byte) (s >> 8);\r
++                      buf[end++] = (byte) s;\r
++              }\r
++              \r
++              public bool IsFlushed {\r
++                      get {\r
++                              return end == 0;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Flushes the pending buffer into the given output array.  If the\r
++              /// output array is to small, only a partial flush is done.\r
++              /// </summary>\r
++              /// <param name="output">\r
++              /// the output array;\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// the offset into output array;\r
++              /// </param>\r
++              /// <param name="length">               \r
++              /// length the maximum number of bytes to store;\r
++              /// </param>\r
++              /// <exception name="ArgumentOutOfRangeException">\r
++              /// IndexOutOfBoundsException if offset or length are invalid.\r
++              /// </exception>\r
++              public int Flush(byte[] output, int offset, int length) \r
++              {\r
++                      if (bitCount >= 8) {\r
++                              buf[end++] = (byte) bits;\r
++                              bits >>= 8;\r
++                              bitCount -= 8;\r
++                      }\r
++                      if (length > end - start) {\r
++                              length = end - start;\r
++                              System.Array.Copy(buf, start, output, offset, length);\r
++                              start = 0;\r
++                              end = 0;\r
++                      } else {\r
++                              System.Array.Copy(buf, start, output, offset, length);\r
++                              start += length;\r
++                      }\r
++                      return length;\r
++              }\r
++              \r
++              public byte[] ToByteArray()\r
++              {\r
++                      byte[] ret = new byte[end - start];\r
++                      System.Array.Copy(buf, start, ret, 0, ret.Length);\r
++                      start = 0;\r
++                      end = 0;\r
++                      return ret;\r
++              }\r
++      }\r
++}     \r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..dd8c658e8435a17082eba58f2879e44aa7570b9f
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,379 @@@
++// DeflaterOutputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++using ICSharpCode.SharpZipLib.Zip.Compression;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams \r
++{\r
++\r
++      /// <summary>\r
++      /// This is a special FilterOutputStream deflating the bytes that are\r
++      /// written through it.  It uses the Deflater for deflating.\r
++      /// \r
++      /// authors of the original java version : Tom Tromey, Jochen Hoenicke \r
++      /// </summary>\r
++      public class DeflaterOutputStream : Stream\r
++      {\r
++              /// <summary>\r
++              /// This buffer is used temporarily to retrieve the bytes from the\r
++              /// deflater and write them to the underlying output stream.\r
++              /// </summary>\r
++              protected byte[] buf;\r
++              \r
++              /// <summary>\r
++              /// The deflater which is used to deflate the stream.\r
++              /// </summary>\r
++              protected Deflater def;\r
++              \r
++              /// <summary>\r
++              /// base stream the deflater depends on.\r
++              /// </summary>\r
++              protected Stream baseOutputStream;\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanRead {\r
++                      get {\r
++                              return baseOutputStream.CanRead;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanSeek {\r
++                      get {\r
++                              return false;\r
++//                            return baseOutputStream.CanSeek;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanWrite {\r
++                      get {\r
++                              return baseOutputStream.CanWrite;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Length {\r
++                      get {\r
++                              return baseOutputStream.Length;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Position {\r
++                      get {\r
++                              return baseOutputStream.Position;\r
++                      }\r
++                      set {\r
++                              baseOutputStream.Position = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Seek(long offset, SeekOrigin origin)\r
++              {\r
++                      throw new NotSupportedException("Seek not supported"); // -jr- 01-Dec-2003\r
++//                    return baseOutputStream.Seek(offset, origin);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void SetLength(long val)\r
++              {\r
++                      baseOutputStream.SetLength(val);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override int ReadByte()\r
++              {\r
++                      return baseOutputStream.ReadByte();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override int Read(byte[] b, int off, int len)\r
++              {\r
++                      return baseOutputStream.Read(b, off, len);\r
++              }\r
++              // -jr- 01-Dec-2003\r
++              public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)\r
++              {\r
++                      throw new NotSupportedException("Asynch read not currently supported");\r
++              }\r
++              \r
++              // -jr- 01-Dec-2003\r
++              public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)\r
++              {\r
++                      throw new NotSupportedException("Asynch write not currently supported");\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Deflates everything in the def's input buffers.  This will call\r
++              /// <code>def.deflate()</code> until all bytes from the input buffers\r
++              /// are processed.\r
++              /// </summary>\r
++              protected void Deflate()\r
++              {\r
++                      while (!def.IsNeedingInput) {\r
++                              int len = def.Deflate(buf, 0, buf.Length);\r
++                              \r
++                              //      System.err.println("DOS deflated " + len + " baseOutputStream of " + buf.length);\r
++                              if (len <= 0) {\r
++                                      break;\r
++                              }\r
++                              baseOutputStream.Write(buf, 0, len);\r
++                      }\r
++                      \r
++                      if (!def.IsNeedingInput) {\r
++                              throw new ApplicationException("Can't deflate all input?");\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new DeflaterOutputStream with a default Deflater and default buffer size.\r
++              /// </summary>\r
++              /// <param name="baseOutputStream">\r
++              /// the output stream where deflated output should be written.\r
++              /// </param>\r
++              public DeflaterOutputStream(Stream baseOutputStream) : this(baseOutputStream, new Deflater(), 512)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new DeflaterOutputStream with the given Deflater and\r
++              /// default buffer size.\r
++              /// </summary>\r
++              /// <param name="baseOutputStream">\r
++              /// the output stream where deflated output should be written.\r
++              /// </param>\r
++              /// <param name="defl">\r
++              /// the underlying deflater.\r
++              /// </param>\r
++              public DeflaterOutputStream(Stream baseOutputStream, Deflater defl) :this(baseOutputStream, defl, 512)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new DeflaterOutputStream with the given Deflater and\r
++              /// buffer size.\r
++              /// </summary>\r
++              /// <param name="baseOutputStream">\r
++              /// the output stream where deflated output should be written.\r
++              /// </param>\r
++              /// <param name="defl">\r
++              /// the underlying deflater.\r
++              /// </param>\r
++              /// <param name="bufsize">\r
++              /// the buffer size.\r
++              /// </param>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if bufsize isn't positive.\r
++              /// </exception>\r
++              public DeflaterOutputStream(Stream baseOutputStream, Deflater defl, int bufsize)\r
++              {\r
++                      this.baseOutputStream = baseOutputStream;\r
++                      if (bufsize <= 0) {\r
++                              throw new InvalidOperationException("bufsize <= 0");\r
++                      }\r
++                      buf = new byte[bufsize];\r
++                      def = defl;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Flushes the stream by calling flush() on the deflater and then\r
++              /// on the underlying stream.  This ensures that all bytes are\r
++              /// flushed.\r
++              /// </summary>\r
++              public override void Flush()\r
++              {\r
++                      def.Flush();\r
++                      Deflate();\r
++                      baseOutputStream.Flush();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Finishes the stream by calling finish() on the deflater. \r
++              /// </summary>\r
++              public virtual void Finish()\r
++              {\r
++                      def.Finish();\r
++                      while (!def.IsFinished)  {\r
++                              int len = def.Deflate(buf, 0, buf.Length);\r
++                              if (len <= 0) {\r
++                                      break;\r
++                              }\r
++                              \r
++                              // kidnthrain encryption alteration\r
++                              if (this.Password != null) {\r
++                                      // plain data has been deflated. Now encrypt result\r
++                                      this.EncryptBlock(buf, 0, len);\r
++                              }\r
++                              \r
++                              baseOutputStream.Write(buf, 0, len);\r
++                      }\r
++                      if (!def.IsFinished) {\r
++                              throw new ApplicationException("Can't deflate all input?");\r
++                      }\r
++                      baseOutputStream.Flush();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Calls finish () and closes the stream.\r
++              /// </summary>\r
++              public override void Close()\r
++              {\r
++                      Finish();\r
++                      baseOutputStream.Close();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Writes a single byte to the compressed output stream.\r
++              /// </summary>\r
++              /// <param name="bval">\r
++              /// the byte value.\r
++              /// </param>\r
++              public override void WriteByte(byte bval)\r
++              {\r
++                      byte[] b = new byte[1];\r
++                      b[0] = (byte) bval;\r
++                      Write(b, 0, 1);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Writes a len bytes from an array to the compressed stream.\r
++              /// </summary>\r
++              /// <param name="buf">\r
++              /// the byte array.\r
++              /// </param>\r
++              /// <param name="off">\r
++              /// the offset into the byte array where to start.\r
++              /// </param>\r
++              /// <param name="len">\r
++              /// the number of bytes to write.\r
++              /// </param>\r
++              public override void Write(byte[] buf, int off, int len)\r
++              {\r
++                      //    System.err.println("DOS with off " + off + " and len " + len);\r
++                      def.SetInput(buf, off, len);\r
++                      Deflate();\r
++              }\r
++              \r
++              #region Encryption\r
++              string password = null;\r
++              uint[] keys     = null;\r
++              \r
++              public string Password {\r
++                      get { \r
++                              return password; \r
++                      }\r
++                      set { \r
++                              password = value; \r
++                      }\r
++              }\r
++              \r
++              \r
++              //The beauty of xor-ing bits is that\r
++              //plain ^ key = enc\r
++              //and enc ^ key = plain\r
++              //accordingly, this is the exact same as the decrypt byte\r
++              //function in InflaterInputStream\r
++              protected byte EncryptByte()\r
++              {\r
++                      uint temp = ((keys[2] & 0xFFFF) | 2);\r
++                      return (byte)((temp * (temp ^ 1)) >> 8);\r
++              }\r
++              \r
++              \r
++              /// <summary>\r
++              /// Takes a buffer of data and uses the keys\r
++              /// that have been previously initialized from a\r
++              /// password and then updated via a random encryption header\r
++              /// to encrypt that data\r
++              /// </summary>\r
++              protected void EncryptBlock(byte[] buf, int off, int len)\r
++              {\r
++                      for (int i = off; i < off + len; ++i) {\r
++                              byte oldbyte = buf[i];\r
++                              buf[i] ^= EncryptByte();\r
++                              UpdateKeys(oldbyte);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Initializes our encryption keys using a given password\r
++              /// </summary>\r
++              protected void InitializePassword(string password) {\r
++                      keys = new uint[] {\r
++                              0x12345678,\r
++                              0x23456789,\r
++                              0x34567890\r
++                      };\r
++                      \r
++                      for (int i = 0; i < password.Length; ++i) {\r
++                              UpdateKeys((byte)password[i]);\r
++                      }\r
++              }\r
++              \r
++              protected void UpdateKeys(byte ch)\r
++              {\r
++                      keys[0] = Crc32.ComputeCrc32(keys[0], ch);\r
++                      keys[1] = keys[1] + (byte)keys[0];\r
++                      keys[1] = keys[1] * 134775813 + 1;\r
++                      keys[2] = Crc32.ComputeCrc32(keys[2], (byte)(keys[1] >> 24));\r
++              }\r
++              #endregion\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..9317e5e185d31b42b1232ea5dc8fbbb8b6562038
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,386 @@@
++// InflaterInputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++\r
++using ICSharpCode.SharpZipLib.Zip.Compression;\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams \r
++{\r
++      \r
++      /// <summary>\r
++      /// This filter stream is used to decompress data compressed baseInputStream the "deflate"\r
++      /// format. The "deflate" format is described baseInputStream RFC 1951.\r
++      ///\r
++      /// This stream may form the basis for other decompression filters, such\r
++      /// as the <code>GzipInputStream</code>.\r
++      ///\r
++      /// author of the original java version : John Leuner\r
++      /// </summary>\r
++      public class InflaterInputStream : Stream\r
++      {\r
++              //Variables\r
++              \r
++              /// <summary>\r
++              /// Decompressor for this filter\r
++              /// </summary>\r
++              protected Inflater inf;\r
++              \r
++              /// <summary>\r
++              /// Byte array used as a buffer\r
++              /// </summary>\r
++              protected byte[] buf;\r
++              \r
++              /// <summary>\r
++              /// Size of buffer\r
++              /// </summary>\r
++              protected int len;\r
++              \r
++              //We just use this if we are decoding one byte at a time with the read() call\r
++              private byte[] onebytebuffer = new byte[1];\r
++              \r
++              /// <summary>\r
++              /// base stream the inflater depends on.\r
++              /// </summary>\r
++              protected Stream baseInputStream;\r
++              \r
++              protected long csize;\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanRead {\r
++                      get {\r
++                              return baseInputStream.CanRead;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanSeek {\r
++                      get {\r
++                              return false;\r
++                              //                              return baseInputStream.CanSeek;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override bool CanWrite {\r
++                      get {\r
++                              return baseInputStream.CanWrite;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Length {\r
++                      get {\r
++                              return len;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Position {\r
++                      get {\r
++                              return baseInputStream.Position;\r
++                      }\r
++                      set {\r
++                              baseInputStream.Position = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Flushes the baseInputStream\r
++              /// </summary>\r
++              public override void Flush()\r
++              {\r
++                      baseInputStream.Flush();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override long Seek(long offset, SeekOrigin origin)\r
++              {\r
++                      throw new NotSupportedException("Seek not supported"); // -jr- 01-Dec-2003\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void SetLength(long val)\r
++              {\r
++                      baseInputStream.SetLength(val);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void Write(byte[] array, int offset, int count)\r
++              {\r
++                      baseInputStream.Write(array, offset, count);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// I needed to implement the abstract member.\r
++              /// </summary>\r
++              public override void WriteByte(byte val)\r
++              {\r
++                      baseInputStream.WriteByte(val);\r
++              }\r
++              \r
++              // -jr- 01-Dec-2003 This may be flawed for some base streams?  Depends on implementation of BeginWrite\r
++              public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)\r
++              {\r
++                      throw new NotSupportedException("Asynch write not currently supported");\r
++              }\r
++              \r
++              //Constructors\r
++              \r
++              /// <summary>\r
++              /// Create an InflaterInputStream with the default decompresseor\r
++              /// and a default buffer size.\r
++              /// </summary>\r
++              /// <param name = "baseInputStream">\r
++              /// the InputStream to read bytes from\r
++              /// </param>\r
++              public InflaterInputStream(Stream baseInputStream) : this(baseInputStream, new Inflater(), 4096)\r
++              {\r
++                      \r
++              }\r
++              \r
++              /// <summary>\r
++              /// Create an InflaterInputStream with the specified decompresseor\r
++              /// and a default buffer size.\r
++              /// </summary>\r
++              /// <param name = "baseInputStream">\r
++              /// the InputStream to read bytes from\r
++              /// </param>\r
++              /// <param name = "inf">\r
++              /// the decompressor used to decompress data read from baseInputStream\r
++              /// </param>\r
++              public InflaterInputStream(Stream baseInputStream, Inflater inf) : this(baseInputStream, inf, 4096)\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Create an InflaterInputStream with the specified decompresseor\r
++              /// and a specified buffer size.\r
++              /// </summary>\r
++              /// <param name = "baseInputStream">\r
++              /// the InputStream to read bytes from\r
++              /// </param>\r
++              /// <param name = "inf">\r
++              /// the decompressor used to decompress data read from baseInputStream\r
++              /// </param>\r
++              /// <param name = "size">\r
++              /// size of the buffer to use\r
++              /// </param>\r
++              public InflaterInputStream(Stream baseInputStream, Inflater inf, int size)\r
++              {\r
++                      this.baseInputStream = baseInputStream;\r
++                      this.inf = inf;\r
++                      try {\r
++                              this.len = (int)baseInputStream.Length;\r
++                      } catch (Exception) {\r
++                              // the stream may not support .Length\r
++                              this.len = 0;\r
++                      }\r
++                      \r
++                      if (size <= 0) {\r
++                              throw new ArgumentOutOfRangeException("size <= 0");\r
++                      }\r
++                      \r
++                      buf = new byte[size]; //Create the buffer\r
++              }\r
++              \r
++              //Methods\r
++              \r
++              /// <summary>\r
++              /// Returns 0 once the end of the stream (EOF) has been reached.\r
++              /// Otherwise returns 1.\r
++              /// </summary>\r
++              public virtual int Available {\r
++                      get {\r
++                              return inf.IsFinished ? 0 : 1;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Closes the input stream\r
++              /// </summary>\r
++              public override void Close()\r
++              {\r
++                      baseInputStream.Close();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Fills the buffer with more data to decompress.\r
++              /// </summary>\r
++              protected void Fill()\r
++              {\r
++                      len = baseInputStream.Read(buf, 0, buf.Length);\r
++                      // decrypting crypted data\r
++                      if (cryptbuffer != null) {\r
++                              DecryptBlock(buf, 0, System.Math.Min((int)(csize - inf.TotalIn), buf.Length));\r
++                      }\r
++                      \r
++                      if (len <= 0) {\r
++                              throw new ApplicationException("Deflated stream ends early.");\r
++                      }\r
++                      inf.SetInput(buf, 0, len);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Reads one byte of decompressed data.\r
++              ///\r
++              /// The byte is baseInputStream the lower 8 bits of the int.\r
++              /// </summary>\r
++              public override int ReadByte()\r
++              {\r
++                      int nread = Read(onebytebuffer, 0, 1); //read one byte\r
++                      if (nread > 0) {\r
++                              return onebytebuffer[0] & 0xff;\r
++                      }\r
++                      return -1; // ok\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Decompresses data into the byte array\r
++              /// </summary>\r
++              /// <param name ="b">\r
++              /// the array to read and decompress data into\r
++              /// </param>\r
++              /// <param name ="off">\r
++              /// the offset indicating where the data should be placed\r
++              /// </param>\r
++              /// <param name ="len">\r
++              /// the number of bytes to decompress\r
++              /// </param>\r
++              public override int Read(byte[] b, int off, int len)\r
++              {\r
++                      for (;;) {\r
++                              int count;\r
++                              try {\r
++                                      count = inf.Inflate(b, off, len);\r
++                              } catch (Exception e) {\r
++                                      throw new ZipException(e.ToString());\r
++                              }\r
++                              \r
++                              if (count > 0) {\r
++                                      return count;\r
++                              }\r
++                              \r
++                              if (inf.IsNeedingDictionary) {\r
++                                      throw new ZipException("Need a dictionary");\r
++                              } else if (inf.IsFinished) {\r
++                                      return 0;\r
++                              } else if (inf.IsNeedingInput) {\r
++                                      Fill();\r
++                              } else {\r
++                                      throw new InvalidOperationException("Don't know what to do");\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Skip specified number of bytes of uncompressed data\r
++              /// </summary>\r
++              /// <param name ="n">\r
++              /// number of bytes to skip\r
++              /// </param>\r
++              public long Skip(long n)\r
++              {\r
++                      if (n < 0) {\r
++                              throw new ArgumentOutOfRangeException("n");\r
++                      }\r
++                      int len = 2048;\r
++                      if (n < len) {\r
++                              len = (int) n;\r
++                      }\r
++                      byte[] tmp = new byte[len];\r
++                      return (long)baseInputStream.Read(tmp, 0, tmp.Length);\r
++              }\r
++              \r
++              #region Encryption stuff\r
++              protected byte[] cryptbuffer = null;\r
++              \r
++              uint[] keys = null;\r
++              protected byte DecryptByte()\r
++              {\r
++                      uint temp = ((keys[2] & 0xFFFF) | 2);\r
++                      return (byte)((temp * (temp ^ 1)) >> 8);\r
++              }\r
++              \r
++              protected void DecryptBlock(byte[] buf, int off, int len)\r
++              {\r
++                      for (int i = off; i < off + len; ++i) {\r
++                              buf[i] ^= DecryptByte();\r
++                              UpdateKeys(buf[i]);\r
++                      }\r
++              }\r
++              \r
++              protected void InitializePassword(string password)\r
++              {\r
++                      keys = new uint[] {\r
++                              0x12345678,\r
++                              0x23456789,\r
++                              0x34567890\r
++                      };\r
++                      for (int i = 0; i < password.Length; ++i) {\r
++                              UpdateKeys((byte)password[i]);\r
++                      }\r
++              }\r
++              \r
++              protected void UpdateKeys(byte ch)\r
++              {\r
++                      keys[0] = Crc32.ComputeCrc32(keys[0], ch);\r
++                      keys[1] = keys[1] + (byte)keys[0];\r
++                      keys[1] = keys[1] * 134775813 + 1;\r
++                      keys[2] = Crc32.ComputeCrc32(keys[2], (byte)(keys[1] >> 24));\r
++              }\r
++              #endregion\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..426c1f752d31cc53d3cff29b3ce60a5f82b8b600
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,176 @@@
++// OutputWindow.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams \r
++{\r
++      \r
++      /// <summary>\r
++      /// Contains the output from the Inflation process.\r
++      /// We need to have a window so that we can refer backwards into the output stream\r
++      /// to repeat stuff.\r
++      ///\r
++      /// author of the original java version : John Leuner\r
++      /// </summary>\r
++      public class OutputWindow\r
++      {\r
++              private static int WINDOW_SIZE = 1 << 15;\r
++              private static int WINDOW_MASK = WINDOW_SIZE - 1;\r
++              \r
++              private byte[] window = new byte[WINDOW_SIZE]; //The window is 2^15 bytes\r
++              private int windowEnd  = 0;\r
++              private int windowFilled = 0;\r
++              \r
++              public void Write(int abyte)\r
++              {\r
++                      if (windowFilled++ == WINDOW_SIZE) {\r
++                              throw new InvalidOperationException("Window full");\r
++                      }\r
++                      window[windowEnd++] = (byte) abyte;\r
++                      windowEnd &= WINDOW_MASK;\r
++              }\r
++              \r
++              \r
++              private void SlowRepeat(int repStart, int len, int dist)\r
++              {\r
++                      while (len-- > 0) {\r
++                              window[windowEnd++] = window[repStart++];\r
++                              windowEnd &= WINDOW_MASK;\r
++                              repStart &= WINDOW_MASK;\r
++                      }\r
++              }\r
++              \r
++              public void Repeat(int len, int dist)\r
++              {\r
++                      if ((windowFilled += len) > WINDOW_SIZE) {\r
++                              throw new InvalidOperationException("Window full");\r
++                      }\r
++                      \r
++                      int rep_start = (windowEnd - dist) & WINDOW_MASK;\r
++                      int border = WINDOW_SIZE - len;\r
++                      if (rep_start <= border && windowEnd < border) {\r
++                              if (len <= dist) {\r
++                                      System.Array.Copy(window, rep_start, window, windowEnd, len);\r
++                                      windowEnd += len;\r
++                              } else {\r
++                                      /* We have to copy manually, since the repeat pattern overlaps.\r
++                                      */\r
++                                      while (len-- > 0) {\r
++                                              window[windowEnd++] = window[rep_start++];\r
++                                      }\r
++                              }\r
++                      } else {\r
++                              SlowRepeat(rep_start, len, dist);\r
++                      }\r
++              }\r
++              \r
++              public int CopyStored(StreamManipulator input, int len)\r
++              {\r
++                      len = Math.Min(Math.Min(len, WINDOW_SIZE - windowFilled), input.AvailableBytes);\r
++                      int copied;\r
++                      \r
++                      int tailLen = WINDOW_SIZE - windowEnd;\r
++                      if (len > tailLen) {\r
++                              copied = input.CopyBytes(window, windowEnd, tailLen);\r
++                              if (copied == tailLen) {\r
++                                      copied += input.CopyBytes(window, 0, len - tailLen);\r
++                              }\r
++                      } else {\r
++                              copied = input.CopyBytes(window, windowEnd, len);\r
++                      }\r
++                      \r
++                      windowEnd = (windowEnd + copied) & WINDOW_MASK;\r
++                      windowFilled += copied;\r
++                      return copied;\r
++              }\r
++              \r
++              public void CopyDict(byte[] dict, int offset, int len)\r
++              {\r
++                      if (windowFilled > 0) {\r
++                              throw new InvalidOperationException();\r
++                      }\r
++                      \r
++                      if (len > WINDOW_SIZE) {\r
++                              offset += len - WINDOW_SIZE;\r
++                              len = WINDOW_SIZE;\r
++                      }\r
++                      System.Array.Copy(dict, offset, window, 0, len);\r
++                      windowEnd = len & WINDOW_MASK;\r
++              }\r
++              \r
++              public int GetFreeSpace()\r
++              {\r
++                      return WINDOW_SIZE - windowFilled;\r
++              }\r
++              \r
++              public int GetAvailable()\r
++              {\r
++                      return windowFilled;\r
++              }\r
++              \r
++              public int CopyOutput(byte[] output, int offset, int len)\r
++              {\r
++                      int copy_end = windowEnd;\r
++                      if (len > windowFilled) {\r
++                              len = windowFilled;\r
++                      } else {\r
++                              copy_end = (windowEnd - windowFilled + len) & WINDOW_MASK;\r
++                      }\r
++                      \r
++                      int copied = len;\r
++                      int tailLen = len - copy_end;\r
++                      \r
++                      if (tailLen > 0) {\r
++                              System.Array.Copy(window, WINDOW_SIZE - tailLen, output, offset, tailLen);\r
++                              offset += tailLen;\r
++                              len = copy_end;\r
++                      }\r
++                      System.Array.Copy(window, copy_end - len, output, offset, len);\r
++                      windowFilled -= copied;\r
++                      if (windowFilled < 0) {\r
++                              throw new InvalidOperationException();\r
++                      }\r
++                      return copied;\r
++              }\r
++              \r
++              public void Reset()\r
++              {\r
++                      windowFilled = windowEnd = 0;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..35f98cc4f769860a563bc002ae7fb2e03259787a
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,245 @@@
++// StreamManipulator.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class allows us to retrieve a specified amount of bits from\r
++      /// the input buffer, as well as copy big byte blocks.\r
++      ///\r
++      /// It uses an int buffer to store up to 31 bits for direct\r
++      /// manipulation.  This guarantees that we can get at least 16 bits,\r
++      /// but we only need at most 15, so this is all safe.\r
++      ///\r
++      /// There are some optimizations in this class, for example, you must\r
++      /// never peek more then 8 bits more than needed, and you must first\r
++      /// peek bits before you may drop them.  This is not a general purpose\r
++      /// class but optimized for the behaviour of the Inflater.\r
++      ///\r
++      /// authors of the original java version : John Leuner, Jochen Hoenicke\r
++      /// </summary>\r
++      public class StreamManipulator\r
++      {\r
++              private byte[] window;\r
++              private int window_start = 0;\r
++              private int window_end = 0;\r
++              \r
++              private uint buffer = 0;\r
++              private int bits_in_buffer = 0;\r
++              \r
++              /// <summary>\r
++              /// Get the next n bits but don't increase input pointer.  n must be\r
++              /// less or equal 16 and if you if this call succeeds, you must drop\r
++              /// at least n-8 bits in the next call.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the value of the bits, or -1 if not enough bits available.  */\r
++              /// </returns>\r
++              public int PeekBits(int n)\r
++              {\r
++                      if (bits_in_buffer < n) {\r
++                              if (window_start == window_end) {\r
++                                      return -1; // ok\r
++                              }\r
++                              buffer |= (uint)((window[window_start++] & 0xff |\r
++                                               (window[window_start++] & 0xff) << 8) << bits_in_buffer);\r
++                              bits_in_buffer += 16;\r
++                      }\r
++                      return (int)(buffer & ((1 << n) - 1));\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Drops the next n bits from the input.  You should have called peekBits\r
++              /// with a bigger or equal n before, to make sure that enough bits are in\r
++              /// the bit buffer.\r
++              /// </summary>\r
++              public void DropBits(int n)\r
++              {\r
++                      buffer >>= n;\r
++                      bits_in_buffer -= n;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the next n bits and increases input pointer.  This is equivalent\r
++              /// to peekBits followed by dropBits, except for correct error handling.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the value of the bits, or -1 if not enough bits available.\r
++              /// </returns>\r
++              public int GetBits(int n)\r
++              {\r
++                      int bits = PeekBits(n);\r
++                      if (bits >= 0) {\r
++                              DropBits(n);\r
++                      }\r
++                      return bits;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the number of bits available in the bit buffer.  This must be\r
++              /// only called when a previous peekBits() returned -1.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the number of bits available.\r
++              /// </returns>\r
++              public int AvailableBits {\r
++                      get {\r
++                              return bits_in_buffer;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the number of bytes available.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the number of bytes available.\r
++              /// </returns>\r
++              public int AvailableBytes {\r
++                      get {\r
++                              return window_end - window_start + (bits_in_buffer >> 3);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Skips to the next byte boundary.\r
++              /// </summary>\r
++              public void SkipToByteBoundary()\r
++              {\r
++                      buffer >>= (bits_in_buffer & 7);\r
++                      bits_in_buffer &= ~7;\r
++              }\r
++              \r
++              public bool IsNeedingInput {\r
++                      get {\r
++                              return window_start == window_end;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Copies length bytes from input buffer to output buffer starting\r
++              /// at output[offset].  You have to make sure, that the buffer is\r
++              /// byte aligned.  If not enough bytes are available, copies fewer\r
++              /// bytes.\r
++              /// </summary>\r
++              /// <param name="output">\r
++              /// the buffer.\r
++              /// </param>\r
++              /// <param name="offset">\r
++              /// the offset in the buffer.\r
++              /// </param>\r
++              /// <param name="length">\r
++              /// the length to copy, 0 is allowed.\r
++              /// </param>\r
++              /// <returns>\r
++              /// the number of bytes copied, 0 if no byte is available.\r
++              /// </returns>\r
++              public int CopyBytes(byte[] output, int offset, int length)\r
++              {\r
++                      if (length < 0) {\r
++                              throw new ArgumentOutOfRangeException("length negative");\r
++                      }\r
++                      if ((bits_in_buffer & 7) != 0) {\r
++                              /* bits_in_buffer may only be 0 or 8 */\r
++                              throw new InvalidOperationException("Bit buffer is not aligned!");\r
++                      }\r
++                      \r
++                      int count = 0;\r
++                      while (bits_in_buffer > 0 && length > 0) {\r
++                              output[offset++] = (byte) buffer;\r
++                              buffer >>= 8;\r
++                              bits_in_buffer -= 8;\r
++                              length--;\r
++                              count++;\r
++                      }\r
++                      if (length == 0) {\r
++                              return count;\r
++                      }\r
++                      \r
++                      int avail = window_end - window_start;\r
++                      if (length > avail) {\r
++                              length = avail;\r
++                      }\r
++                      System.Array.Copy(window, window_start, output, offset, length);\r
++                      window_start += length;\r
++                      \r
++                      if (((window_start - window_end) & 1) != 0) {\r
++                              /* We always want an even number of bytes in input, see peekBits */\r
++                              buffer = (uint)(window[window_start++] & 0xff);\r
++                              bits_in_buffer = 8;\r
++                      }\r
++                      return count + length;\r
++              }\r
++              \r
++              public StreamManipulator()\r
++              {\r
++              }\r
++              \r
++              public void Reset()\r
++              {\r
++                      buffer = (uint)(window_start = window_end = bits_in_buffer = 0);\r
++              }\r
++              \r
++              public void SetInput(byte[] buf, int off, int len)\r
++              {\r
++                      if (window_start < window_end) {\r
++                              throw new InvalidOperationException("Old input was not completely processed");\r
++                      }\r
++                      \r
++                      int end = off + len;\r
++                      \r
++                      /* We want to throw an ArrayIndexOutOfBoundsException early.  The\r
++                      * check is very tricky: it also handles integer wrap around.\r
++                      */\r
++                      if (0 > off || off > end || end > buf.Length) {\r
++                              throw new ArgumentOutOfRangeException();\r
++                      }\r
++                      \r
++                      if ((len & 1) != 0) {\r
++                              /* We always want an even number of bytes in input, see peekBits */\r
++                              buffer |= (uint)((buf[off++] & 0xff) << bits_in_buffer);\r
++                              bits_in_buffer += 8;\r
++                      }\r
++                      \r
++                      window = buf;\r
++                      window_start = off;\r
++                      window_end = end;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..8a56d71d7083a8d45d498f3078f9301f9485311a
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,146 @@@
++// ZipConstants.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System.Text;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class contains constants used for zip.\r
++      /// </summary>\r
++      public sealed class ZipConstants\r
++      {\r
++              /* The local file header */\r
++              public const int LOCHDR = 30;\r
++              public const int LOCSIG = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);\r
++              \r
++              public const int LOCVER =  4;\r
++              public const int LOCFLG =  6;\r
++              public const int LOCHOW =  8;\r
++              public const int LOCTIM = 10;\r
++              public const int LOCCRC = 14;\r
++              public const int LOCSIZ = 18;\r
++              public const int LOCLEN = 22;\r
++              public const int LOCNAM = 26;\r
++              public const int LOCEXT = 28;\r
++              \r
++              public const int SPANNINGSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);\r
++              public const int SPANTEMPSIG = 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);\r
++              \r
++              /* The Data descriptor */\r
++              public const int EXTSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24);\r
++              public const int EXTHDR = 16;\r
++              \r
++              public const int EXTCRC =  4;\r
++              public const int EXTSIZ =  8;\r
++              public const int EXTLEN = 12;\r
++              \r
++              /* The central directory file header */\r
++              public const int CENSIG = 'P' | ('K' << 8) | (1 << 16) | (2 << 24);\r
++              \r
++              /* The central directory file header for 64bit ZIP*/\r
++              public const int CENSIG64 = 'P' | ('K' << 8) | (6 << 16) | (6 << 24);\r
++              \r
++              public const int CENHDR = 46;\r
++              \r
++              public const int CENVEM =  4;\r
++              public const int CENVER =  6;\r
++              public const int CENFLG =  8;\r
++              public const int CENHOW = 10;\r
++              public const int CENTIM = 12;\r
++              public const int CENCRC = 16;\r
++              public const int CENSIZ = 20;\r
++              public const int CENLEN = 24;\r
++              public const int CENNAM = 28;\r
++              public const int CENEXT = 30;\r
++              public const int CENCOM = 32;\r
++              public const int CENDSK = 34;\r
++              public const int CENATT = 36;\r
++              public const int CENATX = 38;\r
++              public const int CENOFF = 42;\r
++              \r
++              /* The entries in the end of central directory */\r
++              public const int ENDSIG = 'P' | ('K' << 8) | (5 << 16) | (6 << 24);\r
++              public const int ENDHDR = 22;\r
++              \r
++              public const int HDRDIGITALSIG = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);\r
++              public const int CENDIGITALSIG = 'P' | ('K' << 8) | (5 << 16) | (5 << 24);\r
++              \r
++              /* The following two fields are missing in SUN JDK */\r
++              public const int ENDNRD =  4;\r
++              public const int ENDDCD =  6;\r
++              \r
++              public const int ENDSUB =  8;\r
++              public const int ENDTOT = 10;\r
++              public const int ENDSIZ = 12;\r
++              public const int ENDOFF = 16;\r
++              public const int ENDCOM = 20;\r
++              \r
++              \r
++              static int defaultCodePage = 0;  // 0 gives default code page, set it to whatever you like or alternatively alter it via property at runtime for more flexibility\r
++                                               // Some care for compatability purposes is required as you can specify unicode code pages here.... if this way of working seems ok\r
++                                               // then some protection may be added to make the interface a bit more robust perhaps.\r
++              \r
++              public static int DefaultCodePage {\r
++                      get {\r
++                              return defaultCodePage; \r
++                      }\r
++                      set {\r
++                              defaultCodePage = value; \r
++                      }\r
++              }\r
++              \r
++              public static string ConvertToString(byte[] data)\r
++              {\r
++#if COMACT_FRAMEWORK                  \r
++                      return Encoding.ASCII.GetString(data,0, data.Length);\r
++#else\r
++                      return Encoding.GetEncoding(DefaultCodePage).GetString(data, 0, data.Length);\r
++#endif\r
++              }\r
++              \r
++              public static byte[] ConvertToArray(string str)\r
++              {\r
++#if COMACT_FRAMEWORK                  \r
++                      return Encoding.ASCII.GetBytes(str);\r
++#else\r
++                      return Encoding.GetEncoding(DefaultCodePage).GetBytes(str);\r
++#endif\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..1cb65df10a5ec8bf189a4a7a5a04d861e2d4454c
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,428 @@@
++// ZipEntry.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip \r
++{\r
++      \r
++      public enum CompressionMethod\r
++      {\r
++              Stored   = 0,\r
++              Deflated = 8,\r
++      }\r
++      \r
++      /// <summary>\r
++      /// This class represents a member of a zip archive.  ZipFile and\r
++      /// ZipInputStream will give you instances of this class as information\r
++      /// about the members in an archive.  On the other hand ZipOutputStream\r
++      /// needs an instance of this class to create a new member.\r
++      ///\r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      public class ZipEntry : ICloneable\r
++      {\r
++              static int KNOWN_SIZE   = 1;\r
++              static int KNOWN_CSIZE  = 2;\r
++              static int KNOWN_CRC    = 4;\r
++              static int KNOWN_TIME   = 8;\r
++              \r
++              string name;\r
++              uint   size;\r
++              ushort version;\r
++              uint   compressedSize;\r
++              uint   crc;\r
++              uint   dosTime;\r
++              \r
++              ushort known = 0;\r
++              CompressionMethod  method = CompressionMethod.Deflated;\r
++              byte[] extra = null;\r
++              string comment = null;\r
++              bool   isCrypted;\r
++              \r
++              int zipFileIndex = -1;  /* used by ZipFile */\r
++              int flags;              /* used by ZipOutputStream */\r
++              int offset;             /* used by ZipFile and ZipOutputStream */\r
++              \r
++              public bool IsEncrypted {\r
++                      get {\r
++                              return (flags & 1) != 0; \r
++                      }\r
++                      set {\r
++                              if (value) {\r
++                                      flags |= 1;\r
++                              } else {\r
++                                      flags &= ~1;\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              public int ZipFileIndex {\r
++                      get {\r
++                              return zipFileIndex;\r
++                      }\r
++                      set {\r
++                              zipFileIndex = value;\r
++                      }\r
++              }\r
++              \r
++              public int Offset {\r
++                      get {\r
++                              return offset;\r
++                      }\r
++                      set {\r
++                              offset = value;\r
++                      }\r
++              }\r
++              \r
++              public int Flags {                                // Stops having two things represent same concept in class (flag isCrypted removed)\r
++                      get { \r
++                              return flags; \r
++                      }\r
++                      set {\r
++                              flags = value; \r
++                      }\r
++              }\r
++              \r
++              \r
++              /// <summary>\r
++              /// Creates a zip entry with the given name.\r
++              /// </summary>\r
++              /// <param name="name">\r
++              /// the name. May include directory components separated by '/'.\r
++              /// </param>\r
++              public ZipEntry(string name)\r
++              {\r
++                      if (name == null)  {\r
++                              throw new System.ArgumentNullException("name");\r
++                      }\r
++                      this.DateTime  = System.DateTime.Now;\r
++                      this.name = name;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a copy of the given zip entry.\r
++              /// </summary>\r
++              /// <param name="e">\r
++              /// the entry to copy.\r
++              /// </param>\r
++              public ZipEntry(ZipEntry e)\r
++              {\r
++                      name           = e.name;\r
++                      known          = e.known;\r
++                      size           = e.size;\r
++                      compressedSize = e.compressedSize;\r
++                      crc            = e.crc;\r
++                      dosTime        = e.dosTime;\r
++                      method         = e.method;\r
++                      extra          = e.extra;\r
++                      comment        = e.comment;\r
++              }\r
++              \r
++              public int Version {\r
++                      get {\r
++                              return version;\r
++                      }\r
++                      set {\r
++                              version = (ushort)value;\r
++                      }\r
++              }\r
++              \r
++              public long DosTime {\r
++                      get {\r
++                              if ((known & KNOWN_TIME) == 0) {\r
++                                      return 0;\r
++                              } else {\r
++                                      return dosTime;\r
++                              }\r
++                      }\r
++                      set {\r
++                              this.dosTime = (uint)value;\r
++                              known |= (ushort)KNOWN_TIME;\r
++                      }\r
++              }\r
++              \r
++              \r
++              /// <summary>\r
++              /// Gets/Sets the time of last modification of the entry.\r
++              /// </summary>\r
++              public DateTime DateTime {\r
++                      get {\r
++                              uint sec  = 2 * (dosTime & 0x1f);\r
++                              uint min  = (dosTime >> 5) & 0x3f;\r
++                              uint hrs  = (dosTime >> 11) & 0x1f;\r
++                              uint day  = (dosTime >> 16) & 0x1f;\r
++                              uint mon  = ((dosTime >> 21) & 0xf);\r
++                              uint year = ((dosTime >> 25) & 0x7f) + 1980; /* since 1900 */\r
++                              return new System.DateTime((int)year, (int)mon, (int)day, (int)hrs, (int)min, (int)sec);\r
++                      }\r
++                      set {\r
++                              DosTime = ((uint)value.Year - 1980 & 0x7f) << 25 | \r
++                                        ((uint)value.Month) << 21 |\r
++                                        ((uint)value.Day) << 16 |\r
++                                        ((uint)value.Hour) << 11 |\r
++                                        ((uint)value.Minute) << 5 |\r
++                                        ((uint)value.Second) >> 1;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns the entry name.  The path components in the entry are\r
++              /// always separated by slashes ('/').\r
++              /// </summary>\r
++              public string Name {\r
++                      get {\r
++                              return name;\r
++                      }\r
++              }\r
++              \r
++              //              /// <summary>\r
++              //              /// Gets/Sets the time of last modification of the entry.\r
++              //              /// </summary>\r
++              //              /// <returns>\r
++              //              /// the time of last modification of the entry, or -1 if unknown.\r
++              //              /// </returns>\r
++              //              public long Time {\r
++              //                      get {\r
++              //                              return (known & KNOWN_TIME) != 0 ? time * 1000L : -1;\r
++              //                      }\r
++              //                      set {\r
++              //                              this.time = (int) (value / 1000L);\r
++              //                              this.known |= (ushort)KNOWN_TIME;\r
++              //                      }\r
++              //              }\r
++              \r
++              /// <summary>\r
++              /// Gets/Sets the size of the uncompressed data.\r
++              /// </summary>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if size is not in 0..0xffffffffL\r
++              /// </exception>\r
++              /// <returns>\r
++              /// the size or -1 if unknown.\r
++              /// </returns>\r
++              public long Size {\r
++                      get {\r
++                              return (known & KNOWN_SIZE) != 0 ? (long)size : -1L;\r
++                      }\r
++                      set  {\r
++                              if (((ulong)value & 0xFFFFFFFF00000000L) != 0) {\r
++                                      throw new ArgumentOutOfRangeException("size");\r
++                              }\r
++                              this.size  = (uint)value;\r
++                              this.known |= (ushort)KNOWN_SIZE;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets/Sets the size of the compressed data.\r
++              /// </summary>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if csize is not in 0..0xffffffffL\r
++              /// </exception>\r
++              /// <returns>\r
++              /// the size or -1 if unknown.\r
++              /// </returns>\r
++              public long CompressedSize {\r
++                      get {\r
++                              return (known & KNOWN_CSIZE) != 0 ? (long)compressedSize : -1L;\r
++                      }\r
++                      set {\r
++                              if (((ulong)value & 0xffffffff00000000L) != 0) {\r
++                                      throw new ArgumentOutOfRangeException();\r
++                              }\r
++                              this.compressedSize = (uint)value;\r
++                              this.known |= (ushort)KNOWN_CSIZE;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets/Sets the crc of the uncompressed data.\r
++              /// </summary>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if crc is not in 0..0xffffffffL\r
++              /// </exception>\r
++              /// <returns>\r
++              /// the crc or -1 if unknown.\r
++              /// </returns>\r
++              public long Crc {\r
++                      get {\r
++                              return (known & KNOWN_CRC) != 0 ? crc & 0xffffffffL : -1L;\r
++                      }\r
++                      set {\r
++                              if (((ulong)crc & 0xffffffff00000000L) != 0) \r
++                              {\r
++                                      throw new Exception();\r
++                              }\r
++                              this.crc = (uint)value;\r
++                              this.known |= (ushort)KNOWN_CRC;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets/Sets the compression method. Only DEFLATED and STORED are supported.\r
++              /// </summary>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if method is not supported.\r
++              /// </exception>\r
++              /// <returns>\r
++              /// the compression method or -1 if unknown.\r
++              /// </returns>\r
++              /// <see cref="ZipOutputStream.DEFLATED"/>\r
++              /// <see cref="ZipOutputStream.STORED"/>\r
++              public CompressionMethod CompressionMethod {\r
++                      get {\r
++                              return method;\r
++                      }\r
++                      set {\r
++                              this.method = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets/Sets the extra data.\r
++              /// </summary>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if extra is longer than 0xffff bytes.\r
++              /// </exception>\r
++              /// <returns>\r
++              /// the extra data or null if not set.\r
++              /// </returns>\r
++              public byte[] ExtraData {\r
++                      get {\r
++                              return extra;\r
++                      }\r
++                      set {\r
++                              if (value == null) {\r
++                                      this.extra = null;\r
++                                      return;\r
++                              }\r
++                              \r
++                              if (value.Length > 0xffff) {\r
++                                      throw new System.ArgumentOutOfRangeException();\r
++                              }\r
++                              this.extra = value;\r
++                              try {\r
++                                      int pos = 0;\r
++                                      while (pos < extra.Length) {\r
++                                              int sig = (extra[pos++] & 0xff) | (extra[pos++] & 0xff) << 8;\r
++                                              int len = (extra[pos++] & 0xff) | (extra[pos++] & 0xff) << 8;\r
++                                              if (sig == 0x5455) {\r
++                                                      /* extended time stamp, unix format by Rainer Prem <Rainer@Prem.de> */\r
++                                                      int flags = extra[pos];\r
++                                                      if ((flags & 1) != 0) {\r
++                                                              int iTime = ((extra[pos+1] & 0xff) |\r
++                                                                      (extra[pos+2] & 0xff) << 8 |\r
++                                                                      (extra[pos+3] & 0xff) << 16 |\r
++                                                                      (extra[pos+4] & 0xff) << 24);\r
++                                                              \r
++                                                              DateTime = (new DateTime ( 1970, 1, 1, 0, 0, 0 ) + new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime ();\r
++                                                              known |= (ushort)KNOWN_TIME;\r
++                                                      }\r
++                                              }\r
++                                              pos += len;\r
++                                      }\r
++                              } catch (Exception) {\r
++                                      /* be lenient */\r
++                                      return;\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets/Sets the entry comment.\r
++              /// </summary>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if comment is longer than 0xffff.\r
++              /// </exception>\r
++              /// <returns>\r
++              /// the comment or null if not set.\r
++              /// </returns>\r
++              public string Comment {\r
++                      get {\r
++                              return comment;\r
++                      }\r
++                      set {\r
++                              if (value.Length > 0xffff) \r
++                              {\r
++                                      throw new ArgumentOutOfRangeException();\r
++                              }\r
++                              this.comment = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets true, if the entry is a directory.  This is solely\r
++              /// determined by the name, a trailing slash '/' marks a directory.\r
++              /// </summary>\r
++              public bool IsDirectory {\r
++                      get {\r
++                              int nlen = name.Length;\r
++                              return nlen > 0 && name[nlen - 1] == '/';\r
++                      }\r
++              }\r
++              \r
++              /// <value>\r
++              /// True, if the entry is encrypted.\r
++              /// </value>\r
++              public bool IsCrypted {\r
++                      get {\r
++                              return isCrypted;\r
++                      }\r
++                      set {\r
++                              isCrypted = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a copy of this zip entry.\r
++              /// </summary>\r
++              public object Clone()\r
++              {\r
++                      return this.MemberwiseClone();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Gets the string representation of this ZipEntry.  This is just\r
++              /// the name as returned by getName().\r
++              /// </summary>\r
++              public override string ToString()\r
++              {\r
++                      return name;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..3e3b2a18ef5988f756df63ccc48de4fc3974a37f
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,540 @@@
++// ZipFile.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.Collections;\r
++using System.IO;\r
++using System.Text;\r
++\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++using ICSharpCode.SharpZipLib.Zip.Compression;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip \r
++{\r
++      \r
++      /// <summary>\r
++      /// This class represents a Zip archive.  You can ask for the contained\r
++      /// entries, or get an input stream for a file entry.  The entry is\r
++      /// automatically decompressed.\r
++      /// \r
++      /// This class is thread safe:  You can open input streams for arbitrary\r
++      /// entries in different threads.\r
++      /// \r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      /// <example>\r
++      /// using System;\r
++      /// using System.Text;\r
++      /// using System.Collections;\r
++      /// using System.IO;\r
++      /// \r
++      /// using NZlib.Zip;\r
++      /// \r
++      /// class MainClass\r
++      /// {\r
++      ///     static public void Main(string[] args)\r
++      ///     {\r
++      ///             ZipFile zFile = new ZipFile(args[0]);\r
++      ///             //Console.WriteLine("Listing of : " + zFile.Name);\r
++      ///             //Console.WriteLine("");\r
++      ///             //Console.WriteLine("Raw Size    Size      Date     Time     Name");\r
++      ///             //Console.WriteLine("--------  --------  --------  ------  ---------");\r
++      ///             foreach (ZipEntry e in zFile) {\r
++      ///                     DateTime d = e.DateTime;\r
++      ///                     //Console.WriteLine("{0, -10}{1, -10}{2}  {3}   {4}", e.Size, e.CompressedSize,\r
++      ///                                                                         d.ToString("dd-MM-yy"), d.ToString("t"),\r
++      ///                                                                         e.Name);\r
++      ///             }\r
++      ///     }\r
++      /// }\r
++      /// </example>\r
++      public class ZipFile : IEnumerable\r
++      {\r
++              string     name;\r
++              string     comment;\r
++              Stream     baseStream;\r
++              ZipEntry[] entries;\r
++              \r
++              /// <summary>\r
++              /// Opens a Zip file with the given name for reading.\r
++              /// </summary>\r
++              /// <exception name="System.IO.IOException">\r
++              /// IOException if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="ICSharpCode.SharpZipLib.ZipException">\r
++              /// if the file doesn't contain a valid zip archive.\r
++              /// </exception>\r
++              public ZipFile(string name) : this(File.OpenRead(name))\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Opens a Zip file reading the given FileStream\r
++              /// </summary>\r
++              /// <exception name="System.IO.IOException">\r
++              /// IOException if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="ICSharpCode.SharpZipLib.ZipException">\r
++              /// if the file doesn't contain a valid zip archive.\r
++              /// </exception>\r
++              public ZipFile(FileStream file)\r
++              {\r
++                      this.baseStream  = file;\r
++                      this.name = file.Name;\r
++                      ReadEntries();\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Opens a Zip file reading the given Stream\r
++              /// </summary>\r
++              /// <exception name="System.IO.IOException">\r
++              /// IOException if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="ICSharpCode.SharpZipLib.ZipException">\r
++              /// if the file doesn't contain a valid zip archive.\r
++              /// </exception>\r
++              public ZipFile(Stream baseStream)\r
++              {\r
++                      this.baseStream  = baseStream;\r
++                      this.name = null;\r
++                      ReadEntries();\r
++              }\r
++              \r
++              \r
++              /// <summary>\r
++              /// Read an unsigned short in little endian byte order.\r
++              /// </summary>\r
++              /// <exception name="System.IO.IOException">\r
++              /// if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="System.IO.EndOfStreamException">\r
++              /// if the file ends prematurely\r
++              /// </exception>\r
++              int ReadLeShort()\r
++              {\r
++                      return baseStream.ReadByte() | baseStream.ReadByte() << 8;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Read an int in little endian byte order.\r
++              /// </summary>\r
++              /// <exception name="System.IO.IOException">\r
++              /// if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="System.IO.EndOfStreamException">\r
++              /// if the file ends prematurely\r
++              /// </exception>\r
++              int ReadLeInt()\r
++              {\r
++                      return ReadLeShort() | ReadLeShort() << 16;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Read the central directory of a zip file and fill the entries\r
++              /// array.  This is called exactly once by the constructors.\r
++              /// </summary>\r
++              /// <exception name="System.IO.IOException">\r
++              /// if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="ICSharpCode.SharpZipLib.ZipException">\r
++              /// if the central directory is malformed\r
++              /// </exception>\r
++              void ReadEntries()\r
++              {\r
++                      /* Search for the End Of Central Directory.  When a zip comment is\r
++                      * present the directory may start earlier.\r
++                      * FIXME: This searches the whole file in a very slow manner if the\r
++                      * file isn't a zip file.\r
++                      */\r
++                      long pos = baseStream.Length - ZipConstants.ENDHDR;\r
++                      do {\r
++                              if (pos < 0) {\r
++                                      throw new ZipException("central directory not found, probably not a zip file");\r
++                              }\r
++                              baseStream.Seek(pos--, SeekOrigin.Begin);\r
++                      } while (ReadLeInt() != ZipConstants.ENDSIG);\r
++                      \r
++                      long oldPos = baseStream.Position;\r
++                      baseStream.Position += ZipConstants.ENDTOT - ZipConstants.ENDNRD;\r
++                      \r
++                      if (baseStream.Position - oldPos != ZipConstants.ENDTOT - ZipConstants.ENDNRD) {\r
++                              throw new EndOfStreamException();\r
++                      }\r
++                      int count = ReadLeShort();\r
++                      \r
++                      oldPos = baseStream.Position;\r
++                      baseStream.Position += ZipConstants.ENDOFF - ZipConstants.ENDSIZ;\r
++                      \r
++                      if (baseStream.Position - oldPos != ZipConstants.ENDOFF - ZipConstants.ENDSIZ) {\r
++                              throw new EndOfStreamException();\r
++                      }\r
++                      \r
++                      int centralOffset = ReadLeInt();\r
++                      \r
++                      // GET COMMENT SIZE (COMES AFTER CENTRALOFFSET) \r
++                      int commentSize = ReadLeShort(); \r
++                      byte[] zipComment = new byte[commentSize]; \r
++                      baseStream.Read(zipComment, 0, zipComment.Length); \r
++                      comment = ZipConstants.ConvertToString(zipComment); \r
++                      \r
++                      entries = new ZipEntry[count];\r
++                      baseStream.Seek(centralOffset, SeekOrigin.Begin);\r
++                      for (int i = 0; i < count; i++) {\r
++                              if (ReadLeInt() != ZipConstants.CENSIG) {\r
++                                      throw new ZipException("Wrong Central Directory signature");\r
++                              }\r
++                              \r
++                              oldPos = baseStream.Position;\r
++                              baseStream.Position += ZipConstants.CENHOW - ZipConstants.CENVEM;\r
++                              \r
++                              if (baseStream.Position - oldPos != ZipConstants.CENHOW - ZipConstants.CENVEM) {\r
++                                      throw new EndOfStreamException();\r
++                              }\r
++                              int method = ReadLeShort();\r
++                              int dostime = ReadLeInt();\r
++                              int crc = ReadLeInt();\r
++                              int csize = ReadLeInt();\r
++                              int size = ReadLeInt();\r
++                              int nameLen = ReadLeShort();\r
++                              int extraLen = ReadLeShort();\r
++                              int commentLen = ReadLeShort();\r
++                              \r
++                              oldPos = baseStream.Position;\r
++                              baseStream.Position += ZipConstants.CENOFF - ZipConstants.CENDSK;\r
++                              if (baseStream.Position - oldPos != ZipConstants.CENOFF - ZipConstants.CENDSK) {\r
++                                      throw new EndOfStreamException();\r
++                              }\r
++                              int offset = ReadLeInt();\r
++                              \r
++                              byte[] buffer = new byte[Math.Max(nameLen, commentLen)];\r
++                              \r
++                              baseStream.Read(buffer, 0, nameLen);\r
++                              string name = ZipConstants.ConvertToString(buffer);\r
++                              \r
++                              ZipEntry entry = new ZipEntry(name);\r
++                              entry.CompressionMethod = (CompressionMethod)method;\r
++                              entry.Crc = crc & 0xffffffffL;\r
++                              entry.Size = size & 0xffffffffL;\r
++                              entry.CompressedSize = csize & 0xffffffffL;\r
++                              entry.DosTime = (uint)dostime;\r
++                              if (extraLen > 0) {\r
++                                      byte[] extra = new byte[extraLen];\r
++                                      baseStream.Read(extra, 0, extraLen);\r
++                                      entry.ExtraData = extra;\r
++                              }\r
++                              if (commentLen > 0) {\r
++                                      baseStream.Read(buffer, 0, commentLen);\r
++                                      entry.Comment = ZipConstants.ConvertToString(buffer);\r
++                              }\r
++                              entry.ZipFileIndex = i;\r
++                              entry.Offset = offset;\r
++                              entries[i] = entry;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Closes the ZipFile.  This also closes all input streams given by\r
++              /// this class.  After this is called, no further method should be\r
++              /// called.\r
++              /// </summary>\r
++              /// <exception name="System.IO.IOException">\r
++              /// if a i/o error occured.\r
++              /// </exception>\r
++              public void Close()\r
++              {\r
++                      entries = null;\r
++                      lock(baseStream) {\r
++                              baseStream.Close();\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns an IEnumerator of all Zip entries in this Zip file.\r
++              /// </summary>\r
++              public IEnumerator GetEnumerator()\r
++              {\r
++                      if (entries == null) {\r
++                              throw new InvalidOperationException("ZipFile has closed");\r
++                      }\r
++                      \r
++                      return new ZipEntryEnumeration(entries);\r
++              }\r
++              \r
++              int GetEntryIndex(string name)\r
++              {\r
++                      for (int i = 0; i < entries.Length; i++) {\r
++                              if (name.Equals(entries[i].Name)) {\r
++                                      return i;\r
++                              }\r
++                      }\r
++                      return -1; // ok\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Searches for a zip entry in this archive with the given name.\r
++              /// </summary>\r
++              /// <param name="name">\r
++              /// the name. May contain directory components separated by slashes ('/').\r
++              /// </param>\r
++              /// <returns>\r
++              /// the zip entry, or null if no entry with that name exists.\r
++              /// </returns>\r
++              public ZipEntry GetEntry(string name)\r
++              {\r
++                      if (entries == null) {\r
++                              throw new InvalidOperationException("ZipFile has closed");\r
++                      }\r
++                      int index = GetEntryIndex(name);\r
++                      return index >= 0 ? (ZipEntry) entries[index].Clone() : null;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Checks, if the local header of the entry at index i matches the\r
++              /// central directory, and returns the offset to the data.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the start offset of the (compressed) data.\r
++              /// </returns>\r
++              /// <exception name="System.IO.IOException">\r
++              /// if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="ICSharpCode.SharpZipLib.ZipException">\r
++              /// if the local header doesn't match the central directory header\r
++              /// </exception>\r
++              long CheckLocalHeader(ZipEntry entry)\r
++              {\r
++                      lock(baseStream) {\r
++                              baseStream.Seek(entry.Offset, SeekOrigin.Begin);\r
++                              if (ReadLeInt() != ZipConstants.LOCSIG) {\r
++                                      throw new ZipException("Wrong Local header signature");\r
++                              }\r
++                              \r
++                              /* skip version and flags */\r
++                              long oldPos = baseStream.Position;\r
++                              baseStream.Position += ZipConstants.LOCHOW - ZipConstants.LOCVER;\r
++                              if (baseStream.Position - oldPos != ZipConstants.LOCHOW - ZipConstants.LOCVER) {\r
++                                      throw new EndOfStreamException();\r
++                              }\r
++                              \r
++                              if (entry.CompressionMethod != (CompressionMethod)ReadLeShort()) {\r
++                                      throw new ZipException("Compression method mismatch");\r
++                              }\r
++                              \r
++                              /* Skip time, crc, size and csize */\r
++                              oldPos = baseStream.Position;\r
++                              baseStream.Position += ZipConstants.LOCNAM - ZipConstants.LOCTIM;\r
++                              \r
++                              if (baseStream.Position - oldPos != ZipConstants.LOCNAM - ZipConstants.LOCTIM) {\r
++                                      throw new EndOfStreamException();\r
++                              }\r
++                              \r
++                              if (entry.Name.Length != ReadLeShort()) {\r
++                                      throw new ZipException("file name length mismatch");\r
++                              }\r
++                              \r
++                              int extraLen = entry.Name.Length + ReadLeShort();\r
++                              return entry.Offset + ZipConstants.LOCHDR + extraLen;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates an input stream reading the given zip entry as\r
++              /// uncompressed data.  Normally zip entry should be an entry\r
++              /// returned by GetEntry().\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the input stream.\r
++              /// </returns>\r
++              /// <exception name="System.IO.IOException">\r
++              /// if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="ICSharpCode.SharpZipLib.ZipException">\r
++              /// if the Zip archive is malformed.\r
++              /// </exception>\r
++              public Stream GetInputStream(ZipEntry entry)\r
++              {\r
++                      if (entries == null) {\r
++                              throw new InvalidOperationException("ZipFile has closed");\r
++                      }\r
++                      \r
++                      int index = entry.ZipFileIndex;\r
++                      if (index < 0 || index >= entries.Length || entries[index].Name != entry.Name) {\r
++                              index = GetEntryIndex(entry.Name);\r
++                              if (index < 0) {\r
++                                      throw new IndexOutOfRangeException();\r
++                              }\r
++                      }\r
++                      \r
++                      long start = CheckLocalHeader(entries[index]);\r
++                      CompressionMethod method = entries[index].CompressionMethod;\r
++                      Stream istr = new PartialInputStream(baseStream, start, entries[index].CompressedSize);\r
++                      switch (method) {\r
++                              case CompressionMethod.Stored:\r
++                                      return istr;\r
++                              case CompressionMethod.Deflated:\r
++                                      return new InflaterInputStream(istr, new Inflater(true));\r
++                              default:\r
++                                      throw new ZipException("Unknown compression method " + method);\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// The comment for the whole zip file.\r
++              /// </summary>\r
++              public string ZipFileComment {\r
++                      get {\r
++                              return comment;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns the name of this zip file.\r
++              /// </summary>\r
++              public string Name {\r
++                      get {\r
++                              return name;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Returns the number of entries in this zip file.\r
++              /// </summary>\r
++              public int Size {\r
++                      get {\r
++                              try {\r
++                                      return entries.Length;\r
++                              } catch (Exception) {\r
++                                      throw new InvalidOperationException("ZipFile has closed");\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              class ZipEntryEnumeration : IEnumerator\r
++              {\r
++                      ZipEntry[] array;\r
++                      int ptr = -1;\r
++                      \r
++                      public ZipEntryEnumeration(ZipEntry[] arr)\r
++                      {\r
++                              array = arr;\r
++                      }\r
++                      \r
++                      public object Current {\r
++                              get {\r
++                                      return array[ptr];\r
++                              }\r
++                      }\r
++                      \r
++                      public void Reset()\r
++                      {\r
++                              ptr = -1;\r
++                      }\r
++                      \r
++                      public bool MoveNext() \r
++                      {\r
++                              return (++ptr < array.Length);\r
++                      }\r
++              }\r
++              \r
++              class PartialInputStream : InflaterInputStream\r
++              {\r
++                      Stream baseStream;\r
++                      long filepos, end;\r
++                      \r
++                      public PartialInputStream(Stream baseStream, long start, long len) : base(baseStream)\r
++                      {\r
++                              this.baseStream = baseStream;\r
++                              filepos = start;\r
++                              end = start + len;\r
++                      }\r
++                      \r
++                      public override int Available \r
++                      {\r
++                              get {\r
++                                      long amount = end - filepos;\r
++                                      if (amount > Int32.MaxValue) {\r
++                                              return Int32.MaxValue;\r
++                                      }\r
++                                      \r
++                                      return (int) amount;\r
++                              }\r
++                      }\r
++                      \r
++                      public override int ReadByte()\r
++                      {\r
++                              if (filepos == end) {\r
++                                      return -1; //ok\r
++                              }\r
++                              \r
++                              lock(baseStream) {\r
++                                      baseStream.Seek(filepos++, SeekOrigin.Begin);\r
++                                      return baseStream.ReadByte();\r
++                              }\r
++                      }\r
++                      \r
++                      public override int Read(byte[] b, int off, int len)\r
++                      {\r
++                              if (len > end - filepos) {\r
++                                      len = (int) (end - filepos);\r
++                                      if (len == 0) {\r
++                                              return 0;\r
++                                      }\r
++                              }\r
++                              lock(baseStream) {\r
++                                      baseStream.Seek(filepos, SeekOrigin.Begin);\r
++                                      int count = baseStream.Read(b, off, len);\r
++                                      if (count > 0) {\r
++                                              filepos += len;\r
++                                      }\r
++                                      return count;\r
++                              }\r
++                      }\r
++                      \r
++                      public long SkipBytes(long amount)\r
++                      {\r
++                              if (amount < 0) {\r
++                                      throw new ArgumentOutOfRangeException();\r
++                              }\r
++                              if (amount > end - filepos) {\r
++                                      amount = end - filepos;\r
++                              }\r
++                              filepos += amount;\r
++                              return amount;\r
++                      }\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..ceae24446727e60e030e3c81822e666b385618b9
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,488 @@@
++// ZipInputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.Text;\r
++using System.IO;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++using ICSharpCode.SharpZipLib.Zip.Compression;\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip \r
++{\r
++      /// <summary>\r
++      /// This is a FilterInputStream that reads the files baseInputStream an zip archive\r
++      /// one after another.  It has a special method to get the zip entry of\r
++      /// the next file.  The zip entry contains information about the file name\r
++      /// size, compressed size, CRC, etc.\r
++      /// It includes support for STORED and DEFLATED entries.\r
++      /// \r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      /// <example> This sample shows how to read a zip file\r
++      /// <code lang="C#">\r
++      /// using System;\r
++      /// using System.Text;\r
++      /// using System.IO;\r
++      /// \r
++      /// using NZlib.Zip;\r
++      /// \r
++      /// class MainClass\r
++      /// {\r
++      ///     public static void Main(string[] args)\r
++      ///     {\r
++      ///             ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));\r
++      ///             \r
++      ///             ZipEntry theEntry;\r
++      ///             while ((theEntry = s.GetNextEntry()) != null) {\r
++      ///                     int size = 2048;\r
++      ///                     byte[] data = new byte[2048];\r
++      ///                     \r
++      ///                     Console.Write("Show contents (y/n) ?");\r
++      ///                     if (Console.ReadLine() == "y") {\r
++      ///                             while (true) {\r
++      ///                                     size = s.Read(data, 0, data.Length);\r
++      ///                                     if (size > 0) {\r
++      ///                                             Console.Write(new ASCIIEncoding().GetString(data, 0, size));\r
++      ///                                     } else {\r
++      ///                                             break;\r
++      ///                                     }\r
++      ///                             }\r
++      ///                     }\r
++      ///             }\r
++      ///             s.Close();\r
++      ///     }\r
++      /// }   \r
++      /// </code>\r
++      /// </example>\r
++      public class ZipInputStream : InflaterInputStream\r
++      {\r
++              Crc32 crc = new Crc32();\r
++              ZipEntry entry = null;\r
++              \r
++              long size;\r
++              int method;\r
++              int flags;\r
++              long avail;\r
++              string password = null;\r
++              \r
++              public string Password {\r
++                      get {\r
++                              return password;\r
++                      }\r
++                      set {\r
++                              password = value;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Creates a new Zip input stream, reading a zip archive.\r
++              /// </summary>\r
++              public ZipInputStream(Stream baseInputStream) : base(baseInputStream, new Inflater(true))\r
++              {\r
++              }\r
++              \r
++              void FillBuf()\r
++              {\r
++                      avail = len = baseInputStream.Read(buf, 0, buf.Length);\r
++              }\r
++              \r
++              int ReadBuf(byte[] outBuf, int offset, int length)\r
++              {\r
++                      if (avail <= 0) {\r
++                              FillBuf();\r
++                              if (avail <= 0) {\r
++                                      return 0;\r
++                              }\r
++                      }\r
++                      if (length > avail) {\r
++                              length = (int)avail;\r
++                      }\r
++                      System.Array.Copy(buf, len - (int)avail, outBuf, offset, length);\r
++                      avail -= length;\r
++                      return length;\r
++              }\r
++              \r
++              void ReadFully(byte[] outBuf)\r
++              {\r
++                      int off = 0;\r
++                      int len = outBuf.Length;\r
++                      while (len > 0) {\r
++                              int count = ReadBuf(outBuf, off, len);\r
++                              if (count == -1) {\r
++                                      throw new Exception(); \r
++                              }\r
++                              off += count;\r
++                              len -= count;\r
++                      }\r
++              }\r
++              \r
++              int ReadLeByte()\r
++              {\r
++                      if (avail <= 0) {\r
++                              FillBuf();\r
++                              if (avail <= 0) {\r
++                                      throw new ZipException("EOF in header");\r
++                              }\r
++                      }\r
++                      return buf[len - avail--] & 0xff;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Read an unsigned short baseInputStream little endian byte order.\r
++              /// </summary>\r
++              int ReadLeShort()\r
++              {\r
++                      return ReadLeByte() | (ReadLeByte() << 8);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Read an int baseInputStream little endian byte order.\r
++              /// </summary>\r
++              int ReadLeInt()\r
++              {\r
++                      return ReadLeShort() | (ReadLeShort() << 16);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Read an int baseInputStream little endian byte order.\r
++              /// </summary>\r
++              long ReadLeLong()\r
++              {\r
++                      return ReadLeInt() | (ReadLeInt() << 32);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Open the next entry from the zip archive, and return its description.\r
++              /// If the previous entry wasn't closed, this method will close it.\r
++              /// </summary>\r
++              public ZipEntry GetNextEntry()\r
++              {\r
++                      if (crc == null) {\r
++                              throw new InvalidOperationException("Closed.");\r
++                      }\r
++                      if (entry != null) {\r
++                              CloseEntry();\r
++                      }\r
++                      \r
++                      if (this.cryptbuffer != null) {\r
++                              if (avail == 0 && inf.RemainingInput != 0) {\r
++                                      avail = inf.RemainingInput - 16;\r
++                                      inf.Reset();\r
++                              }\r
++                              baseInputStream.Position -= this.len;\r
++                              baseInputStream.Read(this.buf, 0, this.len);\r
++                      }\r
++                      \r
++                      int header = ReadLeInt();\r
++                      \r
++                      // -jr- added end sig for empty zip files, Zip64 end sig and digital sig for files that have them...\r
++                      if (header == ZipConstants.CENSIG || \r
++                          header == ZipConstants.ENDSIG || \r
++                          header == ZipConstants.CENDIGITALSIG || \r
++                          header == ZipConstants.CENSIG64) {\r
++                              // Central Header reached or end of empty zip file\r
++                              Close();\r
++                              return null;\r
++                      }\r
++                      // -jr- 07-Dec-2003 ignore spanning temporary signatures if found\r
++                      // SPANNINGSIG is same as descriptor signature and is untested as yet.\r
++                      if (header == ZipConstants.SPANTEMPSIG || header == ZipConstants.SPANNINGSIG) {\r
++                              header = ReadLeInt();\r
++                      }\r
++                      \r
++                      if (header != ZipConstants.LOCSIG) {\r
++                              throw new ZipException("Wrong Local header signature: 0x" + String.Format("{0:X}", header));\r
++                      }\r
++                      \r
++                      short version = (short)ReadLeShort();\r
++                      \r
++                      flags = ReadLeShort();\r
++                      method = ReadLeShort();\r
++                      uint dostime = (uint)ReadLeInt();\r
++                      int crc2 = ReadLeInt();\r
++                      csize = ReadLeInt();\r
++                      size = ReadLeInt();\r
++                      int nameLen = ReadLeShort();\r
++                      int extraLen = ReadLeShort();\r
++                      bool isCrypted = (flags & 1) == 1;\r
++                      if (method == ZipOutputStream.STORED && (!isCrypted && csize != size || (isCrypted && csize - 12 != size))) {\r
++                              throw new ZipException("Stored, but compressed != uncompressed");\r
++                      }\r
++                      \r
++                      byte[] buffer = new byte[nameLen];\r
++                      ReadFully(buffer);\r
++                      \r
++                      string name = ZipConstants.ConvertToString(buffer);\r
++                      \r
++                      entry = new ZipEntry(name);\r
++                      entry.IsCrypted = isCrypted;\r
++                      entry.Version = (ushort)version;\r
++                      if (method != 0 && method != 8) {\r
++                              throw new ZipException("unknown compression method " + method);\r
++                      }\r
++                      entry.CompressionMethod = (CompressionMethod)method;\r
++                      \r
++                      if ((flags & 8) == 0) {\r
++                              entry.Crc  = crc2 & 0xFFFFFFFFL;\r
++                              entry.Size = size & 0xFFFFFFFFL;\r
++                              entry.CompressedSize = csize & 0xFFFFFFFFL;\r
++                      }\r
++                      \r
++                      entry.DosTime = dostime;\r
++                      \r
++                      if (extraLen > 0) {\r
++                              byte[] extra = new byte[extraLen];\r
++                              ReadFully(extra);\r
++                              entry.ExtraData = extra;\r
++                      }\r
++                      \r
++                      // test for encryption\r
++                      if (isCrypted) {\r
++                              if (password == null) {\r
++                                      throw new ZipException("No password set.");\r
++                              }\r
++                              InitializePassword(password);\r
++                              cryptbuffer = new byte[12];\r
++                              ReadFully(cryptbuffer);\r
++                              DecryptBlock(cryptbuffer, 0, cryptbuffer.Length);\r
++                              if ((flags & 8) == 0) {// -jr- 10-Feb-2004 Dont yet know correct size here....\r
++                                      csize -= 12;\r
++                              }\r
++                      } else {\r
++                              cryptbuffer = null;\r
++                      }\r
++                      \r
++                      if (method == ZipOutputStream.DEFLATED && avail > 0) {\r
++                              System.Array.Copy(buf, len - (int)avail, buf, 0, (int)avail);\r
++                              len = (int)avail;\r
++                              avail = 0;\r
++                              if (isCrypted) {\r
++                                      DecryptBlock(buf, 0, Math.Min((int)csize, len));\r
++                              }\r
++                              inf.SetInput(buf, 0, len);\r
++                      }\r
++                      \r
++                      return entry;\r
++              }\r
++              private void ReadDataDescr()\r
++              {\r
++                      if (ReadLeInt() != ZipConstants.EXTSIG) {\r
++                              throw new ZipException("Data descriptor signature not found");\r
++                      }\r
++                      entry.Crc = ReadLeInt() & 0xFFFFFFFFL;\r
++                      csize = ReadLeInt();\r
++                      size = ReadLeInt();\r
++                      entry.Size = size & 0xFFFFFFFFL;\r
++                      entry.CompressedSize = csize & 0xFFFFFFFFL;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Closes the current zip entry and moves to the next one.\r
++              /// </summary>\r
++              public void CloseEntry()\r
++              {\r
++                      if (crc == null) {\r
++                              throw new InvalidOperationException("Closed.");\r
++                      }\r
++                      \r
++                      if (entry == null) {\r
++                              return;\r
++                      }\r
++                      \r
++                      if (method == ZipOutputStream.DEFLATED) {\r
++                              if ((flags & 8) != 0) {\r
++                                      /* We don't know how much we must skip, read until end. */\r
++                                      byte[] tmp = new byte[2048];\r
++                                      while (Read(tmp, 0, tmp.Length) > 0)\r
++                                              ;\r
++                                      /* read will close this entry */\r
++                                      return;\r
++                              }\r
++                              csize -= inf.TotalIn;\r
++                              avail = inf.RemainingInput;\r
++                      }\r
++                      if (avail > csize && csize >= 0) {\r
++                              avail -= csize;\r
++                      } else {\r
++                              csize -= avail;\r
++                              avail = 0;\r
++                              while (csize != 0) {\r
++                                      int skipped = (int)base.Skip(csize & 0xFFFFFFFFL);\r
++                                      \r
++                                      if (skipped <= 0) {\r
++                                              throw new ZipException("zip archive ends early.");\r
++                                      }\r
++                                      \r
++                                      csize -= skipped;\r
++                              }\r
++                      }\r
++                      \r
++                      size = 0;\r
++                      crc.Reset();\r
++                      if (method == ZipOutputStream.DEFLATED) {\r
++                              inf.Reset();\r
++                      }\r
++                      entry = null;\r
++              }\r
++              \r
++              public override int Available {\r
++                      get {\r
++                              return entry != null ? 1 : 0;\r
++                      }\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Reads a byte from the current zip entry.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the byte or -1 on EOF.\r
++              /// </returns>\r
++              /// <exception name="System.IO.IOException">\r
++              /// IOException if a i/o error occured.\r
++              /// </exception>\r
++              /// <exception name="ICSharpCode.SharpZipLib.ZipException">\r
++              /// ZipException if the deflated stream is corrupted.\r
++              /// </exception>\r
++              public override int ReadByte()\r
++              {\r
++                      byte[] b = new byte[1];\r
++                      if (Read(b, 0, 1) <= 0) {\r
++                              return -1; // ok\r
++                      }\r
++                      return b[0] & 0xff;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Reads a block of bytes from the current zip entry.\r
++              /// </summary>\r
++              /// <returns>\r
++              /// the number of bytes read (may be smaller, even before EOF), or -1 on EOF.\r
++              /// </returns>\r
++              /// <exception name="Exception">\r
++              /// IOException if a i/o error occured.\r
++              /// ZipException if the deflated stream is corrupted.\r
++              /// </exception>\r
++              public override int Read(byte[] b, int off, int len)\r
++              {\r
++                      if (crc == null) {\r
++                              throw new InvalidOperationException("Closed.");\r
++                      }\r
++                      \r
++                      if (entry == null) {\r
++                              return 0;\r
++                      }\r
++                      bool finished = false;\r
++                      \r
++                      switch (method) {\r
++                              case ZipOutputStream.DEFLATED:\r
++                                      len = base.Read(b, off, len);\r
++                                      if (len <= 0) { // TODO BUG1 -jr- Check this was < 0 but avail was not adjusted causing failure in later calls\r
++                                              if (!inf.IsFinished) {\r
++                                                      throw new ZipException("Inflater not finished!?");\r
++                                              }\r
++                                              avail = inf.RemainingInput;\r
++                                              \r
++                                              // BUG1 -jr- With bit 3 set you dont yet know the size\r
++                                              if ((flags & 8) == 0 && (inf.TotalIn != csize || inf.TotalOut != size)) {\r
++                                                      throw new ZipException("size mismatch: " + csize + ";" + size + " <-> " + inf.TotalIn + ";" + inf.TotalOut);\r
++                                              }\r
++                                              inf.Reset();\r
++                                              finished = true;\r
++                                      }\r
++                                      break;\r
++                              \r
++                              case ZipOutputStream.STORED:\r
++                                      if (len > csize && csize >= 0) {\r
++                                              len = (int)csize;\r
++                                      }\r
++                                      len = ReadBuf(b, off, len);\r
++                                      if (len > 0) {\r
++                                              csize -= len;\r
++                                              size -= len;\r
++                                      }\r
++                                      \r
++                                      if (csize == 0) {\r
++                                              finished = true;\r
++                                      } else {\r
++                                              if (len < 0) {\r
++                                                      throw new ZipException("EOF in stored block");\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      // decrypting crypted data\r
++                                      if (cryptbuffer != null) {\r
++                                              DecryptBlock(b, off, len);\r
++                                      }\r
++                                      \r
++                                      break;\r
++                      }\r
++                              \r
++                      if (len > 0) {\r
++                              crc.Update(b, off, len);\r
++                      }\r
++                      \r
++                      if (finished) {\r
++                              if ((flags & 8) != 0) {\r
++                                      ReadDataDescr();\r
++                              }\r
++                              \r
++                              if ((crc.Value & 0xFFFFFFFFL) != entry.Crc && entry.Crc != -1) {\r
++                                      throw new ZipException("CRC mismatch");\r
++                              }\r
++                              crc.Reset();\r
++                              entry = null;\r
++                      }\r
++                      return len;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Closes the zip file.\r
++              /// </summary>\r
++              /// <exception name="Exception">\r
++              /// if a i/o error occured.\r
++              /// </exception>\r
++              public override void Close()\r
++              {\r
++                      base.Close();\r
++                      crc = null;\r
++                      entry = null;\r
++              }\r
++              \r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..37d285196b3efcc3e2e22ec59c2815cb1fea841a
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,550 @@@
++// ZipOutputStream.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++using System.IO;\r
++using System.Collections;\r
++using System.Text;\r
++\r
++using ICSharpCode.SharpZipLib.Checksums;\r
++using ICSharpCode.SharpZipLib.Zip.Compression;\r
++using ICSharpCode.SharpZipLib.Zip.Compression.Streams;\r
++\r
++namespace ICSharpCode.SharpZipLib.Zip \r
++{\r
++      /// <summary>\r
++      /// This is a FilterOutputStream that writes the files into a zip\r
++      /// archive one after another.  It has a special method to start a new\r
++      /// zip entry.  The zip entries contains information about the file name\r
++      /// size, compressed size, CRC, etc.\r
++      /// \r
++      /// It includes support for STORED and DEFLATED entries.\r
++      /// This class is not thread safe.\r
++      /// \r
++      /// author of the original java version : Jochen Hoenicke\r
++      /// </summary>\r
++      /// <example> This sample shows how to create a zip file\r
++      /// <code>\r
++      /// using System;\r
++      /// using System.IO;\r
++      /// \r
++      /// using NZlib.Zip;\r
++      /// \r
++      /// class MainClass\r
++      /// {\r
++      ///     public static void Main(string[] args)\r
++      ///     {\r
++      ///             string[] filenames = Directory.GetFiles(args[0]);\r
++      ///             \r
++      ///             ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));\r
++      ///             \r
++      ///             s.SetLevel(5); // 0 - store only to 9 - means best compression\r
++      ///             \r
++      ///             foreach (string file in filenames) {\r
++      ///                     FileStream fs = File.OpenRead(file);\r
++      ///                     \r
++      ///                     byte[] buffer = new byte[fs.Length];\r
++      ///                     fs.Read(buffer, 0, buffer.Length);\r
++      ///                     \r
++      ///                     ZipEntry entry = new ZipEntry(file);\r
++      ///                     \r
++      ///                     s.PutNextEntry(entry);\r
++      ///                     \r
++      ///                     s.Write(buffer, 0, buffer.Length);\r
++      ///                     \r
++      ///             }\r
++      ///             \r
++      ///             s.Finish();\r
++      ///             s.Close();\r
++      ///     }\r
++      /// }   \r
++      /// </code>\r
++      /// </example>\r
++      public class ZipOutputStream : DeflaterOutputStream\r
++      {\r
++              private ArrayList entries  = new ArrayList();\r
++              private Crc32     crc      = new Crc32();\r
++              private ZipEntry  curEntry = null;\r
++              \r
++              private CompressionMethod curMethod;\r
++              private int size;\r
++              private int offset = 0;\r
++              \r
++              private byte[] zipComment = new byte[0];\r
++              private int defaultMethod = DEFLATED;\r
++              \r
++              /// <summary>\r
++              /// Our Zip version is hard coded to 1.0 resp. 2.0\r
++              /// </summary>\r
++              private const int ZIP_STORED_VERSION   = 10;\r
++              private const int ZIP_DEFLATED_VERSION = 20;\r
++              \r
++              /// <summary>\r
++              /// Compression method.  This method doesn't compress at all.\r
++              /// </summary>\r
++              public const int STORED      =  0;\r
++              \r
++              /// <summary>\r
++              /// Compression method.  This method uses the Deflater.\r
++              /// </summary>\r
++              public const int DEFLATED    =  8;\r
++              \r
++              /// <summary>\r
++              /// Creates a new Zip output stream, writing a zip archive.\r
++              /// </summary>\r
++              /// <param name="baseOutputStream">\r
++              /// the output stream to which the zip archive is written.\r
++              /// </param>\r
++              public ZipOutputStream(Stream baseOutputStream) : base(baseOutputStream, new Deflater(Deflater.DEFAULT_COMPRESSION, true))\r
++              { \r
++              }\r
++              \r
++              /// <summary>\r
++              /// Set the zip file comment.\r
++              /// </summary>\r
++              /// <param name="comment">\r
++              /// the comment.\r
++              /// </param>\r
++              /// <exception name ="ArgumentException">\r
++              /// if UTF8 encoding of comment is longer than 0xffff bytes.\r
++              /// </exception>\r
++              public void SetComment(string comment)\r
++              {\r
++                      byte[] commentBytes = ZipConstants.ConvertToArray(comment);\r
++                      if (commentBytes.Length > 0xffff) {\r
++                              throw new ArgumentException("Comment too long.");\r
++                      }\r
++                      zipComment = commentBytes;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets default compression method.  If the Zip entry specifies\r
++              /// another method its method takes precedence.\r
++              /// </summary>\r
++              /// <param name = "method">\r
++              /// the method.\r
++              /// </param>\r
++              /// <exception name = "ArgumentException">\r
++              /// if method is not supported.\r
++              /// </exception>\r
++              public void SetMethod(int method)\r
++              {\r
++                      if (method != STORED && method != DEFLATED) {\r
++                              throw new ArgumentException("Method not supported.");\r
++                      }\r
++                      defaultMethod = method;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Sets default compression level.  The new level will be activated\r
++              /// immediately.\r
++              /// </summary>\r
++              /// <exception cref="System.ArgumentOutOfRangeException">\r
++              /// if level is not supported.\r
++              /// </exception>\r
++              /// <see cref="Deflater"/>\r
++              public void SetLevel(int level)\r
++              {\r
++                      def.SetLevel(level);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write an unsigned short in little endian byte order.\r
++              /// </summary>\r
++              private  void WriteLeShort(int value)\r
++              {\r
++                      baseOutputStream.WriteByte((byte)value);\r
++                      baseOutputStream.WriteByte((byte)(value >> 8));\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write an int in little endian byte order.\r
++              /// </summary>\r
++              private void WriteLeInt(int value)\r
++              {\r
++                      WriteLeShort(value);\r
++                      WriteLeShort(value >> 16);\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Write an int in little endian byte order.\r
++              /// </summary>\r
++              private void WriteLeLong(long value)\r
++              {\r
++                      WriteLeInt((int)value);\r
++                      WriteLeInt((int)(value >> 32));\r
++              }\r
++              \r
++              \r
++              bool shouldWriteBack = false;\r
++              // -jr- Having a hard coded flag for seek capability requires this so users can determine\r
++              // if the entries will be patched or not.\r
++              public bool CanPatchEntries {\r
++                      get { \r
++                              return baseOutputStream.CanSeek; \r
++                      }\r
++              }\r
++              \r
++              long seekPos         = -1;\r
++              /// <summary>\r
++              /// Starts a new Zip entry. It automatically closes the previous\r
++              /// entry if present.  If the compression method is stored, the entry\r
++              /// must have a valid size and crc, otherwise all elements (except\r
++              /// name) are optional, but must be correct if present.  If the time\r
++              /// is not set in the entry, the current time is used.\r
++              /// </summary>\r
++              /// <param name="entry">\r
++              /// the entry.\r
++              /// </param>\r
++              /// <exception cref="System.IO.IOException">\r
++              /// if an I/O error occured.\r
++              /// </exception>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if stream was finished\r
++              /// </exception>\r
++              public void PutNextEntry(ZipEntry entry)\r
++              {\r
++                      if (entries == null) {\r
++                              throw new InvalidOperationException("ZipOutputStream was finished");\r
++                      }\r
++                      \r
++                      CompressionMethod method = entry.CompressionMethod;\r
++                      int flags = 0;\r
++                      entry.IsCrypted = Password != null;\r
++                      switch (method) {\r
++                              case CompressionMethod.Stored:\r
++                                      if (entry.CompressedSize >= 0) {\r
++                                              if (entry.Size < 0) {\r
++                                                      entry.Size = entry.CompressedSize;\r
++                                              } else if (entry.Size != entry.CompressedSize) {\r
++                                                      throw new ZipException("Method STORED, but compressed size != size");\r
++                                              }\r
++                                      } else {\r
++                                              entry.CompressedSize = entry.Size;\r
++                                      }\r
++                                      \r
++                                      if (entry.IsCrypted) {\r
++                                              entry.CompressedSize += 12;\r
++                                      }\r
++                                      \r
++                                      if (entry.Size < 0) {\r
++                                              throw new ZipException("Method STORED, but size not set");\r
++                                      } else if (entry.Crc < 0) {\r
++                                              throw new ZipException("Method STORED, but crc not set");\r
++                                      }\r
++                                      break;\r
++                              case CompressionMethod.Deflated:\r
++                                      if (entry.CompressedSize < 0 || entry.Size < 0 || entry.Crc < 0) {\r
++                                              flags |= 8;\r
++                                      }\r
++                                      break;\r
++                      }\r
++                      \r
++                      if (curEntry != null) {\r
++                              CloseEntry();\r
++                      }\r
++                      \r
++                      //                      if (entry.DosTime < 0) {\r
++                      //                              entry.Time = System.Environment.TickCount;\r
++                      //                      }\r
++                      if (entry.IsCrypted) {\r
++                              flags |= 1;\r
++                      }\r
++                      entry.Flags  = flags;\r
++                      entry.Offset = offset;\r
++                      entry.CompressionMethod = (CompressionMethod)method;\r
++                      \r
++                      curMethod    = method;\r
++                      // Write the local file header\r
++                      WriteLeInt(ZipConstants.LOCSIG);\r
++                      \r
++                      // write ZIP version\r
++                      WriteLeShort(method == CompressionMethod.Stored ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);\r
++                      if ((flags & 8) == 0) {\r
++                              WriteLeShort(flags);\r
++                              WriteLeShort((byte)method);\r
++                              WriteLeInt((int)entry.DosTime);\r
++                              WriteLeInt((int)entry.Crc);\r
++                              WriteLeInt((int)entry.CompressedSize);\r
++                              WriteLeInt((int)entry.Size);\r
++                      } else {\r
++                              if (baseOutputStream.CanSeek) {\r
++                                      shouldWriteBack = true;\r
++                                      WriteLeShort((short)(flags & ~8));\r
++                              } else {\r
++                                      shouldWriteBack = false;\r
++                                      WriteLeShort(flags);\r
++                              }\r
++                              WriteLeShort((byte)method);\r
++                              WriteLeInt((int)entry.DosTime);\r
++                              if (baseOutputStream.CanSeek) {\r
++                                      seekPos = baseOutputStream.Position;\r
++                              }\r
++                              WriteLeInt(0);\r
++                              WriteLeInt(0);\r
++                              WriteLeInt(0);\r
++                      }\r
++                      byte[] name = ZipConstants.ConvertToArray(entry.Name);\r
++                      \r
++                      if (name.Length > 0xFFFF) {\r
++                              throw new ZipException("Name too long.");\r
++                      }\r
++                      byte[] extra = entry.ExtraData;\r
++                      if (extra == null) {\r
++                              extra = new byte[0];\r
++                      }\r
++                      if (extra.Length > 0xFFFF) {\r
++                              throw new ZipException("Extra data too long.");\r
++                      }\r
++                      \r
++                      WriteLeShort(name.Length);\r
++                      WriteLeShort(extra.Length);\r
++                      baseOutputStream.Write(name, 0, name.Length);\r
++                      baseOutputStream.Write(extra, 0, extra.Length);\r
++                      \r
++                      if (Password != null) {\r
++                              InitializePassword(Password);\r
++                              byte[] cryptbuffer = new byte[12];\r
++                              Random rnd = new Random();\r
++                              for (int i = 0; i < cryptbuffer.Length; ++i) {\r
++                                      cryptbuffer[i] = (byte)rnd.Next();\r
++                              }\r
++                              EncryptBlock(cryptbuffer, 0, cryptbuffer.Length);\r
++                              baseOutputStream.Write(cryptbuffer, 0, cryptbuffer.Length);\r
++                      }\r
++                      offset += ZipConstants.LOCHDR + name.Length + extra.Length;\r
++                      \r
++                      /* Activate the entry. */\r
++                      curEntry = entry;\r
++                      crc.Reset();\r
++                      if (method == CompressionMethod.Deflated) {\r
++                              def.Reset();\r
++                      }\r
++                      size = 0;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Closes the current entry.\r
++              /// </summary>\r
++              /// <exception cref="System.IO.IOException">\r
++              /// if an I/O error occured.\r
++              /// </exception>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if no entry is active.\r
++              /// </exception>\r
++              public void CloseEntry()\r
++              {\r
++                      if (curEntry == null) {\r
++                              throw new InvalidOperationException("No open entry");\r
++                      }\r
++                      \r
++                      /* First finish the deflater, if appropriate */\r
++                      if (curMethod == CompressionMethod.Deflated) {\r
++                              base.Finish();\r
++                      }\r
++                      \r
++                      int csize = curMethod == CompressionMethod.Deflated ? def.TotalOut : size;\r
++                      \r
++                      if (curEntry.Size < 0) {\r
++                              curEntry.Size = size;\r
++                      } else if (curEntry.Size != size) {\r
++                              throw new ZipException("size was " + size + ", but I expected " + curEntry.Size);\r
++                      }\r
++                      \r
++                      if (curEntry.IsCrypted) {\r
++                              csize += 12;\r
++                      }\r
++                      \r
++                      if (curEntry.CompressedSize < 0) {\r
++                              curEntry.CompressedSize = csize;\r
++                      } else if (curEntry.CompressedSize != csize) {\r
++                              throw new ZipException("compressed size was " + csize + ", but I expected " + curEntry.CompressedSize);\r
++                      }\r
++                      \r
++                      if (curEntry.Crc < 0) {\r
++                              curEntry.Crc = crc.Value;\r
++                      } else if (curEntry.Crc != crc.Value) {\r
++                              throw new ZipException("crc was " + crc.Value +\r
++                                      ", but I expected " + \r
++                                      curEntry.Crc);\r
++                      }\r
++                      \r
++                      offset += csize;\r
++                      \r
++                      /* Now write the data descriptor entry if needed. */\r
++                      if (curMethod == CompressionMethod.Deflated && (curEntry.Flags & 8) != 0) {\r
++                              if (shouldWriteBack) {\r
++                                      curEntry.Flags &= ~8;\r
++                                      long curPos = baseOutputStream.Position;\r
++                                      baseOutputStream.Seek(seekPos, SeekOrigin.Begin);\r
++                                      WriteLeInt((int)curEntry.Crc);\r
++                                      WriteLeInt((int)curEntry.CompressedSize);\r
++                                      WriteLeInt((int)curEntry.Size);\r
++                                      baseOutputStream.Seek(curPos, SeekOrigin.Begin);\r
++                                      shouldWriteBack = false;\r
++                              } else {\r
++                                      WriteLeInt(ZipConstants.EXTSIG);\r
++                                      WriteLeInt((int)curEntry.Crc);\r
++                                      WriteLeInt((int)curEntry.CompressedSize);\r
++                                      WriteLeInt((int)curEntry.Size);\r
++                                      offset += ZipConstants.EXTHDR;\r
++                              }\r
++                      }\r
++                      \r
++                      entries.Add(curEntry);\r
++                      curEntry = null;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Writes the given buffer to the current entry.\r
++              /// </summary>\r
++              /// <exception cref="System.IO.IOException">\r
++              /// if an I/O error occured.\r
++              /// </exception>\r
++              /// <exception cref="System.InvalidOperationException">\r
++              /// if no entry is active.\r
++              /// </exception>\r
++              public override void Write(byte[] b, int off, int len)\r
++              {\r
++                      if (curEntry == null) {\r
++                              throw new InvalidOperationException("No open entry.");\r
++                      }\r
++                      \r
++                      switch (curMethod) {\r
++                              case CompressionMethod.Deflated:\r
++                                      base.Write(b, off, len);\r
++                                      break;\r
++                              case CompressionMethod.Stored:\r
++                                      if (Password != null) {\r
++                                              byte[] buf = new byte[len];\r
++                                              Array.Copy(b, off, buf, 0, len);\r
++                                              EncryptBlock(buf, 0, len);\r
++                                              baseOutputStream.Write(buf, off, len);\r
++                                      } else {\r
++                                              baseOutputStream.Write(b, off, len);\r
++                                      }\r
++                                      break;\r
++                      }\r
++                      crc.Update(b, off, len);\r
++                      \r
++                      size += len;\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Finishes the stream.  This will write the central directory at the\r
++              /// end of the zip file and flush the stream.\r
++              /// </summary>\r
++              /// <exception cref="System.IO.IOException">\r
++              /// if an I/O error occured.\r
++              /// </exception>\r
++              public override void Finish()\r
++              {\r
++                      if (entries == null)  {\r
++                              return;\r
++                      }\r
++                      \r
++                      if (curEntry != null) {\r
++                              CloseEntry();\r
++                      }\r
++                      \r
++                      int numEntries = 0;\r
++                      int sizeEntries = 0;\r
++                      \r
++                      foreach (ZipEntry entry in entries) {\r
++                              // TODO : check the appnote file for compilance with the central directory standard\r
++                              CompressionMethod method = entry.CompressionMethod;\r
++                              WriteLeInt(ZipConstants.CENSIG); \r
++                              WriteLeShort(method == CompressionMethod.Stored ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);\r
++                              WriteLeShort(method == CompressionMethod.Stored ? ZIP_STORED_VERSION : ZIP_DEFLATED_VERSION);\r
++                              \r
++                              WriteLeShort(entry.Flags);\r
++                              WriteLeShort((short)method);\r
++                              WriteLeInt((int)entry.DosTime);\r
++                              WriteLeInt((int)entry.Crc);\r
++                              WriteLeInt((int)entry.CompressedSize);\r
++                              WriteLeInt((int)entry.Size);\r
++                              \r
++                              byte[] name = ZipConstants.ConvertToArray(entry.Name);\r
++                              \r
++                              if (name.Length > 0xffff) {\r
++                                      throw new ZipException("Name too long.");\r
++                              }\r
++                              \r
++                              byte[] extra = entry.ExtraData;\r
++                              if (extra == null) {\r
++                                      extra = new byte[0];\r
++                              }\r
++                              \r
++                              string strComment = entry.Comment;\r
++                              byte[] comment = strComment != null ? ZipConstants.ConvertToArray(strComment) : new byte[0];\r
++                              if (comment.Length > 0xffff) {\r
++                                      throw new ZipException("Comment too long.");\r
++                              }\r
++                              \r
++                              WriteLeShort(name.Length);\r
++                              WriteLeShort(extra.Length);\r
++                              WriteLeShort(comment.Length);\r
++                              WriteLeShort(0); // disk number\r
++                              WriteLeShort(0); // internal file attr\r
++                              if (entry.IsDirectory) {                         // -jr- 17-12-2003 mark entry as directory (from nikolam.AT.perfectinfo.com)\r
++                                      WriteLeInt(16);\r
++                              } else {\r
++                                      WriteLeInt(0);   // external file attr\r
++                              }\r
++                              WriteLeInt(entry.Offset);\r
++                              \r
++                              baseOutputStream.Write(name,    0, name.Length);\r
++                              baseOutputStream.Write(extra,   0, extra.Length);\r
++                              baseOutputStream.Write(comment, 0, comment.Length);\r
++                              ++numEntries;\r
++                              sizeEntries += ZipConstants.CENHDR + name.Length + extra.Length + comment.Length;\r
++                      }\r
++                      \r
++                      WriteLeInt(ZipConstants.ENDSIG);\r
++                      WriteLeShort(0); // disk number \r
++                      WriteLeShort(0); // disk with start of central dir\r
++                      WriteLeShort(numEntries);\r
++                      WriteLeShort(numEntries);\r
++                      WriteLeInt(sizeEntries);\r
++                      WriteLeInt(offset);\r
++                      WriteLeShort(zipComment.Length);\r
++                      baseOutputStream.Write(zipComment, 0, zipComment.Length);\r
++                      baseOutputStream.Flush();\r
++                      entries = null;\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b342592569aabbfa3dd5a83971fccf801e16cce2
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,62 @@@
++// ZipException.cs\r
++// Copyright (C) 2001 Mike Krueger\r
++//\r
++// This file was translated from java, it was part of the GNU Classpath\r
++// Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.\r
++//\r
++// This program is free software; you can redistribute it and/or\r
++// modify it under the terms of the GNU General Public License\r
++// as published by the Free Software Foundation; either version 2\r
++// of the License, or (at your option) any later version.\r
++//\r
++// This program is distributed in the hope that it will be useful,\r
++// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++// GNU General Public License for more details.\r
++//\r
++// You should have received a copy of the GNU General Public License\r
++// along with this program; if not, write to the Free Software\r
++// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
++//\r
++// Linking this library statically or dynamically with other modules is\r
++// making a combined work based on this library.  Thus, the terms and\r
++// conditions of the GNU General Public License cover the whole\r
++// combination.\r
++// \r
++// As a special exception, the copyright holders of this library give you\r
++// permission to link this library with independent modules to produce an\r
++// executable, regardless of the license terms of these independent\r
++// modules, and to copy and distribute the resulting executable under\r
++// terms of your choice, provided that you also meet, for each linked\r
++// independent module, the terms and conditions of the license of that\r
++// module.  An independent module is a module which is not derived from\r
++// or based on this library.  If you modify this library, you may extend\r
++// this exception to your version of the library, but you are not\r
++// obligated to do so.  If you do not wish to do so, delete this\r
++// exception statement from your version.\r
++\r
++using System;\r
++\r
++namespace ICSharpCode.SharpZipLib \r
++{\r
++      \r
++      /// <summary>\r
++      /// Is thrown during the creation or input of a zip file.\r
++      /// </summary>\r
++      public class ZipException : Exception\r
++      {\r
++              /// <summary>\r
++              /// Initializes a new instance of the ZipException class with default properties.\r
++              /// </summary>\r
++              public ZipException()\r
++              {\r
++              }\r
++              \r
++              /// <summary>\r
++              /// Initializes a new instance of the ZipException class with a specified error message.\r
++              /// </summary>\r
++              public ZipException(string msg) : base(msg)\r
++              {\r
++              }\r
++      }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..fe5ae55972cdb70e8137c502345874ae76555cd4
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,12 @@@
++thisdir = class/ICSharpCode.SharpZipLib
++SUBDIRS = 
++include ../../build/rules.make
++
++LIBRARY = ICSharpCode.SharpZipLib.dll
++LIBRARY_SNK = SharpZipLib.key
++
++LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:System.Xml.dll
++NO_TEST = yes
++EXTRA_DISTFILES = SharpZipLib.pub $(LIBRARY_SNK)
++
++include ../../build/library.make
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..e38911920ac613d0e58769c1a974457dc10cb31f
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,28 @@@
++I imported the 0.6 version of the library. The only changes from the origional were
++the case of some of the file names -- I changed them to match the names in cvs.
++
++Ben Maurer.  May, 2004.
++
++--------------------
++
++This directory contains a local copy of the Zip library from the NZipLib project.
++
++I have added this as a temporary measure to simplify the building and development
++of the Mono Documentation browser, but ideally it should use the real
++library.  Do not fix bugs here, fix it on the original, and incorporate them
++here.
++
++This code is released under this license, from:
++
++      http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx
++
++Here it is:
++
++The library is released under the GPL with the following exception:
++
++Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination.
++
++As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. 
++
++
++Miguel.  Jan, 2003
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..58cf194dfdb9ac183edd43614d60de5ada399419
new file mode 100755 (executable)
Binary files differ
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..c74794f133295e94ca6e9bc82cca4da1d0585606
new file mode 100644 (file)
Binary files differ