Skip to content

Commit 9bf7839

Browse files
committed
Add DotNetZip BZip2 implementation
1 parent 04d5efd commit 9bf7839

File tree

8 files changed

+5133
-1
lines changed

8 files changed

+5133
-1
lines changed

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ For the latest WIP build here: [Rolling Release](https://github.com/SabreTools/S
2828

2929
| Library Name | Use |
3030
| --- | ---|
31-
| [DotNetZip](https://github.com/DinoChiesa/DotNetZip) | DEFLATE implementation; minor edits have been made |
31+
| [DotNetZip](https://github.com/DinoChiesa/DotNetZip) | BZip2 and DEFLATE implementations; minor edits have been made |
3232
| [ZLibPort](https://github.com/Nanook/zlib-C-To-CSharp-Port) | Adds zlib code for internal and external use; minor edits have been made |

SabreTools.Compression/BZip2/BZip2.cs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// BZip2InputStream.cs
2+
// ------------------------------------------------------------------
3+
//
4+
// Copyright (c) 2011 Dino Chiesa.
5+
// All rights reserved.
6+
//
7+
// This code module is part of DotNetZip, a zipfile class library.
8+
//
9+
// ------------------------------------------------------------------
10+
//
11+
// This code is licensed under the Microsoft Public License.
12+
// See the file License.txt for the license details.
13+
// More info on: http://dotnetzip.codeplex.com
14+
//
15+
// ------------------------------------------------------------------
16+
//
17+
// Last Saved: <2011-July-31 11:57:32>
18+
//
19+
// ------------------------------------------------------------------
20+
//
21+
// This module defines the BZip2InputStream class, which is a decompressing
22+
// stream that handles BZIP2. This code is derived from Apache commons source code.
23+
// The license below applies to the original Apache code.
24+
//
25+
// ------------------------------------------------------------------
26+
27+
/*
28+
* Licensed to the Apache Software Foundation (ASF) under one
29+
* or more contributor license agreements. See the NOTICE file
30+
* distributed with this work for additional information
31+
* regarding copyright ownership. The ASF licenses this file
32+
* to you under the Apache License, Version 2.0 (the
33+
* "License"); you may not use this file except in compliance
34+
* with the License. You may obtain a copy of the License at
35+
*
36+
* http://www.apache.org/licenses/LICENSE-2.0
37+
*
38+
* Unless required by applicable law or agreed to in writing,
39+
* software distributed under the License is distributed on an
40+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
41+
* KIND, either express or implied. See the License for the
42+
* specific language governing permissions and limitations
43+
* under the License.
44+
*/
45+
46+
/*
47+
* This package is based on the work done by Keiron Liddle, Aftex Software
48+
* <keiron@aftexsw.com> to whom the Ant project is very grateful for his
49+
* great code.
50+
*/
51+
52+
// compile: msbuild
53+
// not: csc.exe /t:library /debug+ /out:SabreTools.Compression.BZip2.dll BZip2InputStream.cs BCRC32.cs Rand.cs
54+
55+
namespace SabreTools.Compression.BZip2
56+
{
57+
// /**
58+
// * Checks if the signature matches what is expected for a bzip2 file.
59+
// *
60+
// * @param signature
61+
// * the bytes to check
62+
// * @param length
63+
// * the number of bytes to check
64+
// * @return true, if this stream is a bzip2 compressed stream, false otherwise
65+
// *
66+
// * @since Apache Commons Compress 1.1
67+
// */
68+
// public static boolean MatchesSig(byte[] signature)
69+
// {
70+
// if ((signature.Length < 3) ||
71+
// (signature[0] != 'B') ||
72+
// (signature[1] != 'Z') ||
73+
// (signature[2] != 'h'))
74+
// return false;
75+
//
76+
// return true;
77+
// }
78+
79+
internal static class BZip2
80+
{
81+
internal static T[][] InitRectangularArray<T>(int d1, int d2)
82+
{
83+
var x = new T[d1][];
84+
for (int i = 0; i < d1; i++)
85+
{
86+
x[i] = new T[d2];
87+
}
88+
return x;
89+
}
90+
91+
public static readonly int BlockSizeMultiple = 100000;
92+
public static readonly int MinBlockSize = 1;
93+
public static readonly int MaxBlockSize = 9;
94+
public static readonly int MaxAlphaSize = 258;
95+
public static readonly int MaxCodeLength = 23;
96+
public static readonly char RUNA = (char)0;
97+
public static readonly char RUNB = (char)1;
98+
public static readonly int NGroups = 6;
99+
public static readonly int G_SIZE = 50;
100+
public static readonly int N_ITERS = 4;
101+
public static readonly int MaxSelectors = (2 + (900000 / G_SIZE));
102+
public static readonly int NUM_OVERSHOOT_BYTES = 20;
103+
/*
104+
* <p> If you are ever unlucky/improbable enough to get a stack
105+
* overflow whilst sorting, increase the following constant and
106+
* try again. In practice I have never seen the stack go above 27
107+
* elems, so the following limit seems very generous. </p>
108+
*/
109+
internal static readonly int QSORT_STACK_SIZE = 1000;
110+
111+
112+
}
113+
114+
}

0 commit comments

Comments
 (0)