ComponentAce.Compression.Libs.zlib.ZInputStream.read C# (CSharp) Method

read() public method

public read ( byte b, int off, int len ) : int
b byte
off int
len int
return int
        public int read(byte[] b, int off, int len)
        {
            if (len == 0)
                return (0);
            int err;
            z.next_out = b;
            z.next_out_index = off;
            z.avail_out = len;
            do
            {
                if ((z.avail_in == 0) && (!nomoreinput))
                {
                    // if buffer is empty and more input is avaiable, refill it
                    z.next_in_index = 0;
                    z.avail_in = SupportClass.ReadInput(in_Renamed, buf, 0, bufsize); //(bufsize<z.avail_out ? bufsize : z.avail_out));
                    if (z.avail_in == - 1)
                    {
                        z.avail_in = 0;
                        nomoreinput = true;
                    }
                }
                if (compress)
                    err = z.deflate(flush);
                else
                    err = z.inflate(flush);
                if (nomoreinput && (err == zlibConst.Z_BUF_ERROR))
                    return (- 1);
                if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END)
                    throw new ZStreamException((compress?"de":"in") + "flating: " + z.msg);
                if (nomoreinput && (z.avail_out == len))
                    return (- 1);
            }
            while (z.avail_out == len && err == zlibConst.Z_OK);
            //System.err.print("("+(len-z.avail_out)+")");
            return (len - z.avail_out);
        }

Usage Example

コード例 #1
0
ファイル: ResourcePack.cs プロジェクト: ishani/InSiDe
        //
        public bool Load(String filename)
        {
            Console.WriteLine("ResourcePack::Load - {0}", filename);
              using (FileStream fs = File.Open(filename, FileMode.Open))
              {
            byte[] unpackBuffer = null;

            using (BinaryReader br = new BinaryReader(fs))
            {
              UInt32 sizeUncompressed = ByteUtils.SwapUInt32(br.ReadUInt32());
              unpackBuffer = new byte[sizeUncompressed];

              byte[] packedBuf = new byte[br.BaseStream.Length - 4];
              br.Read(packedBuf, 0, packedBuf.Length);

              Console.WriteLine("  ... uncompressed size is {0}", sizeUncompressed);
              using (MemoryStream ms = new MemoryStream(packedBuf))
              {
            using (ZInputStream zStream = new ZInputStream(ms))
            {
              Int32 bOffset = 0;
              while (bOffset < sizeUncompressed)
              {
                Int32 decS = zStream.read(unpackBuffer, bOffset, (Int32)sizeUncompressed - bOffset);
                bOffset += decS;
              }
            }
              }

            }
            fs.Close();

            using (MemoryStream ms = new MemoryStream(unpackBuffer))
            {
              using (BinaryReader ir = new BinaryReader(ms))
              {
            UInt32 numChunks = ByteUtils.SwapUInt32(ir.ReadUInt32());
            Console.WriteLine("  ... processing {0} chunks", numChunks);
            for (UInt32 i = 0; i < numChunks; i++)
            {
              String componentTypeName = ByteUtils.readNullTermString11(ir);
              UID componentUID = new UID(ir.ReadBytes(6));
              String componentName = ByteUtils.readNullTermString11(ir);

              UInt32 componentDataLength = ByteUtils.SwapUInt32(ir.ReadUInt32());

              // go see if we know how to build a component from this data type
              Type typeToBuild = null;
              if (mComponentFactory.TryGetValue(componentTypeName, out typeToBuild))
              {
                // yes; so instantiate the returned type
                SiDComponent newComponent = Activator.CreateInstance(typeToBuild) as SiDComponent;
                newComponent.Name = componentName;

                // ask it to load from the bytestream
                newComponent.LoadFromByteStream(ir, (Int32)componentDataLength);

                // record it
                if (!Add(newComponent))
                {
                  Console.WriteLine("Warning! duplicate item in single resource pack? {0}", componentUID);
                }

                Console.WriteLine("    + {0}:{1}: - {2}", componentUID, SiDComponent.getResourceTypeName(typeToBuild), newComponent.Name);
              }
              else
              {
                // we don't know how to construct this type; store as a 'black box' blob
                Blob newBlob = new Blob(componentTypeName);
                newBlob.Name = componentName;

                // blobs just hold onto the data as raw bytes, ready to parrot it back out on Save
                newBlob.LoadFromByteStream(ir, (Int32)componentDataLength);

                // record it
                if (!Add(newBlob))
                {
                  Console.WriteLine("Warning! duplicate (blob) item in single resource pack? {0}", componentUID);
                }

                Console.WriteLine("    + {0}:{1}:BLOB: - {2}", componentUID, componentTypeName, componentName);
              }
            }
              }
            }

              }

              return true;
        }
All Usage Examples Of ComponentAce.Compression.Libs.zlib.ZInputStream::read