代码拉取完成,页面将自动刷新
/*
* 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。