* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_APPEXECFWK_STANDARD_TOOLS_ZIP_UTILS_H
#define FOUNDATION_APPEXECFWK_STANDARD_TOOLS_ZIP_UTILS_H
#include <chrono>
#include <ctime>
#include <errno.h>
#include <functional>
#include <ratio>
#include <stddef.h>
#include <string>
#include "event_handler.h"
namespace OHOS {
namespace AppExecFwk {
namespace LIBZIP {
using CALLBACK = std::function<void(int)>;
#if !defined(DISALLOW_ASSIGN)
#define DISALLOW_ASSIGN(TypeName) void operator=(const TypeName&) = delete
#endif
#if !defined(DISALLOW_COPY_AND_ASSIGN)
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#endif
using PlatformFile = int;
using char16 = wchar_t;
using string16 = std::wstring;
enum FlushType {
FLUSH_TYPE_NO_FLUSH = 0,
FLUSH_TYPE_PARTIAL_FLUSH = 1,
FLUSH_TYPE_SYNC_FLUSH = 2,
FLUSH_TYPE_FULL_FLUSH = 3,
FLUSH_TYPE_FINISH = 4,
FLUSH_TYPE_BLOCK = 5,
FLUSH_TYPE_TREES = 6
};
using FLUSH_TYPE = enum FlushType;
enum CompressLevel {
COMPRESS_LEVEL_NO_COMPRESSION = 0,
COMPRESS_LEVEL_BEST_SPEED = 1,
COMPRESS_LEVEL_BEST_COMPRESSION = 9,
COMPRESS_LEVEL_DEFAULT_COMPRESSION = -1
};
using COMPRESS_LEVEL = enum CompressLevel;
enum CompressStrategy {
COMPRESS_STRATEGY_DEFAULT_STRATEGY = 0,
COMPRESS_STRATEGY_FILTERED = 1,
COMPRESS_STRATEGY_HUFFMAN_ONLY = 2,
COMPRESS_STRATEGY_RLE = 3,
COMPRESS_STRATEGY_FIXED = 4
};
using COMPRESS_STRATEGY = enum CompressStrategy;
enum MemoryLevel { MEM_LEVEL_MIN_MEMLEVEL = 1, MEM_LEVEL_DEFAULT_MEMLEVEL = 8, MEM_LEVEL_MAX_MEMLEVEL = 9 };
using MEMORY_LEVEL = enum MemoryLevel;
struct Options {
FLUSH_TYPE flush;
FLUSH_TYPE finishFlush;
int chunkSize;
COMPRESS_LEVEL level;
MEMORY_LEVEL memLevel;
COMPRESS_STRATEGY strategy;
Options()
{
CompressDefaultValue();
}
void CompressDefaultValue()
{
flush = FLUSH_TYPE_NO_FLUSH;
finishFlush = FLUSH_TYPE_SYNC_FLUSH;
chunkSize = 128;
level = COMPRESS_LEVEL_DEFAULT_COMPRESSION;
memLevel = MEM_LEVEL_DEFAULT_MEMLEVEL;
strategy = COMPRESS_STRATEGY_DEFAULT_STRATEGY;
}
};
using OPTIONS = struct Options;
constexpr PlatformFile kInvalidPlatformFile = -1;
struct tm* GetCurrentSystemTime(void);
bool StartsWith(const std::string& str, const std::string& searchFor);
bool EndsWith(const std::string& str, const std::string& searchFor);
bool FilePathCheckValid(const std::string& str);
void PostTask(const OHOS::AppExecFwk::InnerEvent::Callback& callback);
}
}
}
#endif