Exemplo n.º 1
0
        public void SetUp()
        {
            byte[] dataToEncode = System.Text.Encoding.ASCII.GetBytes("ABABBA");
            inputStream = new MemoryStream(dataToEncode);
            outputStream = new MemoryStream();

            var input = new StreamEncoderInput(inputStream);
            var output = new StreamEncoderOutput(outputStream);
            var codeTable = new FrameworkDictionaryCodeTable(4000);
            target = new LzwEncoder(input, output, codeTable);
        }
        private static void Encode(Stream inputStream, Stream outputStream)
        {
            var encoderInput = new StreamEncoderInput(inputStream);
            var encoderOutput = new StreamEncoderOutput(outputStream);
            var codeTable = new FrameworkDictionaryCodeTable(1000);
            var encoder = new LzwEncoder(encoderInput, encoderOutput, codeTable);

            encoder.Encode();
            outputStream.Flush();
            outputStream.Seek(0, SeekOrigin.Begin);
        }
        private byte[] Encode(byte[] dataToEncode)
        {
            using(var encoderInputStream = new MemoryStream(dataToEncode))
            {
                using(var encoderOutputStream = new MemoryStream())
                {
                    var input = new StreamEncoderInput(encoderInputStream);
                    var output = new StreamEncoderOutput(encoderOutputStream);
                    ICodeTable codeTable = new FrameworkDictionaryCodeTable(10000);
                    var encoder = new LzwEncoder(input, output, codeTable);

                    encoder.Encode();

                    return encoderOutputStream.ToArray();
                }
            }
        }