当前位置: 首页>>代码示例>>C#>>正文


C# InflaterInputStream.ReadByte方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# InflaterInputStream.ReadByte方法的具体用法?C# InflaterInputStream.ReadByte怎么用?C# InflaterInputStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream的用法示例。


在下文中一共展示了InflaterInputStream.ReadByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Decompress

        /// <summary>
        /// Decompresses the specified data.
        /// </summary>
        /// <param name="data">The compressed byte array.</param>
        /// <param name="pos">The starting position into the byte array.</param>
        /// <param name="Length">The number of compressed bytes to decompress.</param>
        /// <returns>An uncompressed byte array</returns>
        public static byte[] Decompress(byte[] data, int pos, int Length)
        {
            byte[] compressedData = new byte[Length];
            Array.Copy(data, pos + 50, compressedData, 0, Length);
            using (MemoryStream ms = new MemoryStream(compressedData))
            {
                Inflater inflater = new Inflater(false);

                using (InflaterInputStream zIn = new InflaterInputStream(ms, inflater))
                {
                    using (MemoryStream out1 = new MemoryStream())
                    {
                        int c;
                        try
                        {
                            while ((c = zIn.ReadByte()) != -1)
                                out1.WriteByte((byte)c);
                            return out1.ToArray();
                        }
                        catch (IOException e)
                        {
                            throw new RecordFormatException(e.ToString());
                        }
                    }
                }
            }
        }
开发者ID:xiepeixing,项目名称:npoi,代码行数:34,代码来源:EscherBlipWMFRecord.cs

示例2: ReadScanlines

        private void ReadScanlines(MemoryStream dataStream, byte[] pixels, IColorReader colorReader, PngColorTypeInformation colorTypeInformation)
        {
            dataStream.Position = 0;

            int scanlineLength = CalculateScanlineLength(colorTypeInformation);

            int scanlineStep = CalculateScanlineStep(colorTypeInformation);

            byte[] lastScanline = new byte[scanlineLength];
            byte[] currScanline = new byte[scanlineLength];

            byte a = 0;
            byte b = 0;
            byte c = 0;

            int row = 0, filter = 0, column = -1;

            using (InflaterInputStream compressedStream = new InflaterInputStream(dataStream))
            {
                int readByte = 0;
                while ((readByte = compressedStream.ReadByte()) >= 0)
                {
                    if (column == -1)
                    {
                        filter = readByte;

                        column++;
                    }
                    else
                    {
                        currScanline[column] = (byte)readByte;

                        if (column >= scanlineStep)
                        {
                            a = currScanline[column - scanlineStep];
                            c = lastScanline[column - scanlineStep];
                        }
                        else 
                        {
                            a = 0;
                            c = 0;
                        }

                        b = lastScanline[column];

                        if (filter == 1)
                        {
                            currScanline[column] = (byte)(currScanline[column] + a);
                        }
                        else if (filter == 2)
                        {
                            currScanline[column] = (byte)(currScanline[column] + b);
                        }
                        else if (filter == 3)
                        {
                            currScanline[column] = (byte)(currScanline[column] + (byte)Math.Floor((a + b) / 2d));
                        }
                        else if (filter == 4)
                        {
                            currScanline[column] = (byte)(currScanline[column] + PaethPredicator(a, b, c)); 
                        }

                        column++;

                        if (column == scanlineLength)
                        {
                            colorReader.ReadScanline(currScanline, pixels, _header);

                            column = -1;
                            row++;

                            Extensions.Swap(ref currScanline, ref lastScanline);
                        }
                    }
                }
            }
        }
开发者ID:lPinchol,项目名称:Reign-Unity-Plugin,代码行数:77,代码来源:PngDecoder.cs

示例3: GetObjectLoose

        private Object GetObjectLoose(string aId)
        {
            var path = Path.Combine(iFolderObjects.FullName, aId.Substring(0, 2), aId.Substring(2, 38));

            try
            {
                var file = File.OpenRead(path);

                using (var inflater = new InflaterInputStream(file))
                {
                    int offset = 0;

                    byte[] header = new byte[100];

                    while (true)
                    {
                        int b = inflater.ReadByte();

                        if (b == 0)
                        {
                            break;
                        }

                        if (offset >= 100)
                        {
                            throw (new GitException("Illegal object header " + aId));
                        }

                        header[offset++] = (byte)b;
                    }

                    string[] parts = ASCIIEncoding.ASCII.GetString(header, 0, offset).Split(new char[] { ' ' });

                    if (parts.Length != 2)
                    {
                        throw (new GitException("Illegal object header " + aId));
                    }

                    int length;

                    if (!int.TryParse(parts[1], out length))
                    {
                        throw (new GitException("Illegal object length " + aId));
                    }

                    byte[] bytes = new byte[length];

                    inflater.Read(bytes, 0, length);

                    switch (parts[0])
                    {
                        case "commit":
                            return (new Object(EObjectType.Commit, bytes));
                        case "tag":
                            return (new Object(EObjectType.Tag, bytes));
                        case "tree":
                            return (new Object(EObjectType.Tree, bytes));
                        case "blob":
                            return (new Object(EObjectType.Blob, bytes));
                        default:
                            throw (new GitException("Unrecognised object type " + aId));
                    }
                }
            }
            catch (FileNotFoundException)
            {
                return (null);
            }
        }
开发者ID:openhome,项目名称:ohGit,代码行数:69,代码来源:Repository.cs

示例4: readLooseObject

        Tuple<PackObjectType, byte[]> readLooseObject(FileInfo objectFi)
        {
            ObjectId objId = ObjectId.Parse(objectFi.Directory.Name + objectFi.Name);

            var sha = SHA1.Create();
            string tag;
            byte[] objectContents;

            using (var fs = objectFi.OpenRead())
            {
                //TODO: apply some not-invented-here syndrom by reimplmenting inflate
                using (var inflater = new InflaterInputStream(fs))
                {
                    int? spaceNdx = null;
                    int headerBytesRead = 0;
                    byte[] headerBytes = new byte[30]; //should be enough for a 64-bit size
                    while (true)
                    {
                        int b = inflater.ReadByte();
                        if (b == -1)
                            throw new Exception("Unexpected EOF");

                        headerBytes[headerBytesRead] = (byte)b;

                        if (b == ' ')
                            spaceNdx = headerBytesRead;

                        headerBytesRead++;

                        if (b == 0)
                            break;

                        if (headerBytesRead == headerBytes.Length)
                            throw new Exception("Header too big.");
                    }
                    if (!spaceNdx.HasValue)
                        throw new Exception("Did not find space.");

                    //split the string along the space to get the object type and size and size
                    tag = Encoding.ASCII.GetString(headerBytes, 0, spaceNdx.Value);
                    string sizeStr = Encoding.ASCII.GetString(headerBytes, spaceNdx.Value + 1, headerBytesRead - spaceNdx.Value - 2);
                    int objectSize = int.Parse(sizeStr, NumberStyles.None, CultureInfo.InvariantCulture);
                    objectContents = new byte[objectSize];
                    if (inflater.Read(objectContents, 0, objectSize) != objectSize)
                        throw new Exception("Short read.");

                    sha.TransformBlock(headerBytes, 0, headerBytesRead, null, 0);
                }
            }

            sha.TransformFinalBlock(objectContents, 0, objectContents.Length);
            if (!objId.Equals(new ObjectId(sha.Hash)))
                throw new Exception("Hash is not right!");

            PackObjectType objType;
            switch (tag)
            {
                case "blob":
                    objType = PackObjectType.Blob;
                    break;
                case "commit":
                    objType = PackObjectType.Commit;
                    break;
                case "tree":
                    objType = PackObjectType.Tree;
                    break;
                case "tag":
                    objType = PackObjectType.Tag;
                    break;
                default:
                    throw new Exception("Unrecognized object type: " + tag);
            }

            return new Tuple<PackObjectType, byte[]>(objType, objectContents);
        }
开发者ID:AustinWise,项目名称:GitInCSharp,代码行数:75,代码来源:Repo.cs

示例5: Decompress

 /// <summary>
 /// Decompresses the specified data.
 /// </summary>
 /// <param name="data">The compressed byte array.</param>
 /// <param name="pos">The starting position into the byte array.</param>
 /// <param name="Length">The number of compressed bytes to decompress.</param>
 /// <returns>An uncompressed byte array</returns>
 public static byte[] Decompress(byte[] data, int pos, int Length)
 {
     byte[] compressedData = new byte[Length];
     Array.Copy(data, pos + 50, compressedData, 0, Length);
     Stream compressedInputStream = new MemoryStream(compressedData);
     InflaterInputStream inflaterInputStream = new InflaterInputStream(compressedInputStream);
     MemoryStream out1 = new MemoryStream();
     int c;
     try
     {
         while ((c = inflaterInputStream.ReadByte()) != -1)
             out1.WriteByte((byte)c);
     }
     catch (IOException e)
     {
         throw new RecordFormatException(e.ToString());
     }
     return out1.ToArray();
 }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:26,代码来源:EscherBlipWMFRecord.cs


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