Exemplo n.º 1
0
        /// <summary>
        /// Feeds a fragment of Base-32 encoded string into the pipe.
        /// </summary>
        /// <param name="fragment">String fragment.</param>
        /// <param name="final">True if this is the last fragment.</param>
        public void FeedFragment(string fragment, bool final = false)
        {
            _builder.Append(fragment);

            var finished = Base32Core.MarkupBlocks(ref _block, _accumulator, fragment, final);

            if (finished)
            {
                var codeLength = _accumulator.Sum(x => x.CodeLength);

                var input  = _builder.ToString();
                var output = Base32Core.DecodeBlockSequence(input, _accumulator);

                var unfinished = input.Substring(codeLength, input.Length - codeLength);

                _builder.Clear();
                _builder.Append(unfinished);
                _accumulator.Clear();

                //
                // Now feed output to the handler
                //
                _handler(output);
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override void Write(byte[] buffer, int offset, int count)
        {
            var bytes = new byte[count];

            Array.Copy(buffer, offset, bytes, 0, count);

            var encoded      = Base32Core.ToBase32String(bytes);
            var encodedBytes = Encoding.UTF8.GetBytes(encoded);

            _underlyingStream.Write(encodedBytes, 0, encodedBytes.Length);
        }