Remove some unneccesary code bits.
This commit is contained in:
parent
6214789c41
commit
665944b444
|
@ -12,16 +12,15 @@ import (
|
||||||
|
|
||||||
// Translate the input file without GZIP compression.
|
// Translate the input file without GZIP compression.
|
||||||
// input -> gowriter -> output.
|
// 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)
|
fmt.Fprintf(output, "package %s\n\nvar %s []byte = []byte{", pkgname, funcname)
|
||||||
io.Copy(&GoWriter{Writer: output}, input)
|
io.Copy(&GoWriter{Writer: output}, input)
|
||||||
fmt.Fprint(output, "\n}")
|
fmt.Fprint(output, "\n}")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate the input file with GZIP compression.
|
// Translate the input file with GZIP compression.
|
||||||
// input -> gzip -> gowriter -> output.
|
// 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
|
fmt.Fprintf(output, `package %s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -52,5 +51,4 @@ func %s() []byte {
|
||||||
|
|
||||||
return b.Bytes()
|
return b.Bytes()
|
||||||
}`)
|
}`)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
27
main.go
27
main.go
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AppName = "bindata"
|
AppName = "bindata"
|
||||||
AppVersion = "0.6"
|
AppVersion = "0.7"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -81,31 +81,32 @@ func main() {
|
||||||
file = strings.Replace(file, " ", "_", -1)
|
file = strings.Replace(file, " ", "_", -1)
|
||||||
file = strings.Replace(file, ".", "_", -1)
|
file = strings.Replace(file, ".", "_", -1)
|
||||||
file = strings.Replace(file, "-", "_", -1)
|
file = strings.Replace(file, "-", "_", -1)
|
||||||
|
|
||||||
if unicode.IsDigit(rune(file[0])) {
|
if unicode.IsDigit(rune(file[0])) {
|
||||||
// Identifier can't start with a digit.
|
// Identifier can't start with a digit.
|
||||||
file = "_" + file
|
file = "_" + file
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file)
|
fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file)
|
||||||
*funcname = file
|
*funcname = file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// Read the input file, transform it into a gzip compressed data stream and
|
// Read the input file, transform it into a gzip compressed data stream and
|
||||||
// write it out as a go source file.
|
// write it out as a go source file.
|
||||||
if pipe {
|
if pipe {
|
||||||
if *uncompressed {
|
if *uncompressed {
|
||||||
err = translate_uncompressed(os.Stdin, os.Stdout, *pkgname, *funcname)
|
translate_uncompressed(os.Stdin, os.Stdout, *pkgname, *funcname)
|
||||||
} else {
|
} else {
|
||||||
err = translate_compressed(os.Stdin, os.Stdout, *pkgname, *funcname)
|
translate_compressed(os.Stdin, os.Stdout, *pkgname, *funcname)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
fmt.Fprintln(os.Stdout, "[i] Done.")
|
||||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
var fs, fd *os.File
|
var fs, fd *os.File
|
||||||
|
var err error
|
||||||
|
|
||||||
if fs, err = os.Open(*in); err != nil {
|
if fs, err = os.Open(*in); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
||||||
|
@ -122,16 +123,10 @@ func main() {
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
if *uncompressed {
|
if *uncompressed {
|
||||||
err = translate_uncompressed(fs, fd, *pkgname, *funcname)
|
translate_uncompressed(fs, fd, *pkgname, *funcname)
|
||||||
} else {
|
} else {
|
||||||
err = translate_compressed(fs, fd, *pkgname, *funcname)
|
translate_compressed(fs, fd, *pkgname, *funcname)
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(os.Stdout, "[i] Done.")
|
fmt.Fprintln(os.Stdout, "[i] Done.")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user