| 2492 | } |
| 2493 | |
| 2494 | void Write(uint8_t *buf, size_t size) override |
| 2495 | { |
| 2496 | const lzo_bytep in = buf; |
| 2497 | /* Buffer size is from the LZO docs plus the chunk header size. */ |
| 2498 | uint8_t out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 + sizeof(uint32_t) * 2]; |
| 2499 | uint8_t wrkmem[LZO1X_1_MEM_COMPRESS]; |
| 2500 | lzo_uint outlen; |
| 2501 | |
| 2502 | do { |
| 2503 | /* Compress up to LZO_BUFFER_SIZE bytes at once. */ |
| 2504 | lzo_uint len = size > LZO_BUFFER_SIZE ? LZO_BUFFER_SIZE : (lzo_uint)size; |
| 2505 | lzo1x_1_compress(in, len, out + sizeof(uint32_t) * 2, &outlen, wrkmem); |
| 2506 | ((uint32_t*)out)[1] = TO_BE32((uint32_t)outlen); |
| 2507 | ((uint32_t*)out)[0] = TO_BE32(lzo_adler32(0, out + sizeof(uint32_t), outlen + sizeof(uint32_t))); |
| 2508 | this->chain->Write(out, outlen + sizeof(uint32_t) * 2); |
| 2509 | |
| 2510 | /* Move to next data chunk. */ |
| 2511 | size -= len; |
| 2512 | in += len; |
| 2513 | } while (size > 0); |
| 2514 | } |
| 2515 | }; |
| 2516 | |
| 2517 | #endif /* WITH_LZO */ |