test3.c 2.2 KB

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