1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright 2021 Nick White.
// Use of this source code is governed by the GPLv3
// license that can be found in the LICENSE file.
// +build ignore
// this downloads the needed files to embed into the binary,
// and is run by `go generate`
package main
import (
"fmt"
"io"
"net/http"
"os"
"path"
)
func dl(url string) error {
fn := path.Base(url)
f, err := os.Create(fn)
if err != nil {
return fmt.Errorf("Error creating file %s: %v", fn, err)
}
defer f.Close()
r, err := http.Get(url)
if err != nil {
return fmt.Errorf("Error getting url %s: %v", url, err)
}
defer r.Body.Close()
_, err = io.Copy(f, r.Body)
if err != nil {
return fmt.Errorf("Error saving %s: %v", fn, err)
}
return nil
}
func main() {
urls := []string{
"https://rescribe.xyz/rescribe/embeds/tessdata.20211001.zip",
"https://rescribe.xyz/rescribe/embeds/tesseract-linux-v5.0.0-alpha.20210510.zip",
"https://rescribe.xyz/rescribe/embeds/tesseract-osx-v4.1.1.20191227.zip",
"https://rescribe.xyz/rescribe/embeds/tesseract-osx-m1-v4.1.1.20210802.zip",
"https://rescribe.xyz/rescribe/embeds/tesseract-w32-v5.0.0-alpha.20210506.zip",
}
for _, v := range urls {
fmt.Printf("Downloading %s\n", v)
err := dl(v)
if err != nil {
fmt.Printf("Error downloading %s: %v\n", v, err)
os.Exit(1)
}
}
}
|