-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathio.go
More file actions
45 lines (40 loc) · 764 Bytes
/
io.go
File metadata and controls
45 lines (40 loc) · 764 Bytes
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
package libcore
import (
"io"
"net"
"os"
"github.com/ulikunitz/xz"
"github.com/v2fly/v2ray-core/v5/common/buf"
"libcore/comm"
)
type packetConn interface {
readFrom() (buffer *buf.Buffer, addr net.Addr, err error)
writeTo(buffer *buf.Buffer, addr net.Addr) (err error)
io.Closer
}
func Unxz(archive string, path string) error {
i, err := os.Open(archive)
if err != nil {
return err
}
r, err := xz.NewReader(i)
if err != nil {
comm.CloseIgnore(i)
return err
}
o, err := os.Create(path)
if err != nil {
comm.CloseIgnore(i)
return err
}
_, err = io.Copy(o, r)
comm.CloseIgnore(i, o)
return err
}
func unxz(path string) error {
err := Unxz(path, path+".tmp")
if err != nil {
return err
}
return os.Rename(path+".tmp", path)
}