1package bindata
2
3import (
4	"bufio"
5	"fmt"
6	"os"
7)
8
9// translateToFile generates one single file
10func translateToFile(c *Config, toc []Asset) (err error) {
11	// Create output file.
12	fd, err := os.Create(c.Output)
13	if err != nil {
14		return err
15	}
16
17	// Create a buffered writer for better performance.
18	bfd := bufio.NewWriter(fd)
19
20	err = writeHeader(bfd, c, toc)
21	if err != nil {
22		goto out
23	}
24
25	// Write package declaration.
26	_, err = fmt.Fprintf(bfd, "\npackage %s\n\n", c.Package)
27	if err != nil {
28		goto out
29	}
30
31	// Write assets.
32	if c.Debug || c.Dev {
33		err = writeDebug(bfd, c, toc)
34	} else {
35		err = writeRelease(bfd, c, toc)
36	}
37
38	if err != nil {
39		goto out
40	}
41
42	// Write table of contents
43	err = writeTOC(bfd, toc)
44	if err != nil {
45		goto out
46	}
47
48	// Write hierarchical tree of assets
49	err = writeTOCTree(bfd, toc)
50	if err != nil {
51		return err
52	}
53
54	// Write restore procedure
55	err = writeRestore(bfd)
56out:
57	return flushAndClose(fd, bfd, err)
58}
59