Add a -resources flag to cmd/ractool

This commit is contained in:
Nigel Tao committed 2019-08-09 18:59:10 +10:00
1 parent 08798669eb
commit 6e7c88f42f
2 files changed
+16

No files matched your search

+2
View File
@@ -81,4 +81,6 @@ Encode-Related Flags:
the chunk size (in DSpace)
-indexlocation
the index location, "start" or "end" (default "start")
-resources
comma-separated list of resource files, such as shared dictionaries
`
+14
View File
@@ -87,6 +87,8 @@ Encode-Related Flags:
the chunk size (in DSpace)
-indexlocation
the index location, "start" or "end" (default "start")
-resources
comma-separated list of resource files, such as shared dictionaries
*/
package main
@@ -122,6 +124,8 @@ var (
dchunksizeFlag = flag.String("dchunksize", "0", "the chunk size (in DSpace)")
indexlocationFlag = flag.String("indexlocation", "start",
"the index location, \"start\" or \"end\"")
resourcesFlag = flag.String("resources", "",
"comma-separated list of resource files, such as shared dictionaries")
)
func usage() {
@@ -323,6 +327,16 @@ func encode(r io.Reader) error {
return errors.New("unsupported -codec")
}
if *resourcesFlag != "" {
for _, filename := range strings.Split(*resourcesFlag, ",") {
resource, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
w.ResourcesData = append(w.ResourcesData, resource)
}
}
if _, err := io.Copy(w, r); err != nil {
return err
}