Esempio n. 1
0
        private static DataStream Compress(DataStream inputDataStream, CompressorParameters parameters)
        {
            DataStream outputDataStream = DataStreamFactory.FromMemory();
            var        writer           = new DataWriter(outputDataStream)
            {
                DefaultEncoding = Encoding.ASCII,
            };

            if (parameters == null)
            {
                parameters = new CompressorParameters
                {
                    Version    = 0x01,
                    Endianness = 0x00,
                };
            }

            writer.Endianness = parameters.Endianness == 0 ? EndiannessMode.LittleEndian : EndiannessMode.BigEndian;
            writer.Write("SLLZ", false);
            writer.Write(parameters.Endianness);
            writer.Write(parameters.Version);
            writer.Write((ushort)0x10); // Header size
            writer.Write((int)inputDataStream.Length);
            writer.Stream.PushCurrentPosition();
            writer.Write(0x00000000); // Compressed size

            DataStream compressedDataStream;

            if (parameters.Version == 1)
            {
                compressedDataStream = CompressV1(inputDataStream);
            }
            else if (parameters.Version == 2)
            {
                if (inputDataStream.Length < 0x1B)
                {
                    throw new FormatException($"SLLZv2: Input size must more than 0x1A.");
                }

                compressedDataStream = CompressV2(inputDataStream);
            }
            else
            {
                throw new FormatException($"SLLZ: Unknown compression version {parameters.Version}.");
            }

            compressedDataStream.WriteTo(outputDataStream);
            writer.Stream.PopPosition();
            writer.Write((int)(compressedDataStream.Length + 0x10)); // data + header

            compressedDataStream.Dispose();

            return(outputDataStream);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes the compressor parameters.
 /// </summary>
 /// <param name="parameters">Compressor configuration.</param>
 public void Initialize(CompressorParameters parameters)
 {
     this.compressorParameters = parameters;
 }