summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1787c56)
raw | patch | inline | side by side (parent: 1787c56)
author | ishmal <ishmal@users.sourceforge.net> | |
Fri, 14 Apr 2006 08:20:06 +0000 (08:20 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Fri, 14 Apr 2006 08:20:06 +0000 (08:20 +0000) |
src/dom/util/ziptool.cpp | patch | blob | history | |
src/dom/util/ziptool.h | patch | blob | history |
index 72b7e63b7e1c57783e01c5f4127c6102c38a23a7..701b9d9eba17c77aef449c79b59312065dcbdd95 100644 (file)
--- a/src/dom/util/ziptool.cpp
+++ b/src/dom/util/ziptool.cpp
\r
//#### Huffman Encode\r
void encodeLiteralStatic(unsigned int ch);\r
+\r
+ unsigned char windowBuf[32768];\r
};\r
\r
\r
bool Deflater::compressWindow()\r
{\r
//### Compress as much of the window as possible\r
+ int i=0;\r
+ std::vector<unsigned char>::iterator iter;\r
+ for (iter=window.begin() ; iter!=window.end() ; iter++)\r
+ windowBuf[i++] = *iter;\r
+\r
while (windowPos < window.size())\r
{\r
//### Find best match, if any\r
{\r
unsigned int pos1 = lookBack + lookAhead;\r
unsigned int pos2 = windowPos + lookAhead;\r
- if (window[pos1] != window[pos2])\r
+ if (windowBuf[pos1] != windowBuf[pos2])\r
break;\r
}\r
if (lookAhead > bestMatchLen)\r
{\r
//Literal encode\r
//trace("### literal");\r
- encodeLiteralStatic(window[windowPos]);\r
+ encodeLiteralStatic(windowBuf[windowPos]);\r
windowPos++;\r
}\r
}\r
+\r
encodeLiteralStatic(256);\r
return true;\r
}\r
iter++;\r
}\r
windowPos = 0;\r
- putBits(0x01, 1); //1 -- last block\r
+ if (window.size() >= 32768)\r
+ putBits(0x00, 1); //0 -- more blocks\r
+ else\r
+ putBits(0x01, 1); //1 -- last block\r
putBits(0x01, 2); //01 -- static trees\r
if (!compressWindow())\r
return false;\r
uncompressedData = val;\r
}\r
\r
+/**\r
+ *\r
+ */\r
+unsigned long ZipEntry::getCrc()\r
+{\r
+ return crc;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void ZipEntry::setCrc(unsigned long val)\r
+{\r
+ crc = val;\r
+}\r
+\r
/**\r
*\r
*/\r
\r
\r
\r
-/**\r
- *\r
- */\r
-unsigned long ZipEntry::getCrc()\r
-{\r
- return crc;\r
-}\r
\r
/**\r
*\r
}\r
}\r
\r
+ if (uncompressedSize != uncompBuf.size())\r
+ {\r
+ error("Size mismatch. Received %ld, received %ld",\r
+ uncompressedSize, uncompBuf.size());\r
+ return false;\r
+ }\r
+\r
+ Crc32 crcEngine;\r
+ crcEngine.update(uncompBuf);\r
+ unsigned long crc = crcEngine.getValue();\r
+ if (crc != crc32)\r
+ {\r
+ error("Crc mismatch. Calculated %08ux, received %08ux", crc, crc32);\r
+ return false;\r
+ }\r
+\r
ZipEntry *ze = new ZipEntry(fileName, comment);\r
ze->setCompressionMethod(compressionMethod);\r
ze->setCompressedData(compBuf);\r
ze->setUncompressedData(uncompBuf);\r
+ ze->setCrc(crc);\r
entries.push_back(ze);\r
\r
\r
diff --git a/src/dom/util/ziptool.h b/src/dom/util/ziptool.h
index 217b13171623b3b923dd364b3d15c84c632a0907..88631c997a0bb31b2d005d0e2408a7232a38cd20 100644 (file)
--- a/src/dom/util/ziptool.h
+++ b/src/dom/util/ziptool.h
*/\r
virtual unsigned long getCrc();\r
\r
+ /**\r
+ *\r
+ */\r
+ virtual void setCrc(unsigned long crc);\r
+\r
/**\r
*\r
*/\r