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:
parent
1822504ed8
commit
238b87d26a
@ -11,13 +11,13 @@ package geodata
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"google.golang.org/protobuf/encoding/protowire"
|
"google.golang.org/protobuf/encoding/protowire"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v4/common/errors"
|
"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
|
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
|
||||||
@ -30,7 +30,7 @@ var (
|
|||||||
errCodeNotFound = errors.New("code not found")
|
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
|
count := 1
|
||||||
isInner := false
|
isInner := false
|
||||||
tempContainer := make([]byte, 0, 5)
|
tempContainer := make([]byte, 0, 5)
|
||||||
@ -107,7 +107,7 @@ Loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Decode(filename, code string) ([]byte, error) {
|
func Decode(filename, code string) ([]byte, error) {
|
||||||
f, err := os.Open(filename)
|
f, err := filesystem.NewFileSeeker(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("failed to open file: ", filename).Base(err)
|
return nil, newError("failed to open file: ", filename).Base(err)
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,16 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v4/common/platform"
|
"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 FileReaderFunc func(path string) (io.ReadCloser, error)
|
||||||
|
|
||||||
type FileWriterFunc func(path string) (io.WriteCloser, 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) {
|
var NewFileReader FileReaderFunc = func(path string) (io.ReadCloser, error) {
|
||||||
return os.Open(path)
|
return os.Open(path)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user