| 1600 | /* /////////////////////////////////////////////////////////////////////////// */ |
| 1601 | |
| 1602 | static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize) |
| 1603 | { |
| 1604 | /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte, |
| 1605 | 2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/ |
| 1606 | |
| 1607 | size_t i, j, numdeflateblocks = (datasize + 65534) / 65535; |
| 1608 | unsigned datapos = 0; |
| 1609 | for(i = 0; i < numdeflateblocks; i++) |
| 1610 | { |
| 1611 | unsigned BFINAL, BTYPE, LEN, NLEN; |
| 1612 | unsigned char firstbyte; |
| 1613 | |
| 1614 | BFINAL = (i == numdeflateblocks - 1); |
| 1615 | BTYPE = 0; |
| 1616 | |
| 1617 | firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1)); |
| 1618 | ucvector_push_back(out, firstbyte); |
| 1619 | |
| 1620 | LEN = 65535; |
| 1621 | if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos; |
| 1622 | NLEN = 65535 - LEN; |
| 1623 | |
| 1624 | ucvector_push_back(out, (unsigned char)(LEN % 256)); |
| 1625 | ucvector_push_back(out, (unsigned char)(LEN / 256)); |
| 1626 | ucvector_push_back(out, (unsigned char)(NLEN % 256)); |
| 1627 | ucvector_push_back(out, (unsigned char)(NLEN / 256)); |
| 1628 | |
| 1629 | /*Decompressed data*/ |
| 1630 | for(j = 0; j < 65535 && datapos < datasize; j++) |
| 1631 | { |
| 1632 | ucvector_push_back(out, data[datapos++]); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | return 0; |
| 1637 | } |
| 1638 | |
| 1639 | /* |
| 1640 | write the lz77-encoded data, which has lit, len and dist codes, to compressed stream using huffman trees. |
no test coverage detected