Advertisement
honey_the_codewitch

zip example

Mar 26th, 2022
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. // Demo requires an ESP32 (tested) or perhaps an ESP8266 (untested)
  2. #include <Arduino.h>
  3. #include <SPIFFS.h>
  4. #include <htcw_zip.hpp>
  5. using namespace io;
  6. using namespace zip;
  7. void setup() {
  8.     char path[1024];
  9.     Serial.begin(115200);
  10.     SPIFFS.begin(false);
  11.     File f_in = SPIFFS.open("/test.zip","rb");
  12.     file_stream fs(f_in);
  13.     archive arch;
  14.     archive::open(&fs,&arch);
  15.     for(int i = 0;i<arch.entries_size();++i) {
  16.         archive_entry entry;
  17.         arch.entry(i,&entry);
  18.         entry.copy_path(path+1,1024);
  19.         Serial.print("File: ");
  20.         Serial.println(path+1);
  21.         path[0]='/';
  22.         File f_out = SPIFFS.open(path,"wb");
  23.         file_stream fs_out(f_out);
  24.         entry.extract(&fs_out);
  25.         fs_out.close();
  26.         f_out = SPIFFS.open(path,"r");
  27.         while(f_out.available()) {
  28.             int i = f_out.read();
  29.             char sz[2];
  30.             sz[1]=0;
  31.             if(-1!=i) {
  32.                 sz[0]=(char)i;
  33.                 Serial.print(sz);
  34.             } else {
  35.                 break;
  36.             }    
  37.         }
  38.         Serial.println();
  39.     }
  40.     fs.close();
  41. }
  42. void loop() {
  43.    
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement