summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/paulrosania/go-charset/charset/file.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-07-07 23:34:05 +0200
committerWim <wim@42.be>2017-07-07 23:34:05 +0200
commita0938d93869904ebf6d9938485c248b976150fac (patch)
treea12fad5acdceeec93a28efb600ca62b9fdfb40a5 /vendor/github.com/paulrosania/go-charset/charset/file.go
parent2338c69d402ad3779f4e2a2f38ac800ceca656b9 (diff)
downloadmatterbridge-msglm-a0938d93869904ebf6d9938485c248b976150fac.tar.gz
matterbridge-msglm-a0938d93869904ebf6d9938485c248b976150fac.tar.bz2
matterbridge-msglm-a0938d93869904ebf6d9938485c248b976150fac.zip
Add go-charset and chardet to vendor
Diffstat (limited to 'vendor/github.com/paulrosania/go-charset/charset/file.go')
-rw-r--r--vendor/github.com/paulrosania/go-charset/charset/file.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/github.com/paulrosania/go-charset/charset/file.go b/vendor/github.com/paulrosania/go-charset/charset/file.go
new file mode 100644
index 00000000..a0c26225
--- /dev/null
+++ b/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)
+}