1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

Fix: geodata reader for multi-platform compatibility (#964)

This commit is contained in:
rurirei 2021-05-04 00:12:47 +08:00 committed by GitHub
parent 1822504ed8
commit 238b87d26a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -11,13 +11,13 @@ package geodata
import (
"io"
"os"
"runtime"
"strings"
"google.golang.org/protobuf/encoding/protowire"
"github.com/v2fly/v2ray-core/v4/common/errors"
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
)
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
@ -30,7 +30,7 @@ var (
errCodeNotFound = errors.New("code not found")
)
func emitBytes(f *os.File, code string) ([]byte, error) {
func emitBytes(f io.ReadSeeker, code string) ([]byte, error) {
count := 1
isInner := false
tempContainer := make([]byte, 0, 5)
@ -107,7 +107,7 @@ Loop:
}
func Decode(filename, code string) ([]byte, error) {
f, err := os.Open(filename)
f, err := filesystem.NewFileSeeker(filename)
if err != nil {
return nil, newError("failed to open file: ", filename).Base(err)
}

View File

@ -8,10 +8,16 @@ import (
"github.com/v2fly/v2ray-core/v4/common/platform"
)
type FileSeekerFunc func(path string) (io.ReadSeekCloser, error)
type FileReaderFunc func(path string) (io.ReadCloser, error)
type FileWriterFunc func(path string) (io.WriteCloser, error)
var NewFileSeeker FileSeekerFunc = func(path string) (io.ReadSeekCloser, error) {
return os.Open(path)
}
var NewFileReader FileReaderFunc = func(path string) (io.ReadCloser, error) {
return os.Open(path)
}