compressors.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <cstdio>
  2. #include <cstring>
  3. #include "HeapAllocator.h"
  4. #include "ZipCompressor.h"
  5. using namespace crown;
  6. int main()
  7. {
  8. HeapAllocator allocator;
  9. ZipCompressor compressor(allocator);
  10. const char* uncompressed_string = "letstry";
  11. uint8_t* compressed_string;
  12. uint8_t* result;
  13. size_t compr_size = 0;
  14. size_t result_size = 0;
  15. compressed_string = compressor.compress((void*)uncompressed_string, strlen(uncompressed_string), compr_size);
  16. printf("Uncompressed: ");
  17. printf("Size: %d - ", (uint32_t)strlen(uncompressed_string));
  18. printf(uncompressed_string);
  19. printf("\n\n");
  20. printf("Compressed: ");
  21. printf("Size: %d - ", (uint32_t)compr_size);
  22. for (size_t i = 0; i < compr_size; i++)
  23. {
  24. printf("%c", compressed_string[i]);
  25. }
  26. printf("\n\n");
  27. result = compressor.uncompress((void*)compressed_string, compr_size, result_size);
  28. printf("Uncompressed again: ");
  29. printf("Size: %d - ", (uint32_t)result_size);
  30. for (size_t i = 0; i < result_size; i++)
  31. {
  32. printf("%c", result[i]);
  33. }
  34. printf("\n\n");
  35. allocator.deallocate(compressed_string);
  36. allocator.deallocate(result);
  37. return 0;
  38. }