allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / scripts / squashfs / lzma / CS / 7zip / Compress / LZ / LzOutWindow.cs
blob3ccfb19ad5424e7cefde5b01cd975c5e3f149796
1 // LzOutWindow.cs
3 namespace SevenZip.Compression.LZ
5 public class OutWindow
7 byte[] _buffer = null;
8 uint _pos;
9 uint _windowSize = 0;
10 uint _streamPos;
11 System.IO.Stream _stream;
13 public void Create(uint windowSize)
15 if (_windowSize != windowSize)
17 // System.GC.Collect();
18 _buffer = new byte[windowSize];
20 _windowSize = windowSize;
21 _pos = 0;
22 _streamPos = 0;
25 public void Init(System.IO.Stream stream, bool solid)
27 ReleaseStream();
28 _stream = stream;
29 if (!solid)
31 _streamPos = 0;
32 _pos = 0;
36 public void Init(System.IO.Stream stream) { Init(stream, false); }
38 public void ReleaseStream()
40 Flush();
41 _stream = null;
44 public void Flush()
46 uint size = _pos - _streamPos;
47 if (size == 0)
48 return;
49 _stream.Write(_buffer, (int)_streamPos, (int)size);
50 if (_pos >= _windowSize)
51 _pos = 0;
52 _streamPos = _pos;
55 public void CopyBlock(uint distance, uint len)
57 uint pos = _pos - distance - 1;
58 if (pos >= _windowSize)
59 pos += _windowSize;
60 for (; len > 0; len--)
62 if (pos >= _windowSize)
63 pos = 0;
64 _buffer[_pos++] = _buffer[pos++];
65 if (_pos >= _windowSize)
66 Flush();
70 public void PutByte(byte b)
72 _buffer[_pos++] = b;
73 if (_pos >= _windowSize)
74 Flush();
77 public byte GetByte(uint distance)
79 uint pos = _pos - distance - 1;
80 if (pos >= _windowSize)
81 pos += _windowSize;
82 return _buffer[pos];