-
Notifications
You must be signed in to change notification settings - Fork 25
/
translateToFile.go
66 lines (54 loc) · 1.24 KB
/
translateToFile.go
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
59
60
61
62
63
64
65
66
// Copyright 2018 The go-bindata Authors. All rights reserved.
// Use of this source code is governed by a CC0 1.0 Universal (CC0 1.0)
// Public Domain Dedication license that can be found in the LICENSE file.
package bindata
import (
"bufio"
"fmt"
"os"
)
// translateToFile generates one single file
func translateToFile(c *Config, keys []string, toc map[string]*asset) (err error) {
// Create output file.
fd, err := os.Create(c.Output)
if err != nil {
return err
}
if c.Verbose {
fmt.Printf("> %s\n", c.Output)
}
// Create a buffered writer for better performance.
bfd := bufio.NewWriter(fd)
err = writeHeader(bfd, c, keys, toc)
if err != nil {
goto out
}
// Write package declaration.
_, err = fmt.Fprintf(bfd, "\npackage %s\n\n", c.Package)
if err != nil {
goto out
}
// Write assets.
if c.Debug || c.Dev {
err = writeDebug(bfd, c, keys, toc)
} else {
err = writeRelease(bfd, c, keys, toc)
}
if err != nil {
goto out
}
// Write table of contents
err = writeTOC(bfd, keys, toc)
if err != nil {
goto out
}
// Write hierarchical tree of assets
err = writeTOCTree(bfd, keys, toc)
if err != nil {
return err
}
// Write restore procedure
err = writeRestore(bfd)
out:
return flushAndClose(fd, bfd, err)
}