Example #1
0
 public static void Write(this IEncodingOutputStream @this, long value)
 {
     for (int n = 0; n < 8; n++)
     {
         Write(@this, (byte)value);
         value >>= 8;
     }
 }
Example #2
0
 public static void Write(this IEncodingOutputStream @this, char symbol)
 {
     for (int n = 0; n < 2; n++)
     {
         Write(@this, (byte)symbol);
         symbol >>= 8;
     }
 }
Example #3
0
 public static void Write(this IEncodingOutputStream @this, byte value)
 {
     for (int n = 0; n < 8; n++)
     {
         @this.WriteBit((value & 1) == 1 ? Bit.One : Bit.Zero);
         value >>= 1;
     }
 }
Example #4
0
        public void Initialize(IPlatformService platform, EncodingToken encodingToken, IEncodingOutputStream stream)
        {
            Guard.IsNotNull(platform, nameof(platform));
            Guard.IsNotNull(encodingToken, nameof(encodingToken));
            Guard.IsNotNull(stream, nameof(stream));

            this.platform      = platform;
            this.encodingToken = encodingToken;
            this.stream        = stream;
            this.encoder       = new HuffmanEncoder();
        }
        public long Encode(IEncodingInputStream inputStream, IEncodingOutputStream outputStream, EncodingToken encodingToken, CancellationToken cancellationToken, IProgressHandler progress)
        {
            Guard.IsNotNull(inputStream, nameof(inputStream));
            Guard.IsNotNull(outputStream, nameof(outputStream));
            Guard.IsNotNull(encodingToken, nameof(encodingToken));

            CodingTable codingTable = encodingToken.CodingTable;

            inputStream.Reset();
            long sequenceLength = 0;
            long progressValue  = progress?.State.CastTo <CodingProgressState>()?.Value ?? 0;

            while (inputStream.ReadSymbol(out byte symbol))
            {
                BitSequence codingSequence = codingTable[symbol];
                for (int n = 0; n < codingSequence.Size; n++)
                {
                    Bit bit = codingSequence[n];
                    sequenceLength++;
                    outputStream.WriteBit(bit);
                }
                // Throttling
                if (++progressValue == ChunkSize)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    progress?.Report(ChunkSize, inputStream.Path);
                    progressValue = 0;
                }
            }
            if (progress != null)
            {
                CodingProgressState progressState = (CodingProgressState)progress.State ?? new CodingProgressState();
                progress.State = progressState.WithValue(progressValue);
            }
            return(sequenceLength);
        }
Example #6
0
 public static void Write(this IEncodingOutputStream @this, StreamKind value)
 {
     Write(@this, (byte)value);
 }
 void IStreamBuilder.Initialize(IPlatformService platform, EncodingToken encodingToken, IEncodingOutputStream stream)
 {
     Trace += "->Initialize;";
 }