123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- /*================================================================
- Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
- Quectel Wireless Solution Proprietary and Confidential.
- =================================================================*/
- /*=================================================================
- EDIT HISTORY FOR MODULE
- This section contains comments describing changes made to the module.
- Notice that changes are listed in reverse chronological order.
- WHEN WHO WHAT, WHERE, WHY
- ------------ ------- -------------------------------------------------------------------------------
- =================================================================*/
- /*===========================================================================
- * include files
- ===========================================================================*/
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "ql_api_osi.h"
- #include "ql_log.h"
- #include "zip_demo.h"
- #include "ql_zip.h"
- #include "ql_fs.h"
- /*===========================================================================
- * Macro Definition
- ===========================================================================*/
- #define QL_ZIPDEMO_LOG_LEVEL QL_LOG_LEVEL_INFO
- #define QL_ZIPDEMO_LOG(msg, ...) QL_LOG(QL_ZIPDEMO_LOG_LEVEL, "ql_ZIPDEMO", msg, ##__VA_ARGS__)
- #define QL_ZIPDEMO_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_ZIPDEMO", msg, ##__VA_ARGS__)
- #define ZIP_FILE_LEN 1024
- /*===========================================================================
- * Variate
- ===========================================================================*/
- const char *unZipFilePath="UFS:test.zip";
- char *unZip_path=NULL;
- const char *TestFilePath[2]={"UFS:test01.txt","UFS:test02.txt"};
- const char *TestFilezipname[2]={"test01.txt","test02.txt"};
- int unzip_result=QL_FILE_OK;
- int dl_size;
- int upl_size;
- ql_task_t zip_task = NULL;
- /*===========================================================================
- * Functions
- ===========================================================================*/
- static void ql_zip_demo_thread(void *param)
- {
- int ret = 0;
- int run_num=0;
- HZIP hz=0;
- QFILE fd[2] = {0};
-
- unsigned char *zip_fs_space=calloc(10,ZIP_FILE_LEN);
- if(NULL==zip_fs_space)
- {
- QL_ZIPDEMO_LOG("malloc err\r\n");
- return;
- }
- ql_rtos_task_sleep_s(5);
- QL_ZIPDEMO_LOG("========== zip demo start ==========\r\n");
- QL_ZIPDEMO_LOG("========== start create Test Files:[%s][%s]==========\r\n",TestFilePath[0],TestFilePath[1]);
- fd[0] = ql_fopen(TestFilePath[0],"w+");
- fd[1] = ql_fopen(TestFilePath[1],"w+");
- if(fd[0] < 0||fd[1] < 0)
- {
- QL_ZIPDEMO_LOG("open file failed !\r\n");
- QL_ZIPDEMO_LOG("========== Create Test Files:[%s][%s] fail==========\r\n",TestFilePath[0],TestFilePath[1]);
- goto main_exit;
- }
- else
- {
- QL_ZIPDEMO_LOG("open file:[%d][%d] success!\r\n",fd[0],fd[1]);
- }
- memset(zip_fs_space,'a',10*ZIP_FILE_LEN);
- ret = ql_fwrite(zip_fs_space, 10*ZIP_FILE_LEN, 1, fd[0]);
- if(ret > 0)
- {
- QL_ZIPDEMO_LOG("file:test01.txt write :%d bytes data\r\n", ret);
- }
- else
- {
- ql_fclose(fd[0]);
- ql_fclose(fd[1]);
- QL_ZIPDEMO_LOG("file:test01.txt write Failed\r\n");
- QL_ZIPDEMO_LOG("========== Create Test Files:[%s][%s] Failed==========\r\n",TestFilePath[0],TestFilePath[1]);
- goto main_exit;
- }
- memset(zip_fs_space,'b',5*ZIP_FILE_LEN);
- ret = ql_fwrite(zip_fs_space, 5*ZIP_FILE_LEN, 1, fd[1]);
- if(ret > 0)
- {
- QL_ZIPDEMO_LOG("file:test02.txt write :%d bytes data\r\n", ret);
- }
- else
- {
- ql_fclose(fd[0]);
- ql_fclose(fd[1]);
- QL_ZIPDEMO_LOG("file:test02.txt write Failed\r\n");
- QL_ZIPDEMO_LOG("========== Create Test Files:[%s][%s] Failed==========\r\n",TestFilePath[0],TestFilePath[1]);
- goto main_exit;
- }
- ql_fclose(fd[0]);
- ql_fclose(fd[1]);
- QL_ZIPDEMO_LOG("========== Create Test Files:[%s][%s] success==========\r\n",TestFilePath[0],TestFilePath[1]);
- ql_rtos_task_sleep_s(5);
-
- for(run_num=0;run_num<50;run_num++)
- {
- QL_ZIPDEMO_LOG("========== loop_test[%d] start==========\r\n",run_num+1);
- QL_ZIPDEMO_LOG("========== start zip file[%d]==========\r\n",run_num+1);
-
- hz = ql_fs_zip_create(unZipFilePath,0,&ret);
- if (ret<0)
- {
- QL_ZIPDEMO_LOG("create empty.zip:[%s] Failed,errcode=%d\r\n",unZipFilePath,ret);
- goto main_exit;
- }
- else
- {
- QL_ZIPDEMO_LOG("create empty.zip:[%s] Success\r\n",unZipFilePath);
- }
-
- ret=ql_fs_zip_add_file(hz,TestFilezipname[0],TestFilePath[0]);
- if (ret!=QL_FILE_OK)
- {
- QL_ZIPDEMO_LOG("add [%s] to zip Failed\r\n",TestFilePath[0]);
- goto main_exit;
- }
- QL_ZIPDEMO_LOG("add [%s] to zip Success\r\n",TestFilePath[0]);
- ret=ql_fs_zip_add_file(hz,TestFilezipname[1],TestFilePath[1]);
- if (ret!=QL_FILE_OK)
- {
- QL_ZIPDEMO_LOG("add [%s] to zip Failed\r\n",TestFilePath[1]);
- goto main_exit;
- }
- QL_ZIPDEMO_LOG("add [%s] to zip Success\r\n",TestFilePath[1]);
- ql_fs_zip_close(hz);
- #if 0
- //解压到内存
- ql_rtos_task_sleep_s(5);
- ql_unzip_mem_data_s *ql_unzip_tmp = (ql_unzip_mem_data_s *)calloc(1, sizeof(ql_unzip_mem_data_s));
- if (ql_unzip_tmp == NULL)
- {
- QL_ZIPDEMO_LOG("malloc err");
- goto main_exit;
- }
-
- ql_unzip_tmp->data = (void *)calloc(1, 15*ZIP_FILE_LEN);
- if (ql_unzip_tmp->data == NULL)
- {
- QL_ZIPDEMO_LOG("malloc err");
- free(ql_unzip_tmp);
- goto main_exit;
- }
- ql_unzip_tmp->total_len = 15*ZIP_FILE_LEN;
- ret = ql_fs_unzip_ex(unZipFilePath, QL_UNZIP_TO_MEMERY, ql_unzip_tmp);
- if(ret!=QL_FILE_OK)
- {
- QL_ZIPDEMO_LOG("unzip file:[%s] Failed",unZipFilePath);
- free(ql_unzip_tmp->data);
- free(ql_unzip_tmp);
- goto main_exit;
- }
- QL_ZIPDEMO_LOG("used_len=%d,item_num=%d",ql_unzip_tmp->used_len, ql_unzip_tmp->item_num);
-
- int j=0;
- int i = 0;
- char *tmep = NULL;
- for (j=0; j<ql_unzip_tmp->item_num; j++)
- {
- QL_ZIPDEMO_LOG("file path=%s", ql_unzip_tmp->item[j].file_path);
- QL_ZIPDEMO_LOG("file len=%d,type=%d", ql_unzip_tmp->item[j].item_len, ql_unzip_tmp->item[j].file_type);
- tmep = (char *)ql_unzip_tmp->item[j].item_data;
- if (tmep && ql_unzip_tmp->item[j].file_type == QL_UNZIP_FILE)
- {
- if (0 == strcmp(ql_unzip_tmp->item[j].file_path, TestFilePath[0]))
- {
- for (i=0; i<ql_unzip_tmp->item[j].item_len; i++)
- {
- if (tmep[i] != 'a')
- {
- QL_ZIPDEMO_LOG("not match -----------");
- break;
- }
- }
- }
- if (0 == strcmp(ql_unzip_tmp->item[j].file_path, TestFilePath[1]))
- {
- for (i=0; i<ql_unzip_tmp->item[j].item_len; i++)
- {
- if (tmep[i] != 'b')
- {
- QL_ZIPDEMO_LOG("not match -----------");
- break;
- }
- }
- }
- }
- }
- free(ql_unzip_tmp->data);
- free(ql_unzip_tmp);
- QL_ZIPDEMO_LOG("unzip file:[%s] Success\r\n",unZipFilePath);
- #else
- //解压到文件系统
- QL_ZIPDEMO_LOG("========== zip file[%d] success==========\r\n",run_num+1);
- ql_rtos_task_sleep_s(5);
- QL_ZIPDEMO_LOG("========== start unzip file[%d]==========\r\n",run_num+1);
-
- ret=ql_fs_unzip(unZipFilePath,unZip_path,1);
- //ql_unzip_file_data_s ql_unzip_file_tmp = {0};
- //ql_unzip_file_tmp.mode = 1;
- //ql_unzip_file_tmp.path_name = unZip_path;
- //ret = ql_fs_unzip_ex(unZipFilePath, QL_UNZIP_TO_FILE, &ql_unzip_file_tmp);
- if(ret!=QL_FILE_OK)
- {
- QL_ZIPDEMO_LOG("unzip file:[%s] Failed\r\n",unZipFilePath);
- goto main_exit;
- }
-
- QL_ZIPDEMO_LOG("unzip file:[%s] Success\r\n",unZipFilePath);
- #endif
- QL_ZIPDEMO_LOG("========== unzip file[%d] success==========\r\n",run_num+1);
- ql_rtos_task_sleep_s(5);
- }
- main_exit:
- QL_ZIPDEMO_LOG("========== zip demo end ==========\r\n");
- ql_remove(TestFilePath[0]);
- ql_remove(TestFilePath[1]);
- if(zip_fs_space!=NULL)
- {
- free(zip_fs_space);
- zip_fs_space = NULL;
- }
- ql_rtos_task_delete(NULL);
- return;
- }
- void ql_zip_app_init(void)
- {
- QlOSStatus err = QL_OSI_SUCCESS;
- err = ql_rtos_task_create(&zip_task, 8*4096, APP_PRIORITY_NORMAL, "ql_zipdemo", ql_zip_demo_thread, NULL, 5);
- if( err != QL_OSI_SUCCESS )
- {
- QL_ZIPDEMO_LOG("zip demo task created failed");
- }
- }
|