コード例 #1
0
ファイル: ShockwaveFlash.cs プロジェクト: proxymoron/Sulakore
        /// <summary>
        /// Stitches the Shockwave Flash(SWF) file header containing basic information, with the compressed/uncompressed content of the file.
        /// </summary>
        /// <param name="standard">The compression/decompression standard to use.</param>
        /// <param name="isCompressing">if set to <c>true</c> [is compressing].</param>
        /// <returns></returns>
        protected byte[] StitchFlashDataWithHeader(CompressionStandard standard, bool isCompressing)
        {
            if (isCompressing &&
                standard == CompressionStandard.None)
            {
                CompressWith = CompressionStandard.ZLIB;
                standard     = CompressWith;
            }

            var flashHeader = new byte[8];

            Buffer.BlockCopy(_flashData, 0, flashHeader, 0, 8);
            flashHeader[0] = (isCompressing ? (byte)standard : (byte)'F');

            var flashBody = new byte[_flashData.Length - 8];

            Buffer.BlockCopy(_flashData, 8, flashBody, 0, flashBody.Length);

            byte[] body = null;
            switch (standard)
            {
            default:
            {
                throw new InvalidOperationException(
                          "Invalid compression/decompression standard was specified: " + standard);
            }

            case CompressionStandard.ZLIB:
            {
                if (isCompressing)
                {
                    body = ZlibStream.CompressBuffer(flashBody);
                }
                if (!isCompressing)
                {
                    body = ZlibStream.UncompressBuffer(flashBody);
                }
                break;
            }

            case CompressionStandard.LZMA:
            {
                if (isCompressing)
                {
                    body = LZMA.CompressBuffer(flashBody);
                }
                if (!isCompressing)
                {
                    body = LZMA.DecompressBuffer(flashBody, (int)FileLength - 8);
                }
                break;
            }
            }

            var buffer = new byte[8 + body.Length];

            Buffer.BlockCopy(flashHeader, 0, buffer, 0, 8);
            Buffer.BlockCopy(body, 0, buffer, 8, body.Length);
            return(buffer);
        }
コード例 #2
0
ファイル: ShockwaveFlash.cs プロジェクト: SirJamal/Sulakore
        /// <summary>
        /// Stitches the Shockwave Flash(SWF) file header containing basic information, with the compressed/uncompressed content of the file. 
        /// </summary>
        /// <param name="standard">The compression/decompression standard to use.</param>
        /// <param name="isCompressing">if set to <c>true</c> [is compressing].</param>
        /// <returns></returns>
        protected byte[] StitchFlashDataWithHeader(CompressionStandard standard, bool isCompressing)
        {
            if (isCompressing &&
                standard == CompressionStandard.None)
            {
                CompressWith = CompressionStandard.ZLIB;
                standard = CompressWith;
            }

            var flashHeader = new byte[8];
            Buffer.BlockCopy(_flashData, 0, flashHeader, 0, 8);
            flashHeader[0] = (isCompressing ? (byte)standard : (byte)'F');

            var flashBody = new byte[_flashData.Length - 8];
            Buffer.BlockCopy(_flashData, 8, flashBody, 0, flashBody.Length);

            byte[] body = null;
            switch (standard)
            {
                default:
                {
                    throw new InvalidOperationException(
                        "Invalid compression/decompression standard was specified: " + standard);
                }
                case CompressionStandard.ZLIB:
                {
                    if (isCompressing) body = ZlibStream.CompressBuffer(flashBody);
                    if (!isCompressing) body = ZlibStream.UncompressBuffer(flashBody);
                    break;
                }
                case CompressionStandard.LZMA:
                {
                    if (isCompressing) body = LZMA.CompressBuffer(flashBody);
                    if (!isCompressing) body = LZMA.DecompressBuffer(flashBody, (int)FileLength - 8);
                    break;
                }
            }

            var buffer = new byte[8 + body.Length];
            Buffer.BlockCopy(flashHeader, 0, buffer, 0, 8);
            Buffer.BlockCopy(body, 0, buffer, 8, body.Length);
            return buffer;
        }