3 namespace SevenZip.Compression.LZ
11 System.IO.Stream _stream;
13 public uint TrainSize = 0;
15 public void Create(uint windowSize)
17 if (_windowSize != windowSize)
19 // System.GC.Collect();
20 _buffer = new byte[windowSize];
22 _windowSize = windowSize;
27 public void Init(System.IO.Stream stream, bool solid)
39 public bool Train(System.IO.Stream stream)
41 long len = stream.Length;
42 uint size = (len < _windowSize) ? (uint)len : _windowSize;
44 stream.Position = len - size;
45 _streamPos = _pos = 0;
48 uint curSize = _windowSize - _pos;
51 int numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);
52 if (numReadBytes == 0)
54 size -= (uint)numReadBytes;
55 _pos += (uint)numReadBytes;
56 _streamPos += (uint)numReadBytes;
57 if (_pos == _windowSize)
58 _streamPos = _pos = 0;
63 public void ReleaseStream()
71 uint size = _pos - _streamPos;
74 _stream.Write(_buffer, (int)_streamPos, (int)size);
75 if (_pos >= _windowSize)
80 public void CopyBlock(uint distance, uint len)
82 uint pos = _pos - distance - 1;
83 if (pos >= _windowSize)
85 for (; len > 0; len--)
87 if (pos >= _windowSize)
89 _buffer[_pos++] = _buffer[pos++];
90 if (_pos >= _windowSize)
95 public void PutByte(byte b)
98 if (_pos >= _windowSize)
102 public byte GetByte(uint distance)
104 uint pos = _pos - distance - 1;
105 if (pos >= _windowSize)