Remove some unneccesary code bits.

This commit is contained in:
jim teeuwen 2012-06-07 23:28:16 +02:00
parent 6214789c41
commit 665944b444
2 changed files with 33 additions and 40 deletions

View File

@ -12,16 +12,15 @@ import (
// Translate the input file without GZIP compression.
// input -> gowriter -> output.
func translate_uncompressed(input io.Reader, output io.Writer, pkgname, funcname string) (err error) {
func translate_uncompressed(input io.Reader, output io.Writer, pkgname, funcname string) {
fmt.Fprintf(output, "package %s\n\nvar %s []byte = []byte{", pkgname, funcname)
io.Copy(&GoWriter{Writer: output}, input)
fmt.Fprint(output, "\n}")
return
}
// Translate the input file with GZIP compression.
// input -> gzip -> gowriter -> output.
func translate_compressed(input io.Reader, output io.Writer, pkgname, funcname string) (err error) {
func translate_compressed(input io.Reader, output io.Writer, pkgname, funcname string) {
fmt.Fprintf(output, `package %s
import (
@ -52,5 +51,4 @@ func %s() []byte {
return b.Bytes()
}`)
return
}

27
main.go
View File

@ -16,7 +16,7 @@ import (
const (
AppName = "bindata"
AppVersion = "0.6"
AppVersion = "0.7"
)
func main() {
@ -81,31 +81,32 @@ func main() {
file = strings.Replace(file, " ", "_", -1)
file = strings.Replace(file, ".", "_", -1)
file = strings.Replace(file, "-", "_", -1)
if unicode.IsDigit(rune(file[0])) {
// Identifier can't start with a digit.
file = "_" + file
}
fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file)
*funcname = file
}
}
var err error
// Read the input file, transform it into a gzip compressed data stream and
// write it out as a go source file.
if pipe {
if *uncompressed {
err = translate_uncompressed(os.Stdin, os.Stdout, *pkgname, *funcname)
translate_uncompressed(os.Stdin, os.Stdout, *pkgname, *funcname)
} else {
err = translate_compressed(os.Stdin, os.Stdout, *pkgname, *funcname)
translate_compressed(os.Stdin, os.Stdout, *pkgname, *funcname)
}
if err != nil {
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
fmt.Fprintln(os.Stdout, "[i] Done.")
return
}
} else {
var fs, fd *os.File
var err error
if fs, err = os.Open(*in); err != nil {
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
@ -122,16 +123,10 @@ func main() {
defer fd.Close()
if *uncompressed {
err = translate_uncompressed(fs, fd, *pkgname, *funcname)
translate_uncompressed(fs, fd, *pkgname, *funcname)
} else {
err = translate_compressed(fs, fd, *pkgname, *funcname)
}
if err != nil {
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
return
translate_compressed(fs, fd, *pkgname, *funcname)
}
fmt.Fprintln(os.Stdout, "[i] Done.")
}
}