• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# BZip2.BZip2InputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ICSharpCode.SharpZipLib.BZip2.BZip2InputStream的典型用法代码示例。如果您正苦于以下问题:C# BZip2InputStream类的具体用法?C# BZip2InputStream怎么用?C# BZip2InputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BZip2InputStream类属于ICSharpCode.SharpZipLib.BZip2命名空间,在下文中一共展示了BZip2InputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
 }
开发者ID:GNOME,项目名称:capuchin,代码行数:7,代码来源:TarBz2Extracter.cs


示例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]);
				}
			}
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:34,代码来源:Bzip2Tests.cs


示例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);
			}
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:26,代码来源:Bzip2Tests.cs


示例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);
        }
开发者ID:debop,项目名称:NFramework,代码行数:35,代码来源:SharpBZip2CompressorFixture.cs


示例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;
        }
开发者ID:debop,项目名称:NFramework,代码行数:31,代码来源:SharpBZip2Compressor.cs


示例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);
     }
 }
开发者ID:UnicoenProject,项目名称:UNICOEN-Test,代码行数:8,代码来源:Extractor.cs


示例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();
            }
        }
开发者ID:ruarai,项目名称:Trigrad,代码行数:58,代码来源:FileDecompression.cs


示例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);
        }
开发者ID:owen-griffiths,项目名称:Experiments,代码行数:55,代码来源:Program.cs


示例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);
            }
        }
开发者ID:rscustom,项目名称:rocksmith-custom-song-toolkit,代码行数:12,代码来源:Wwise.cs


示例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();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:12,代码来源:BZip2.cs


示例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);
         }
     });
 }
开发者ID:GreenIcicle,项目名称:ConnectedVehicleBatchLayer,代码行数:13,代码来源:Program.cs


示例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;
        }
开发者ID:hanson-huang,项目名称:Encore,代码行数:14,代码来源:BZip2Decompressor.cs


示例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;
        }
开发者ID:eatage,项目名称:AppTest.bak,代码行数:21,代码来源:zip.cs


示例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();
                }
            }
        }
开发者ID:fanfeilong,项目名称:exceltk,代码行数:24,代码来源:BZip2.cs


示例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;
        }
开发者ID:stuartyK,项目名称:XmcdParser,代码行数:46,代码来源:Program.cs


示例16: DebArchiveInputStream

        public DebArchiveInputStream(Stream inputStream)
            : base(inputStream)
        {
            this.arIn = new ArArchiveInputStream (inputStream);

            ArArchiveEntry binary = arIn.GetNextArEntry ();
            if (!binary.Name.Equals ("debian-binary"))
            {
                // TODO Customize
                throw new IOException ("Invalid name, expected debian-binary, readed:" + binary.Name);
            }
            ArArchiveEntry control = arIn.GetNextArEntry ();
            if (!control.Name.Equals ("control.tar.gz"))
            {
                throw new IOException ("Invalid name, expected control.tar.gz, readed:" + control.Name);
            }
            ArArchiveEntry data = arIn.GetNextArEntry ();
            Stream compressedStream = null;
            if (data.Name.Equals ("data.tar.gz"))
            {
                compressedStream = new GZipStream (arIn, CompressionMode.Decompress);

            }
            else if (data.Name.Equals ("data.tar.bz2"))
            {
                compressedStream = new BZip2InputStream (arIn);
            }
            else if (data.Name.Equals ("data.tar.bz2"))
            {
                compressedStream = new LZMAInputStream (arIn);

            }
            else if (data.Name.Equals ("data.tar"))
            {
                compressedStream = arIn;
            }
            else
            {
                throw new IOException ("Unsupported compressed data:" + data.Name);
            }
            this.tarStream = new TarInputStream (compressedStream);
        }
开发者ID:albfernandez,项目名称:dalle,代码行数:42,代码来源:DebArchiveInputStream.cs


示例17: Decompress

		public static void Decompress(Stream inStream, Stream outStream) 
		{
			if ( inStream == null ) {
				throw new ArgumentNullException("inStream");
			}
			
			if ( outStream == null ) {
				throw new ArgumentNullException("outStream");
			}
			
			using ( outStream ) {
				using ( BZip2InputStream bzis = new BZip2InputStream(inStream) ) {
					int ch = bzis.ReadByte();
					while (ch != -1) {
						outStream.WriteByte((byte)ch);
						ch = bzis.ReadByte();
					}
				}
			}
		}
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:20,代码来源:BZip2.cs


示例18: ParseDisks

        private static void ParseDisks(BulkInsertOperation insert)
        {
            int i = 0;
            var parser = new Parser();
            var buffer = new byte[1024*1024];// more than big enough for all files

            using (var bz2 = new BZip2InputStream(File.Open(@"D:\Scratch\freedb-complete-20150101.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);
                        insert.Store(disk);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine();
                        Console.WriteLine(entry.Name);
                        Console.WriteLine(e);
                    }
                }
            }
        }
开发者ID:ayende,项目名称:XmcdParser,代码行数:41,代码来源:Program.cs


示例19: UnzipString

    public static string UnzipString(string compbytes)
    {
        string result;
        MemoryStream m_msBZip2 = null;
        BZip2InputStream m_isBZip2 = null;
        try
        {
            m_msBZip2 = new MemoryStream(Convert.FromBase64String(compbytes));
            // read final uncompressed string size stored in first 4 bytes
            //
            using (BinaryReader reader = new BinaryReader(m_msBZip2, System.Text.Encoding.ASCII))
            {
                Int32 size = reader.ReadInt32();

                m_isBZip2 = new BZip2InputStream(m_msBZip2);
                byte[] bytesUncompressed = new byte[size];
                m_isBZip2.Read(bytesUncompressed, 0, bytesUncompressed.Length);
                m_isBZip2.Close();
                m_msBZip2.Close();

                result = Encoding.ASCII.GetString(bytesUncompressed);

                reader.Close();
            }
        }
        finally
        {
            if (m_isBZip2 != null)
            {
                m_isBZip2.Dispose();
            }
            if (m_msBZip2 != null)
            {
                m_msBZip2.Dispose();
            }
        }
        return result;
    }
开发者ID:Raj2509,项目名称:net.kibotu.sandbox.unity.dragnslay,代码行数:38,代码来源:ZipString.cs


示例20: bz2read

        /// <summary>
        /// required for applying a binary patch
        /// </summary>
        private FileStream bz2read(ref BZip2InputStream bz, Int32 offset, string fname)
        {
            FileStream ReturnValue;
            FileStream fs;

            try
            {
                fs = new FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.Read);
                fs.Seek(offset, SeekOrigin.Begin);
                bz = new BZip2InputStream(fs);
                ReturnValue = fs;
            }
            catch (Exception e)
            {
                throw new Exception("Cannot open file " + fname + " for reading; " + e.Message);
            }
            return ReturnValue;
        }
开发者ID:js1987,项目名称:openpetragit,代码行数:21,代码来源:PatchTools.cs



注:本文中的ICSharpCode.SharpZipLib.BZip2.BZip2InputStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Checksums.Crc32类代码示例发布时间:2022-05-26
下一篇:
C# Project.Solution类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap