예제 #1
0
        /// <summary>
        /// Creates an FDAT Chunk from an IDAT Chunk.
        /// </summary>
        /// <returns>The FDAT chunk.</returns>
        /// <param name="idatChunk">IDAT chunk.</param>
        /// <param name="sequenceNumber">Sequence number.</param>
        public static fdATChunk FromIDATChunk(IDATChunk idatChunk, uint sequenceNumber)
        {
            uint newCrc;

            byte[]    frameData;
            fdATChunk fdat = null;

            using (var msCrc = new MemoryStream())
            {
                msCrc.WriteBytes(new[] { (byte)'f', (byte)'d', (byte)'A', (byte)'T' });
                byte[] seqNum = BitConverter.GetBytes(Helper.ConvertEndian(sequenceNumber));
                frameData = new byte[seqNum.Length + idatChunk.ChunkData.Length];
                Buffer.BlockCopy(seqNum, 0, frameData, 0, seqNum.Length);
                Buffer.BlockCopy(idatChunk.ChunkData, 0, frameData, seqNum.Length, idatChunk.ChunkData.Length);
                msCrc.WriteBytes(frameData);

                newCrc = CrcHelper.Calculate(msCrc.ToArray());
            }

            using (var ms = new MemoryStream())
            {
                ms.WriteUInt32((uint)Helper.ConvertEndian(idatChunk.ChunkData.Length + 4));
                ms.WriteBytes(new[] { (byte)'f', (byte)'d', (byte)'A', (byte)'T' });
                ms.WriteBytes(frameData);
                ms.WriteUInt32(Helper.ConvertEndian(newCrc));
                ms.Position = 0;

                fdat = new fdATChunk(ms);
            }

            return(fdat);
        }
예제 #2
0
        /// <summary>
        /// Modify the ChunkData part.
        /// </summary>
        public void ModifyChunkData(int postion, byte[] newData)
        {
            Array.Copy(newData, 0, ChunkData, postion, newData.Length);

            using (var msCrc = new MemoryStream())
            {
                msCrc.WriteBytes(Encoding.ASCII.GetBytes(ChunkType));
                msCrc.WriteBytes(ChunkData);

                Crc = CrcHelper.Calculate(msCrc.ToArray());
            }
        }
예제 #3
0
        /// <summary>
        /// Converts an FDAT Chunk to an IDAT Chunk.
        /// </summary>
        /// <returns>The IDAT chunk.</returns>
        public IDATChunk ToIDATChunk()
        {
            uint newCrc;

            using (var msCrc = new MemoryStream())
            {
                msCrc.WriteBytes(new[] { (byte)'I', (byte)'D', (byte)'A', (byte)'T' });
                msCrc.WriteBytes(FrameData);

                newCrc = CrcHelper.Calculate(msCrc.ToArray());
            }

            using (var ms = new MemoryStream())
            {
                ms.WriteUInt32(Helper.ConvertEndian(Length - 4));
                ms.WriteBytes(new[] { (byte)'I', (byte)'D', (byte)'A', (byte)'T' });
                ms.WriteBytes(FrameData);
                ms.WriteUInt32(Helper.ConvertEndian(newCrc));
                ms.Position = 0;

                return(new IDATChunk(ms));
            }
        }