deb-simple/deb/release/writer.go

48 lines
794 B
Go
Raw Normal View History

2017-09-11 02:58:50 +00:00
package release
import (
"strings"
"fmt"
"bufio"
)
type writer struct {
writer *bufio.Writer
}
func (r *writer) WriteValue(key, value string) (int, error) {
if len(value) == 0 {
return 0, nil
}
return r.writer.WriteString(key + ": " + value + "\n")
}
func (r *writer) WriteSlice(key string, s []string) (int, error) {
if len(s) == 0 {
return 0, nil
}
return r.writer.WriteString(key + ": " + strings.Join(s, " ") + "\n")
}
func (r *writer) WriteHashTable(key string, files []*File) {
if files == nil || len(files) == 0 {
return
}
r.writer.WriteString(key + ":\n")
var hash string
for _, f := range files {
if hash = f.Hash(key); hash != "" {
fmt.Fprintf(r.writer, " %s %d %s\n", hash, f.Size, f.Name)
}
}
}
func (r *writer) Flush() {
r.writer.Flush()
}