forked from shuLhan/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translateToFile.go
58 lines (48 loc) · 949 Bytes
/
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
package bindata
import (
"bufio"
"fmt"
"os"
)
// translateToFile generates one single file
func translateToFile(c *Config, toc []Asset) (err error) {
// Create output file.
fd, err := os.Create(c.Output)
if err != nil {
return err
}
// Create a buffered writer for better performance.
bfd := bufio.NewWriter(fd)
err = writeHeader(bfd, c, 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, toc)
} else {
err = writeRelease(bfd, c, toc)
}
if err != nil {
goto out
}
// Write table of contents
err = writeTOC(bfd, toc)
if err != nil {
goto out
}
// Write hierarchical tree of assets
err = writeTOCTree(bfd, toc)
if err != nil {
return err
}
// Write restore procedure
err = writeRestore(bfd)
out:
return flushAndClose(fd, bfd, err)
}