diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
| commit | e9c24f4af7ed56760f6db7941827d09f6db9020b (patch) | |
| tree | 62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/paulrosania/go-charset/charset/file.go | |
| parent | 58d5e7cfda4781d8a57ec52aefd02983835c301a (diff) | |
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/paulrosania/go-charset/charset/file.go')
| -rw-r--r-- | teleirc/matterbridge/vendor/github.com/paulrosania/go-charset/charset/file.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/paulrosania/go-charset/charset/file.go b/teleirc/matterbridge/vendor/github.com/paulrosania/go-charset/charset/file.go new file mode 100644 index 0000000..a0c2622 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/paulrosania/go-charset/charset/file.go @@ -0,0 +1,40 @@ +package charset + +import ( + "io" + "io/ioutil" + "os" + "path/filepath" +) + +var files = make(map[string]func() (io.ReadCloser, error)) + +// RegisterDataFile registers the existence of a given data +// file with the given name that may be used by a character-set converter. +// It is intended to be used by packages that wish to embed +// data in the executable binary, and should not be +// used normally. +func RegisterDataFile(name string, open func() (io.ReadCloser, error)) { + files[name] = open +} + +// CharsetDir gives the location of the default data file directory. +// This directory will be used for files with names that have not +// been registered with RegisterDataFile. +var CharsetDir = "/usr/local/lib/go-charset/datafiles" + +func readFile(name string) (data []byte, err error) { + var r io.ReadCloser + if open := files[name]; open != nil { + r, err = open() + if err != nil { + return + } + } else { + r, err = os.Open(filepath.Join(CharsetDir, name)) + if err != nil { + return + } + } + return ioutil.ReadAll(r) +} |
