mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 09:04:38 +00:00
Upgrade to Assimp 5.0
This commit is contained in:
parent
d8cc73f5a1
commit
c2018ad3de
662 changed files with 106518 additions and 21818 deletions
|
|
@ -1,12 +1,11 @@
|
|||
### A portable (OSX/Linux/Windows), simple zip library written in C
|
||||
This is done by hacking awesome [miniz](https://code.google.com/p/miniz) library and layering functions on top of the miniz v1.15 API.
|
||||
|
||||
[![Windows][win-badge]][win-link] [![OS X][osx-linux-badge]][osx-linux-link]
|
||||
[](https://ci.appveyor.com/project/kuba--/zip)
|
||||
[](https://travis-ci.org/kuba--/zip)
|
||||
[](https://github.com/kuba--/zip/releases)
|
||||
[](https://codecov.io/gh/kuba--/zip)
|
||||
|
||||
[win-badge]: https://img.shields.io/appveyor/ci/kuba--/zip/master.svg?label=windows "AppVeyor build status"
|
||||
[win-link]: https://ci.appveyor.com/project/kuba--/zip "AppVeyor build status"
|
||||
[osx-linux-badge]: https://img.shields.io/travis/kuba--/zip/master.svg?label=linux/osx "Travis CI build status"
|
||||
[osx-linux-link]: https://travis-ci.org/kuba--/zip "Travis CI build status"
|
||||
|
||||
# The Idea
|
||||
<img src="zip.png" name="zip" />
|
||||
|
|
@ -23,117 +22,288 @@ It was the reason, why I decided to write zip module on top of the miniz. It req
|
|||
|
||||
* Create a new zip archive with default compression level.
|
||||
```c
|
||||
struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||||
struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
char *buf = "Some data here...";
|
||||
zip_entry_write(zip, buf, strlen(buf));
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
|
||||
zip_entry_open(zip, "foo-2.txt");
|
||||
{
|
||||
// merge 3 files into one entry and compress them on-the-fly.
|
||||
zip_entry_fwrite(zip, "foo-2.1.txt");
|
||||
zip_entry_fwrite(zip, "foo-2.2.txt");
|
||||
zip_entry_fwrite(zip, "foo-2.3.txt");
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
const char *buf = "Some data here...\0";
|
||||
zip_entry_write(zip, buf, strlen(buf));
|
||||
}
|
||||
zip_close(zip);
|
||||
zip_entry_close(zip);
|
||||
|
||||
zip_entry_open(zip, "foo-2.txt");
|
||||
{
|
||||
// merge 3 files into one entry and compress them on-the-fly.
|
||||
zip_entry_fwrite(zip, "foo-2.1.txt");
|
||||
zip_entry_fwrite(zip, "foo-2.2.txt");
|
||||
zip_entry_fwrite(zip, "foo-2.3.txt");
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
```
|
||||
|
||||
* Append to the existing zip archive.
|
||||
```c
|
||||
struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'a');
|
||||
struct zip_t *zip = zip_open("foo.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'a');
|
||||
{
|
||||
zip_entry_open(zip, "foo-3.txt");
|
||||
{
|
||||
zip_entry_open(zip, "foo-3.txt");
|
||||
{
|
||||
char *buf = "Append some data here...";
|
||||
zip_entry_write(zip, buf, strlen(buf));
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
const char *buf = "Append some data here...\0";
|
||||
zip_entry_write(zip, buf, strlen(buf));
|
||||
}
|
||||
zip_close(zip);
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
```
|
||||
|
||||
* Extract a zip archive into a folder.
|
||||
```c
|
||||
int on_extract_entry(const char *filename, void *arg) {
|
||||
static int i = 0;
|
||||
int n = *(int *)arg;
|
||||
printf("Extracted: %s (%d of %d)\n", filename, ++i, n);
|
||||
int on_extract_entry(const char *filename, void *arg) {
|
||||
static int i = 0;
|
||||
int n = *(int *)arg;
|
||||
printf("Extracted: %s (%d of %d)\n", filename, ++i, n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arg = 2;
|
||||
zip_extract("foo.zip", "/tmp", on_extract_entry, &arg);
|
||||
int arg = 2;
|
||||
zip_extract("foo.zip", "/tmp", on_extract_entry, &arg);
|
||||
```
|
||||
|
||||
* Extract a zip entry into memory.
|
||||
* Extract a zip entry into memory.
|
||||
```c
|
||||
void *buf = NULL;
|
||||
size_t bufsize;
|
||||
void *buf = NULL;
|
||||
size_t bufsize;
|
||||
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
zip_entry_read(zip, &buf, &bufsize);
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
zip_entry_read(zip, &buf, &bufsize);
|
||||
}
|
||||
zip_close(zip);
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
|
||||
free(buf);
|
||||
free(buf);
|
||||
```
|
||||
|
||||
* Extract a zip entry into memory using callback.
|
||||
* Extract a zip entry into memory (no internal allocation).
|
||||
```c
|
||||
struct buffer_t {
|
||||
char *data;
|
||||
size_t size;
|
||||
};
|
||||
unsigned char *buf;
|
||||
size_t bufsize;
|
||||
|
||||
static size_t on_extract(void *arg, unsigned long long offset, const void *data, size_t size) {
|
||||
struct buffer_t *buf = (struct buffer_t *)arg;
|
||||
buf->data = realloc(buf->data, buf->size + size + 1);
|
||||
assert(NULL != buf->data);
|
||||
|
||||
memcpy(&(buf->data[buf->size]), data, size);
|
||||
buf->size += size;
|
||||
buf->data[buf->size] = 0;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
struct buffer_t buf = {0};
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
zip_entry_extract(zip, on_extract, &buf);
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
bufsize = zip_entry_size(zip);
|
||||
buf = calloc(sizeof(unsigned char), bufsize);
|
||||
|
||||
free(buf.data);
|
||||
zip_entry_noallocread(zip, (void *)buf, bufsize);
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
|
||||
free(buf);
|
||||
```
|
||||
|
||||
|
||||
* Extract a zip entry into a file.
|
||||
* Extract a zip entry into memory using callback.
|
||||
```c
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
struct buffer_t {
|
||||
char *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static size_t on_extract(void *arg, unsigned long long offset, const void *data, size_t size) {
|
||||
struct buffer_t *buf = (struct buffer_t *)arg;
|
||||
buf->data = realloc(buf->data, buf->size + size + 1);
|
||||
assert(NULL != buf->data);
|
||||
|
||||
memcpy(&(buf->data[buf->size]), data, size);
|
||||
buf->size += size;
|
||||
buf->data[buf->size] = 0;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
struct buffer_t buf = {0};
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
zip_entry_open(zip, "foo-2.txt");
|
||||
{
|
||||
zip_entry_fread(zip, "foo-2.txt");
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
zip_entry_extract(zip, on_extract, &buf);
|
||||
}
|
||||
zip_close(zip);
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
|
||||
free(buf.data);
|
||||
```
|
||||
|
||||
|
||||
* Extract a zip entry into a file.
|
||||
```c
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
{
|
||||
zip_entry_open(zip, "foo-2.txt");
|
||||
{
|
||||
zip_entry_fread(zip, "foo-2.txt");
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
```
|
||||
|
||||
* List of all zip entries
|
||||
```c
|
||||
struct zip_t *zip = zip_open("foo.zip", 0, 'r');
|
||||
int i, n = zip_total_entries(zip);
|
||||
for (i = 0; i < n; ++i) {
|
||||
zip_entry_openbyindex(zip, i);
|
||||
{
|
||||
const char *name = zip_entry_name(zip);
|
||||
int isdir = zip_entry_isdir(zip);
|
||||
unsigned long long size = zip_entry_size(zip);
|
||||
unsigned int crc32 = zip_entry_crc32(zip);
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close(zip);
|
||||
```
|
||||
|
||||
## Bindings
|
||||
Compile zip library as a dynamic library.
|
||||
```shell
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake -DBUILD_SHARED_LIBS=true ..
|
||||
$ make
|
||||
```
|
||||
|
||||
### Go (cgo)
|
||||
```go
|
||||
package main
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I../src
|
||||
#cgo LDFLAGS: -L. -lzip
|
||||
#include <zip.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func main() {
|
||||
path := C.CString("/tmp/go.zip")
|
||||
zip := C.zip_open(path, 6, 'w')
|
||||
|
||||
entryname := C.CString("test")
|
||||
C.zip_entry_open(zip, entryname)
|
||||
|
||||
content := "test content"
|
||||
buf := unsafe.Pointer(C.CString(content))
|
||||
bufsize := C.size_t(len(content))
|
||||
C.zip_entry_write(zip, buf, bufsize)
|
||||
|
||||
C.zip_entry_close(zip)
|
||||
|
||||
C.zip_close(zip)
|
||||
}
|
||||
```
|
||||
|
||||
### Ruby (ffi)
|
||||
Install _ffi_ gem.
|
||||
```shell
|
||||
$ gem install ffi
|
||||
```
|
||||
|
||||
Bind in your module.
|
||||
```ruby
|
||||
require 'ffi'
|
||||
|
||||
module Zip
|
||||
extend FFI::Library
|
||||
ffi_lib "./libzip.#{::FFI::Platform::LIBSUFFIX}"
|
||||
|
||||
attach_function :zip_open, [:string, :int, :char], :pointer
|
||||
attach_function :zip_close, [:pointer], :void
|
||||
|
||||
attach_function :zip_entry_open, [:pointer, :string], :int
|
||||
attach_function :zip_entry_close, [:pointer], :void
|
||||
attach_function :zip_entry_write, [:pointer, :string, :int], :int
|
||||
end
|
||||
|
||||
ptr = Zip.zip_open("/tmp/ruby.zip", 6, "w".bytes()[0])
|
||||
|
||||
status = Zip.zip_entry_open(ptr, "test")
|
||||
|
||||
content = "test content"
|
||||
status = Zip.zip_entry_write(ptr, content, content.size())
|
||||
|
||||
Zip.zip_entry_close(ptr)
|
||||
Zip.zip_close(ptr)
|
||||
```
|
||||
|
||||
### Python (cffi)
|
||||
Install _cffi_ package
|
||||
```shell
|
||||
$ pip install cffi
|
||||
```
|
||||
|
||||
Bind in your package.
|
||||
```python
|
||||
import ctypes.util
|
||||
from cffi import FFI
|
||||
|
||||
ffi = FFI()
|
||||
ffi.cdef("""
|
||||
struct zip_t *zip_open(const char *zipname, int level, char mode);
|
||||
void zip_close(struct zip_t *zip);
|
||||
|
||||
int zip_entry_open(struct zip_t *zip, const char *entryname);
|
||||
int zip_entry_close(struct zip_t *zip);
|
||||
int zip_entry_write(struct zip_t *zip, const void *buf, size_t bufsize);
|
||||
""")
|
||||
|
||||
Zip = ffi.dlopen(ctypes.util.find_library("zip"))
|
||||
|
||||
ptr = Zip.zip_open("/tmp/python.zip", 6, 'w')
|
||||
|
||||
status = Zip.zip_entry_open(ptr, "test")
|
||||
|
||||
content = "test content"
|
||||
status = Zip.zip_entry_write(ptr, content, len(content))
|
||||
|
||||
Zip.zip_entry_close(ptr)
|
||||
Zip.zip_close(ptr)
|
||||
```
|
||||
|
||||
### Ring
|
||||
The language comes with RingZip based on this library
|
||||
```ring
|
||||
load "ziplib.ring"
|
||||
|
||||
new Zip {
|
||||
setFileName("myfile.zip")
|
||||
open("w")
|
||||
newEntry() {
|
||||
open("test.c")
|
||||
writefile("test.c")
|
||||
close()
|
||||
}
|
||||
close()
|
||||
}
|
||||
```
|
||||
|
||||
# Contribution Rules/Coding Standards
|
||||
No need to throw away your coding style, just do your best to follow default clang-format style.
|
||||
Apply `clang-format` to the source files before commit:
|
||||
```sh
|
||||
for file in $(git ls-files | \grep -E '\.(c|h)$' | \grep -v -- '#')
|
||||
do
|
||||
clang-format -i $file
|
||||
done
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue