本文整理汇总了C#中ICSharpCode.SharpZipLib.BZip2.BZip2InputStream类的典型用法代码示例。如果您正苦于以下问题:C# BZip2InputStream类的具体用法?C# BZip2InputStream怎么用?C# BZip2InputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BZip2InputStream类属于ICSharpCode.SharpZipLib.BZip2命名空间,在下文中一共展示了BZip2InputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Extract
public void Extract(string path, string dest_dir)
{
BZip2InputStream bz2stream = new BZip2InputStream(new FileStream( path, FileMode.Open));
TarExtracter untar = new TarExtracter();
untar.Extract(bz2stream, dest_dir);
bz2stream.Close();
}
示例2: BasicRoundTrip
public void BasicRoundTrip()
{
MemoryStream ms = new MemoryStream();
BZip2OutputStream outStream = new BZip2OutputStream(ms);
byte[] buf = new byte[10000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Close();
ms = new MemoryStream(ms.GetBuffer());
ms.Seek(0, SeekOrigin.Begin);
using (BZip2InputStream inStream = new BZip2InputStream(ms))
{
byte[] buf2 = new byte[buf.Length];
int pos = 0;
while (true)
{
int numRead = inStream.Read(buf2, pos, 4096);
if (numRead <= 0)
{
break;
}
pos += numRead;
}
for (int i = 0; i < buf.Length; ++i)
{
Assert.AreEqual(buf2[i], buf[i]);
}
}
}
示例3: CreateEmptyArchive
public void CreateEmptyArchive()
{
MemoryStream ms = new MemoryStream();
BZip2OutputStream outStream = new BZip2OutputStream(ms);
outStream.Close();
ms = new MemoryStream(ms.GetBuffer());
ms.Seek(0, SeekOrigin.Begin);
using (BZip2InputStream inStream = new BZip2InputStream(ms))
{
byte[] buffer = new byte[1024];
int pos = 0;
while (true)
{
int numRead = inStream.Read(buffer, 0, buffer.Length);
if (numRead <= 0)
{
break;
}
pos += numRead;
}
Assert.AreEqual(pos, 0);
}
}
示例4: BZip2_Compress_Extract_Test
public void BZip2_Compress_Extract_Test() {
var plainStream = PlainText.ToStream();
plainStream.Seek(0, SeekOrigin.Begin);
var plainData = Encoding.UTF8.GetBytes(PlainText);
byte[] compressedData;
byte[] extractedData;
// Compress
using(var compressedStream = new MemoryStream())
using(var bz2 = new BZip2OutputStream(compressedStream)) {
bz2.Write(plainData, 0, plainData.Length);
bz2.Close();
compressedData = compressedStream.ToArray();
}
Assert.IsNotNull(compressedData);
// Array.Resize(ref compressedData, compressedData.Length+1);
// compressedData[compressedData.Length - 1] = (byte)0;
// Extract
using(var compressedStream = new MemoryStream(compressedData))
using(var bz2 = new BZip2InputStream(compressedStream))
using(var extractedStream = new MemoryStream()) {
StreamTool.CopyStreamToStream(bz2, extractedStream);
extractedData = extractedStream.ToArray();
}
Assert.IsNotNull(extractedData);
string extractedText = Encoding.UTF8.GetString(extractedData).TrimEnd('\0');
Assert.AreEqual(PlainText, extractedText);
}
示例5: Decompress
/// <summary>
/// 압축된 데이타를 복원한다.
/// </summary>
/// <param name="input">복원할 Data</param>
/// <returns>복원된 Data</returns>
public override byte[] Decompress(byte[] input) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.DecompressStartMsg);
// check input data
if(input.IsZeroLength()) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.InvalidInputDataMsg);
return CompressorTool.EmptyBytes;
}
byte[] output;
using(var inStream = new MemoryStream(input)) {
using(var bz2 = new BZip2InputStream(inStream))
using(var outStream = new MemoryStream(input.Length * 2)) {
StreamTool.CopyStreamToStream(bz2, outStream, CompressorTool.BUFFER_SIZE);
output = outStream.ToArray();
}
}
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.DecompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);
return output;
}
示例6: Untbz
public static void Untbz(Stream stream, string outDirPath)
{
using (var inputStream = new BZip2InputStream(stream)) {
var archive = TarArchive.CreateInputTarArchive(inputStream);
archive.AsciiTranslate = false;
archive.ExtractContents(outDirPath);
}
}
示例7: TrigradCompressed
/// <summary> Loads a TrigradCompressed image from a stream. </summary>
public TrigradCompressed(Stream s)
{
using (BZip2InputStream dezipper = new BZip2InputStream(s))
using (BinaryReader reader = new BinaryReader(dezipper))
{
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();
uint count = reader.ReadUInt32();
Point[] points = new Point[count];
for (int i = 0; i < count; i++)
points[i].X = reader.ReadUInt16();
for (int i = 0; i < count; i++)
points[i].Y = reader.ReadUInt16();
ColorStruct[] colors = new ColorStruct[count];
for (int i = 0; i < count; i++)
colors[i].R = reader.ReadByte();
for (int i = 0; i < count; i++)
colors[i].G = reader.ReadByte();
for (int i = 0; i < count; i++)
colors[i].B = reader.ReadByte();
for (int i = 0; i < count; i++)
{
SampleTable.Add(points[i],colors[i].Color);
}
uint meshCount = reader.ReadUInt32();
SampleTri[] tris = new SampleTri[meshCount];
for (int i = 0; i < meshCount; i++)
tris[i] = new SampleTri();
for (int i = 0; i < meshCount; i++)
tris[i].U = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black));
for (int i = 0; i < meshCount; i++)
tris[i].V = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black));
for (int i = 0; i < meshCount; i++)
tris[i].W = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black));
foreach (var tri in tris)
{
tri.U.Color = SampleTable[tri.U.Point];
tri.V.Color = SampleTable[tri.V.Point];
tri.W.Color = SampleTable[tri.W.Point];
}
Mesh = tris.ToList();
}
}
示例8: Main
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage : MtUnZip {NameOfOsm.Bz2} {MtIsEnabled}");
return;
}
if (!File.Exists(args[0]))
{
Console.WriteLine("File {0} does not exist", args[0]);
return;
}
bool mtIsEnabled = bool.Parse(args[1]);
var timer = Stopwatch.StartNew();
var unzipper = new BZip2InputStream(File.OpenRead(args[0]));
Stream bufferedReader = unzipper;
if (mtIsEnabled)
bufferedReader = new MultiThreadBufferedReader(unzipper);
var rd = XmlReader.Create(bufferedReader);
var nodeNameCounts = new List<NodeStats>();
while (rd.Read())
{
if (rd.NodeType == XmlNodeType.Element)
{
var name = rd.Name;
var stats = nodeNameCounts.FirstOrDefault(nodeStats => nodeStats.Name == name);
if (stats == null)
{
stats = new NodeStats(name);
nodeNameCounts.Add(stats);
}
stats.Update(rd);
}
}
nodeNameCounts.Sort((lhs, rhs) => lhs.Name.CompareTo(rhs.Name));
foreach (var stats in nodeNameCounts)
{
Console.WriteLine("{0,20} : {1,10:N0}", stats.Name, stats.Count);
}
Console.WriteLine("Took {0:N0} [ms]", timer.ElapsedMilliseconds);
Console.WriteLine("Total Processor time {0:N0} [ms]", Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds);
}
示例9: ExtractTemplate
// about 800ms here, not that slow.
public static void ExtractTemplate(string packedTemplatePath)
{
var appRootDir = Path.GetDirectoryName(Application.ExecutablePath);
using (var packedTemplate = File.OpenRead(packedTemplatePath))
using (var bz2 = new BZip2InputStream(packedTemplate))
using (var tar = TarArchive.CreateInputTarArchive(bz2))
{
tar.ExtractContents(appRootDir);
}
}
示例10: Decompress
public static void Decompress(Stream instream, Stream outstream)
{
System.IO.Stream bos = outstream;
System.IO.Stream bis = instream;
BZip2InputStream bzis = new BZip2InputStream(bis);
int ch = bzis.ReadByte();
while (ch != -1) {
bos.WriteByte((byte)ch);
ch = bzis.ReadByte();
}
bos.Flush();
}
示例11: RemoveLineBreaks
private static void RemoveLineBreaks(string source, string destination)
{
Parallel.ForEach(Directory.GetFiles(source, "*.bz2"), file =>
{
using(var fileStream = new FileStream(file, FileMode.Open))
using (var bz2Stream = new BZip2InputStream(fileStream))
using(var reader = new StreamReader(bz2Stream))
{
var content = reader.ReadToEnd().Replace(Environment.NewLine, string.Empty);
File.WriteAllText(Path.Combine(destination, Path.GetFileNameWithoutExtension(file)), content);
}
});
}
示例12: Decompress
public static byte[] Decompress(byte[] input, int uncompressedLength)
{
Contract.Requires(input != null);
Contract.Requires(uncompressedLength >= 0);
Contract.Ensures(Contract.Result<byte[]>() != null);
Contract.Ensures(Contract.Result<byte[]>().Length == uncompressedLength);
var output = new byte[uncompressedLength];
using (var stream = new BZip2InputStream(new MemoryStream(input, false)))
stream.Read(output, 0, uncompressedLength);
return output;
}
示例13: Decompress
/// <summary>
/// 解压缩字符串(ICSharpCode.SharpZipLib版)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string Decompress(string input)
{
string result = string.Empty;
byte[] buffer = Convert.FromBase64String(input);
using (Stream inputStream = new MemoryStream(buffer))
{
BZip2InputStream zipStream = new BZip2InputStream(inputStream);
using (StreamReader reader = new StreamReader(zipStream, Encoding.UTF8))
{
//输出
result = reader.ReadToEnd();
}
}
return result;
}
示例14: Decompress
/// <summary>
/// Decompress the <paramref name="inStream">input</paramref> writing
/// uncompressed data to the <paramref name="outStream">output stream</paramref>
/// </summary>
/// <param name="inStream">The readable stream containing data to decompress.</param>
/// <param name="outStream">The output stream to receive the decompressed data.</param>
/// <param name="isStreamOwner">Both streams are closed on completion if true.</param>
public static void Decompress(Stream inStream, Stream outStream, bool isStreamOwner) {
if (inStream==null||outStream==null) {
throw new Exception("Null Stream");
}
try {
using (var bzipInput=new BZip2InputStream(inStream)) {
bzipInput.IsStreamOwner=isStreamOwner;
StreamUtils.Copy(bzipInput, outStream, new byte[4096]);
}
} finally {
if (isStreamOwner) {
// inStream is closed by the BZip2InputStream if stream owner
outStream.Dispose();
}
}
}
示例15: ParseDisks
private static Stopwatch ParseDisks(Action<Disk> addToBatch)
{
int i = 0;
var parser = new Parser();
var buffer = new byte[1024*1024];// more than big enough for all files
var sp = Stopwatch.StartNew();
using (var bz2 = new BZip2InputStream(File.Open(@"D:\Data\freedb-complete-20120101.tar.bz2", FileMode.Open)))
using (var tar = new TarInputStream(bz2))
{
TarEntry entry;
while((entry=tar.GetNextEntry()) != null)
{
if(entry.Size == 0 || entry.Name == "README" || entry.Name == "COPYING")
continue;
var readSoFar = 0;
while(true)
{
var read = tar.Read(buffer, readSoFar, ((int) entry.Size) - readSoFar);
if (read == 0)
break;
readSoFar += read;
}
// we do it in this fashion to have the stream reader detect the BOM / unicode / other stuff
// so we can read the values properly
var fileText = new StreamReader(new MemoryStream(buffer,0, readSoFar)).ReadToEnd();
try
{
var disk = parser.Parse(fileText);
addToBatch(disk);
if (i++ % BatchSize == 0)
Console.Write("\r{0} {1:#,#} {2} ", entry.Name, i, sp.Elapsed);
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine(entry.Name);
Console.WriteLine(e);
return sp;
}
}
}
return sp;
}