test1.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <zzz.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <time.h>
  6. int main(int argc, char **argv)
  7. {
  8. zzz_entity_t *ent;
  9. int ret;
  10. void *ctx = zzz_create_file("a.zzz");
  11. uint8_t *mem = NULL;
  12. uint64_t size;
  13. char buf[4096];
  14. char *content = "hello world\nmasik sor\nmeg valami hogy legyen hosszabb\nhello world\nmasik sor\nmeg valami hogy legye0123456789\n";
  15. char *password = "valami";
  16. (void)argc;
  17. (void)argv;
  18. /* compress per entity */
  19. zzz_entity_file(ctx, "valami.txt", 1, strlen(content));
  20. zzz_entity_mtime_t(ctx, time(NULL));
  21. zzz_entity_extra_mime(ctx, "text/plain");
  22. zzz_entity_data(ctx, (uint8_t*)content, strlen(content));
  23. zzz_entity_flush(ctx);
  24. zzz_entity_symlink(ctx, "link.txt", "valami.txt");
  25. zzz_entity_extra_mime(ctx, "text/plain");
  26. zzz_entity_flush(ctx);
  27. zzz_entity_dir(ctx, "directory");
  28. zzz_entity_flush(ctx);
  29. zzz_finish(ctx, &mem, NULL);
  30. free(mem);
  31. printf("\n\n");
  32. ctx = zzz_open_file("a.zzz");
  33. if(!ctx) { printf("unable to read\n"); return 0; }
  34. do {
  35. ret = zzz_read_header(ctx, &ent);
  36. printf("read header %d\n",ret);
  37. switch(ret) {
  38. case ZZZ_END: printf("end.\n"); break;
  39. case ZZZ_ENCRYPTED:
  40. ret = zzz_decrypt(ctx, (uint8_t*)password, strlen(password));
  41. continue;
  42. case ZZZ_OK:
  43. printf("fn '%s'\ntype %02x uncompressed %ld compressed %ld filt %d %d\n", ent->filename, ent->header.type,
  44. ent->header.uncompressed, ent->header.contentsize, ent->filter[0].method, ent->filter[1].method);
  45. if(ent->header.uncompressed) {
  46. size = ent->header.uncompressed;
  47. ret = zzz_read_data(ctx, (uint8_t*)&buf, &size);
  48. printf("data read uncomp %ld ret %d\n", size, ret);
  49. ret = ZZZ_OK;
  50. }
  51. break;
  52. default:
  53. printf("error %d\n", ret);
  54. break;
  55. }
  56. } while(ret == ZZZ_OK);
  57. zzz_close(ctx);
  58. return 0;
  59. }