Ai
1 Star 0 Fork 0

CovScript 智锐编程语言/covscript-zip

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zip.cpp 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
李登淳 提交于 2021-03-23 13:58 +08:00 . Update zip.cpp
/*
* Covariant Script Zip Bindings
*
* 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.
*
* Copyright (C) 2017-2021 Michael Lee(李登淳)
*
* Email: lee@covariant.cn, mikecovlee@163.com
* Github: https://github.com/mikecovlee
* Website: http://covscript.org.cn
*/
#include <zip.hpp>
#include <covscript/dll.hpp>
#include <covscript/cni.hpp>
using cov_zip_t = std::shared_ptr<cov::zip>;
namespace cs_impl {
template<>
struct type_conversion_cs<cov::zip&> {
using source_type=cov_zip_t;
};
template<>
struct type_conversion_cs<const cov::zip&> {
using source_type=cov_zip_t;
};
template<>
struct type_convertor<cov_zip_t, cov::zip&> {
static cov::zip& convert(const cov_zip_t &s)
{
return *s;
}
};
template<>
struct type_convertor<cov_zip_t, const cov::zip&> {
static const cov::zip& convert(const cov_zip_t &s)
{
return *s;
}
};
}
CNI_ROOT_NAMESPACE {
CNI_V(extract, cov::zip_extract)
CNI_NAMESPACE(openmode)
{
CNI_VALUE(read, cov::zip::openmode::read)
CNI_VALUE(write, cov::zip::openmode::write)
CNI_VALUE(append, cov::zip::openmode::append)
}
cov_zip_t open(const std::string& path, cov::zip::openmode mode)
{
return std::make_shared<cov::zip>(path, mode);
}
CNI(open)
CNI_V(zip_extract, cov::zip_extract)
CNI_NAMESPACE(entry_type)
{
CNI_VISITOR_V(name, [](const cov::zip::entry& e) {
return e.name;
})
CNI_VISITOR_V(is_dir, [](const cov::zip::entry& e) {
return e.is_dir;
})
CNI_VISITOR_V(size, [](const cov::zip::entry& e) {
return e.size;
})
CNI_VISITOR_V(crc32, [](const cov::zip::entry& e) {
return std::to_string(e.crc32);
})
}
CNI_NAMESPACE(zip_type)
{
CNI_V(is_open, &cov::zip::is_open)
cs::var get_entries(cov_zip_t& z) {
auto opt = z->get_entries();
if (!opt)
return cs::null_pointer;
cs::var value = cs::var::make<cs::array>();
cs::array &arr = value.val<cs::array>();
for (auto &it:*opt)
arr.emplace_back(it);
return value;
}
CNI(get_entries)
CNI_V(read_entry_stream, [](cov_zip_t& z, const std::string& path, cs::ostream& os) {
return z->read_entry_stream(path, *os);
})
CNI_V(write_entry_stream, [](cov_zip_t& z, const std::string& path, cs::istream& is) {
return z->write_entry_stream(path, *is);
})
CNI_V(entry_add, &cov::zip::entry_add)
CNI_V(entry_extract, &cov::zip::entry_extract)
CNI_V(entry_delete, &cov::zip::entry_delete)
}
}
CNI_ENABLE_TYPE_EXT_V(entry_type, cov::zip::entry, cs::zip::entry)
CNI_ENABLE_TYPE_EXT_V(zip_type, cov_zip_t, cs::zip::zip_type)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/covscript/covscript-zip.git
git@gitee.com:covscript/covscript-zip.git
covscript
covscript-zip
covscript-zip
main

搜索帮助