test4.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /* encryption with global compress */
  19. zzz_compression(ctx, ZZZ_FILTER_ZSTD, 5);
  20. zzz_encrypt(ctx, ZZZ_ENC_AES_256_CBC, (uint8_t*)password, strlen(password));
  21. zzz_entity_file(ctx, "valami.txt", 1, strlen(content));
  22. zzz_entity_mtime_t(ctx, time(NULL));
  23. zzz_entity_extra_mime(ctx, "text/plain");
  24. zzz_entity_data(ctx, (uint8_t*)content, strlen(content));
  25. zzz_entity_flush(ctx);
  26. zzz_entity_symlink(ctx, "link.txt", "valami.txt");
  27. zzz_entity_extra_mime(ctx, "text/plain");
  28. zzz_entity_flush(ctx);
  29. zzz_entity_dir(ctx, "directory");
  30. zzz_entity_flush(ctx);
  31. zzz_finish(ctx, &mem, NULL);
  32. free(mem);
  33. printf("\n\n");
  34. ctx = zzz_open_file("a.zzz");
  35. if(!ctx) { printf("unable to read\n"); return 0; }
  36. do {
  37. ret = zzz_read_header(ctx, &ent);
  38. printf("read header %d\n",ret);
  39. switch(ret) {
  40. case ZZZ_END: printf("end.\n"); break;
  41. case ZZZ_ENCRYPTED:
  42. ret = zzz_decrypt(ctx, (uint8_t*)password, strlen(password));
  43. continue;
  44. case ZZZ_OK:
  45. printf("fn '%s'\ntype %02x uncompressed %ld compressed %ld filt %d %d\n", ent->filename, ent->header.type,
  46. ent->header.uncompressed, ent->header.contentsize, ent->filter[0].method, ent->filter[1].method);
  47. if(ent->header.uncompressed) {
  48. size = ent->header.uncompressed;
  49. ret = zzz_read_data(ctx, (uint8_t*)&buf, &size);
  50. printf("data read uncomp %ld ret %d\n", size, ret);
  51. ret = ZZZ_OK;
  52. }
  53. break;
  54. default:
  55. printf("error %d\n", ret);
  56. break;
  57. }
  58. } while(ret == ZZZ_OK);
  59. zzz_close(ctx);
  60. return 0;
  61. }