Imlpement buffered output writer for increased performance.
This addresses issue 14.
This commit is contained in:
parent
436fd0c250
commit
ae22b84b7e
15
convert.go
15
convert.go
|
@ -5,6 +5,7 @@
|
||||||
package bindata
|
package bindata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -41,25 +42,29 @@ func Translate(c *Config) error {
|
||||||
|
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
|
// Create a buffered writer for better performance.
|
||||||
|
bfd := bufio.NewWriter(fd)
|
||||||
|
defer bfd.Flush()
|
||||||
|
|
||||||
// Write build tags, if applicable.
|
// Write build tags, if applicable.
|
||||||
if len(c.Tags) > 0 {
|
if len(c.Tags) > 0 {
|
||||||
_, err = fmt.Fprintf(fd, "// +build %s\n\n", c.Tags)
|
_, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write package declaration.
|
// Write package declaration.
|
||||||
_, err = fmt.Fprintf(fd, "package %s\n\n", c.Package)
|
_, err = fmt.Fprintf(bfd, "package %s\n\n", c.Package)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write assets.
|
// Write assets.
|
||||||
if c.Debug {
|
if c.Debug {
|
||||||
err = writeDebug(fd, toc)
|
err = writeDebug(bfd, toc)
|
||||||
} else {
|
} else {
|
||||||
err = writeRelease(fd, c, toc)
|
err = writeRelease(bfd, c, toc)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -67,7 +72,7 @@ func Translate(c *Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write table of contents
|
// Write table of contents
|
||||||
return writeTOC(fd, toc)
|
return writeTOC(bfd, toc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// findFiles recursively finds all the file paths in the given directory tree.
|
// findFiles recursively finds all the file paths in the given directory tree.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user