Пример #1
0
        /// <summary>
        /// Extracts the original image to a stream.
        /// </summary>
        /// <param name="output">A binary writer to the stream.</param>
        public void ExtractOriginalImage(Stream output)
        {
            PiggStream   p_stream = new PiggStream(this.LeafInfo);
            BinaryReader reader   = new BinaryReader(p_stream);

            PiggTextureHeader header = this.Header;
            int block_size           = 0x1000; // Read four kilobytes at a time
            int bytes_read;

            do
            {
                byte[] buffer = new byte[block_size];
                bytes_read = p_stream.Read(buffer, 0, block_size);
                if (bytes_read > 0)
                {
                    output.Write(buffer, 0, bytes_read);
                }
            } while (bytes_read > 0);
        }
Пример #2
0
        /// <summary>
        /// Extracts an embedded file using the information contained within the
        /// PiggLeafInfo structure.
        /// </summary>
        /// <param name="output">Stream to which file information is saved.
        /// </param>
        /// <returns>The total number of bytes written to the stream.</returns>
        public int Extract(Stream output)
        {
            PiggStream p_stream   = new PiggStream(this);
            int        block_size = 0x1000;

            byte[] bytes         = new byte[block_size];
            int    total_bytes   = 0;
            bool   end_of_stream = false;

            while (end_of_stream == false)
            {
                int bytes_read = p_stream.Read(bytes, 0, block_size);
                total_bytes += bytes_read;
                if (bytes_read > 0)
                {
                    output.Write(bytes, 0, bytes_read);
                }
                else
                {
                    end_of_stream = true;
                }
            }
            return(total_bytes);
        }