-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.go
83 lines (68 loc) · 1.81 KB
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package croot
// #include "croot/croot.h"
//
// #include <stdlib.h>
// #include <string.h>
import "C"
import (
"fmt"
"unsafe"
)
type File interface {
Object
Cd(path string) bool
Close(option string)
GetFd() int
Get(namecycle string) Object
IsOpen() bool
Write(name string, opt, bufsiz int) int
}
type fileImpl struct {
c C.CRoot_File
}
func OpenFile(name, option, title string, compress, netopt int) (File, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
copt := C.CString(option)
defer C.free(unsafe.Pointer(copt))
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
f := C.CRoot_File_Open(cname, (*C.CRoot_Option)(copt), ctitle, C.int32_t(compress), C.int32_t(netopt))
if f == nil {
return nil, fmt.Errorf("croot.OpenFile: could not open file [%s]", name)
}
return &fileImpl{c: f}, nil
}
func (f *fileImpl) Cd(path string) bool {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
return c2bool(C.CRoot_File_cd(f.c, cpath))
}
func (f *fileImpl) Close(option string) {
copt := C.CString(option)
defer C.free(unsafe.Pointer(copt))
C.CRoot_File_Close(f.c, (*C.CRoot_Option)(copt))
}
func (f *fileImpl) GetFd() int {
return int(C.CRoot_File_GetFd(f.c))
}
func (f *fileImpl) Get(namecycle string) Object {
cname := C.CString(namecycle)
defer C.free(unsafe.Pointer(cname))
o := C.CRoot_File_Get(f.c, cname)
if o == nil {
return nil
}
return to_gocroot(&objectImpl{o})
}
func (f *fileImpl) IsOpen() bool {
return c2bool(C.CRoot_File_IsOpen(f.c))
}
//func (f *fileImpl) ReadBuffer(buf, pos, len)
//func (f *fileImpl) ReadBuffers
//func (f *fileImpl) WriteBuffer
func (f *fileImpl) Write(name string, opt, bufsiz int) int {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return int(C.CRoot_File_Write(f.c, cname, C.int32_t(opt), C.int32_t(bufsiz)))
}