Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '7zip/Compress/LZ/LZOutWindow.cpp')
-rwxr-xr-x7zip/Compress/LZ/LZOutWindow.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/7zip/Compress/LZ/LZOutWindow.cpp b/7zip/Compress/LZ/LZOutWindow.cpp
new file mode 100755
index 00000000..22fb4c04
--- /dev/null
+++ b/7zip/Compress/LZ/LZOutWindow.cpp
@@ -0,0 +1,83 @@
+// LZOutWindow.cpp
+
+#include "StdAfx.h"
+
+#include "LZOutWindow.h"
+
+void CLZOutWindow::Create(UINT32 windowSize)
+{
+ _pos = 0;
+ _streamPos = 0;
+ UINT32 newBlockSize = windowSize;
+ const UINT32 kMinBlockSize = 1;
+ if (newBlockSize < kMinBlockSize)
+ newBlockSize = kMinBlockSize;
+ if (_buffer != 0 && _windowSize == newBlockSize)
+ return;
+ delete []_buffer;
+ _buffer = 0;
+ _windowSize = newBlockSize;
+ _buffer = new BYTE[_windowSize];
+}
+
+CLZOutWindow::~CLZOutWindow()
+{
+ // ReleaseStream();
+ delete []_buffer;
+}
+
+/*
+void CLZOutWindow::SetWindowSize(UINT32 windowSize)
+{
+ _windowSize = windowSize;
+}
+*/
+
+void CLZOutWindow::Init(ISequentialOutStream *stream, bool solid)
+{
+ // ReleaseStream();
+ _stream = stream;
+ // _stream->AddRef();
+
+ if(!solid)
+ {
+ _streamPos = 0;
+ _pos = 0;
+ }
+}
+
+/*
+void CLZOutWindow::ReleaseStream()
+{
+ if(_stream != 0)
+ {
+ // Flush(); // Test it
+ _stream->Release();
+ _stream = 0;
+ }
+}
+*/
+
+void CLZOutWindow::FlushWithCheck()
+{
+ HRESULT result = Flush();
+ if (result != S_OK)
+ throw CLZOutWindowException(result);
+}
+
+HRESULT CLZOutWindow::Flush()
+{
+ UINT32 size = _pos - _streamPos;
+ if(size == 0)
+ return S_OK;
+ UINT32 processedSize;
+ HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
+ if (result != S_OK)
+ return result;
+ if (size != processedSize)
+ return E_FAIL;
+ if (_pos >= _windowSize)
+ _pos = 0;
+ _streamPos = _pos;
+ return S_OK;
+}