示例#1
0
        /// <summary>
        /// 解压原始数据流
        /// </summary>
        /// <param name="pOut">要输出的目的流</param>
        public void ExtractStreamTo(Stream pOut)
        {
            if (m_Stream == null)
            {
                // 来自数据包内的流
                Stream tBaseStream = m_Package.BaseStream;

                // 寻址到数据开始处
                tBaseStream.Seek(FCYResPackage.HeaderSize + DataOffset, SeekOrigin.Begin);

                // 是否压缩
                if (IsCompressed)
                {
                    // 已压缩,解压到目的流
                    FCYResPackageHelper.DeflateDecodeTo(tBaseStream, pOut, (int)DataRealSize);
                }
                else
                {
                    // 直接输出到目标流
                    FCYResPackageHelper.FillStream(tBaseStream, pOut, (int)DataRealSize);
                }
            }
            else // 来自本地的数据流
            {
                // 直接输出到目标流
                FCYResPackageHelper.FillStream(m_Stream, pOut, (int)DataRealSize);
            }
        }
示例#2
0
        internal override void WriteToStream(Stream pOut, XmlElement ParentXml)
        {
            // 记下当前位置
            long tPos = pOut.Position;

            // 是否是外部流
            if (m_Stream == null)
            {
                // 外部流
                Stream tBaseStream = m_Package.BaseStream;

                // 寻址
                tBaseStream.Seek(FCYResPackage.HeaderSize + m_MainDataOffset, SeekOrigin.Begin);

                // 直接复制
                FCYResPackageHelper.FillStream(tBaseStream, pOut, (int)(IsCompressed ? DataCompressedSize : DataRealSize));
            }
            else
            {
                // 内部流
                if (IsCompressed)
                {
                    long tPosStart = pOut.Position;

                    // 压缩流
                    m_Stream.Seek(0, SeekOrigin.Begin);
                    FCYResPackageHelper.DeflateEncodeTo(m_Stream, pOut, (int)DataRealSize);

                    long tPosEnd = pOut.Position;

                    // 关闭内部流
                    m_Stream.Close();
                    m_Stream = null;

                    // 更新数据
                    m_DataCompressedSize = (uint)(tPosEnd - tPosStart);
                }
                else
                {
                    // 直接复制
                    m_Stream.Seek(0, SeekOrigin.Begin);
                    FCYResPackageHelper.FillStream(m_Stream, pOut, (int)DataRealSize);
                }
            }

            // 更新位置
            m_MainDataOffset = (uint)tPos - FCYResPackage.HeaderSize;

            // 准备Xml数据
            XmlElement tElement = ParentXml.OwnerDocument.CreateElement("Node");

            tElement.SetAttribute("Name", Name);
            tElement.SetAttribute("OrgSize", DataRealSize.ToString());
            tElement.SetAttribute("IsCompressed", IsCompressed ? "yes" : "no");
            tElement.SetAttribute("CompressedSize", DataCompressedSize.ToString());
            tElement.SetAttribute("Offset", DataOffset.ToString());
            tElement.InnerText = AdditionData;

            // 写出Xml数据
            ParentXml.AppendChild(tElement);
        }