annotate BZip2/BZip2.cs @ 1:94e25b786321

Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller Initial commit of clean SharpZipLib 0860 source. Only change is build paths.
author IBBoard <dev@ibboard.co.uk>
date Sat, 30 Oct 2010 14:03:17 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // BZip2.cs
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // Copyright (C) 2010 David Pierson
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 //
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 // This program is free software; you can redistribute it and/or
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 // modify it under the terms of the GNU General Public License
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 // as published by the Free Software Foundation; either version 2
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 // of the License, or (at your option) any later version.
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 //
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 // This program is distributed in the hope that it will be useful,
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 // GNU General Public License for more details.
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 //
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 // You should have received a copy of the GNU General Public License
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 // along with this program; if not, write to the Free Software
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 //
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 // Linking this library statically or dynamically with other modules is
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 // making a combined work based on this library. Thus, the terms and
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 // conditions of the GNU General Public License cover the whole
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 // combination.
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 //
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 // As a special exception, the copyright holders of this library give you
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 // permission to link this library with independent modules to produce an
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 // executable, regardless of the license terms of these independent
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 // modules, and to copy and distribute the resulting executable under
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 // terms of your choice, provided that you also meet, for each linked
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 // independent module, the terms and conditions of the license of that
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 // module. An independent module is a module which is not derived from
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 // or based on this library. If you modify this library, you may extend
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 // this exception to your version of the library, but you are not
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 // obligated to do so. If you do not wish to do so, delete this
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 // exception statement from your version.
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 // Suppress this in CF and 1.1, not needed. Static classes introduced in C# version 2.0
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 #if !NETCF_2_0 && !NET_1_1
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 using System;
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 using System.IO;
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 namespace ICSharpCode.SharpZipLib.BZip2 {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 /// <summary>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 /// An example class to demonstrate compression and decompression of BZip2 streams.
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 /// </summary>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 public static class BZip2
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 /// <summary>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 /// Decompress the <paramref name="inStream">input</paramref> writing
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 /// uncompressed data to the <paramref name="outStream">output stream</paramref>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 /// </summary>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 /// <param name="inStream">The readable stream containing data to decompress.</param>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 /// <param name="outStream">The output stream to receive the decompressed data.</param>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 /// <param name="isStreamOwner">Both streams are closed on completion if true.</param>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner)
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 if (inStream == null || outStream == null) {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 throw new Exception("Null Stream");
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 try {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 using (BZip2InputStream bzipInput = new BZip2InputStream(inStream)) {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 bzipInput.IsStreamOwner = isStreamOwner;
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 Core.StreamUtils.Copy(bzipInput, outStream, new byte[4096]);
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 } finally {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 if (isStreamOwner) {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 // inStream is closed by the BZip2InputStream if stream owner
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 outStream.Close();
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 /// <summary>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 /// Compress the <paramref name="inStream">input stream</paramref> sending
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 /// result data to <paramref name="outStream">output stream</paramref>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 /// </summary>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 /// <param name="inStream">The readable stream to compress.</param>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 /// <param name="outStream">The output stream to receive the compressed data.</param>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 /// <param name="isStreamOwner">Both streams are closed on completion if true.</param>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 /// <param name="level">Block size acts as compression level (1 to 9) with 1 giving
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 /// the lowest compression and 9 the highest.</param>
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 public static void Compress(Stream inStream, Stream outStream, bool isStreamOwner, int level)
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 if (inStream == null || outStream == null) {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 throw new Exception("Null Stream");
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 try {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 using (BZip2OutputStream bzipOutput = new BZip2OutputStream(outStream, level)) {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 bzipOutput.IsStreamOwner = isStreamOwner;
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 Core.StreamUtils.Copy(inStream, bzipOutput, new byte[4096]);
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 } finally {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 if (isStreamOwner) {
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 // outStream is closed by the BZip2OutputStream if stream owner
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 inStream.Close();
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 }
94e25b786321 Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 #endif