public override void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodingProgress progress = null) { if (_disposed) { throw new ObjectDisposedException(nameof(SynchronizedStreamConnector)); } this.Reset(); _externalProgress = progress; if (_coders.Length > 1) { this.CreateAllCodingThreads(inStream, outStream, inSize, outSize); foreach (var t in _threads) { t.Thread.Start(); } var allFinishedEvents = _threads.Select(t => t.Info.FinishedEvent.WaitHandle).ToArray(); WaitHandle.WaitAll(allFinishedEvents); } else { _coders.First().Code(inStream, outStream, inSize, outSize, progress); } }
private void Reset() { if (_disposed) { throw new ObjectDisposedException(nameof(SynchronizedStreamConnector)); } _externalProgress = null; _processedInSize = 0; _processedOutSize = 0; if (_connections != null) { foreach (var connector in _connections) { connector.Reset(); } } }
public override void Code(System.IO.Stream inStream, System.IO.Stream outStream, Int64 inSize, Int64 outSize, ICodingProgress progress) { if (outSize < 0) { throw new ArgumentOutOfRangeException(nameof(outSize), "outSize must be grater than 0. outSize is the uncompressed size of inStream."); } Init(inStream, outStream); LzmaBase.State state = new LzmaBase.State(); state.Init(); uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; UInt64 nowPos64 = 0; UInt64 outSize64 = (UInt64)outSize; if (nowPos64 < outSize64) { if (m_IsMatchDecoders[state.Index << LzmaBase.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0) { throw new DataErrorException(); } state.UpdateChar(); byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0); m_OutWindow.PutByte(b); nowPos64++; } while (nowPos64 < outSize64) { // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64); // while(nowPos64 < next) { uint posState = (uint)nowPos64 & m_PosStateMask; if (m_IsMatchDecoders[(state.Index << LzmaBase.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) { byte b; byte prevByte = m_OutWindow.GetByte(0); if (!state.IsCharState()) { b = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder, (uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0)); } else { b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte); } m_OutWindow.PutByte(b); state.UpdateChar(); nowPos64++; } else { uint len; if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) { if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) { if (m_IsRep0LongDecoders[(state.Index << LzmaBase.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) { state.UpdateShortRep(); m_OutWindow.PutByte(m_OutWindow.GetByte(rep0)); nowPos64++; continue; } } else { UInt32 distance; if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep1; } else { if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep2; } else { distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + LzmaBase.kMatchMinLen; state.UpdateRep(); } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; len = LzmaBase.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState); state.UpdateMatch(); uint posSlot = m_PosSlotDecoder[LzmaBase.GetLenToPosState(len)].Decode(m_RangeDecoder); if (posSlot >= LzmaBase.kStartPosModelIndex) { int numDirectBits = (int)((posSlot >> 1) - 1); rep0 = ((2 | (posSlot & 1)) << numDirectBits); if (posSlot < LzmaBase.kEndPosModelIndex) { rep0 += RangeBitTreeDecoder.ReverseDecode(m_PosDecoders, rep0 - posSlot - 1, m_RangeDecoder, numDirectBits); } else { rep0 += (m_RangeDecoder.DecodeDirectBits( numDirectBits - LzmaBase.kNumAlignBits) << LzmaBase.kNumAlignBits); rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); } } else { rep0 = posSlot; } } if (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck) { if (rep0 == 0xFFFFFFFF) { break; } throw new DataErrorException(); } m_OutWindow.CopyBlock(rep0, len); nowPos64 += len; } } } m_OutWindow.Flush(); m_OutWindow.ReleaseStream(); m_RangeDecoder.ReleaseStream(); }
public override void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodingProgress progress = null) { var inBuf = new byte[DefaultBlockSize]; var outBuf = new byte[inBuf.Length]; _bucket = new int[inBuf.Length]; long processedSize = 0; for (; ;) { var nRead = inStream.Read(inBuf, 0, inBuf.Length); if (nRead == 0) { break; } processedSize += nRead; var primaryIndex = this.EncodeBlock(inBuf, outBuf, nRead); outStream.Write(outBuf, 0, nRead); if (progress != null) { progress.Report(new CodingProgressInfo(processedSize, processedSize)); } } }
public abstract void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodingProgress progress = null);
public CodingThreadInfo(ICoder coder, Stream inStream, Stream outStream, long inSize, long outSize, ICodingProgress progress = null) { this.Coder = coder; this.InStream = inStream; this.OutStream = outStream; this.Progress = progress; this.InSize = inSize; this.OutSize = outSize; this.FinishedEvent = new ManualResetEventSlim(false); }
public override void Code(Stream inStream, Stream outStream, long inSize = -1, long outSize = -1, ICodingProgress progress = null) { long processedSize = 0; for (; ;) { var nRead = inStream.Read(_buffer.Value, 0, _buffer.Value.Length); if (nRead == 0) { break; } outStream.Write(_buffer.Value, 0, nRead); processedSize += nRead; if (progress != null) { progress.Report(new CodingProgressInfo(processedSize, processedSize)); } } }
public static async Task CodeAsync(this ICoder self, Stream inStream, Stream outStream, long inSize, long outSize, ICodingProgress progress = null) { await Task.Factory.StartNew(() => self.Code(inStream, outStream, inSize, outSize, progress)) .ConfigureAwait(false); }
public override void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodingProgress progress = null) { throw new NotImplementedException(); }