Esempio n. 1
0
File: c.go Progetto: h12w/go-zip
func (z *Zip) statIndex(index uint64, flags C.zip_flags_t) (*C.struct_zip_stat, error) {
	var s C.struct_zip_stat
	if 0 != C.zip_stat_index(z.p, C.zip_uint64_t(index), flags, &s) {
		return nil, z.error()
	}
	return &s, nil
}
Esempio n. 2
0
File: c.go Progetto: h12w/go-zip
func ze_se_to_error(ze, se C.int) error {
	buf := []C.char{0}
	bufLen := C.zip_error_to_str(&buf[0], 1, ze, se) + 1
	buf = make([]C.char, bufLen)
	C.zip_error_to_str(&buf[0], C.zip_uint64_t(bufLen), ze, se)
	return Error{ze, se, C.GoString(&buf[0])}
}
Esempio n. 3
0
File: c.go Progetto: h12w/go-zip
func (z *Zip) sourceFileP(file *C.FILE, start uint64, length int64) (*zipSource, error) {
	s := C.zip_source_filep(z.p, file, C.zip_uint64_t(start), C.zip_int64_t(length))
	if s == nil {
		return nil, z.error()
	}
	return &zipSource{s}, nil
}
Esempio n. 4
0
File: c.go Progetto: h12w/go-zip
func (z *Zip) Delete(index uint64) error {
	z.lock()
	defer z.unlock()
	if 0 != C.zip_delete(z.p, C.zip_uint64_t(index)) {
		return z.error()
	}
	return nil
}
Esempio n. 5
0
File: c.go Progetto: h12w/go-zip
func (f *ZipFile) Read(b []byte) (int64, error) {
	f.z.lock()
	defer f.z.unlock()
	n := C.zip_fread(f.p, unsafe.Pointer(&b[0]), C.zip_uint64_t(len(b)))
	if n == -1 {
		return 0, f.error()
	}
	return int64(n), nil
}
Esempio n. 6
0
File: c.go Progetto: h12w/go-zip
func (z *Zip) FopenIndex(index uint64, flags C.zip_flags_t) (*ZipFile, error) {
	z.lock()
	defer z.unlock()
	f := C.zip_fopen_index(z.p, C.zip_uint64_t(index), flags)
	if f == nil {
		return nil, z.error()
	}
	return &ZipFile{f, z}, nil
}
Esempio n. 7
0
File: c.go Progetto: h12w/go-zip
func (z *Zip) Rename(index uint64, name string) error {
	z.lock()
	defer z.unlock()
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	if 0 != C.zip_rename(z.p, C.zip_uint64_t(index), cname) {
		return z.error()
	}
	return nil
}