aboutsummaryrefslogtreecommitdiff
path: root/file/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'file/file.go')
-rw-r--r--file/file.go19
1 files changed, 5 insertions, 14 deletions
diff --git a/file/file.go b/file/file.go
index d69a640..4fde2f3 100644
--- a/file/file.go
+++ b/file/file.go
@@ -3,7 +3,6 @@ package file
import (
"bufio"
- "bytes"
"encoding"
"encoding/base64"
"errors"
@@ -99,23 +98,15 @@ func EncodeFile(fname string, perm os.FileMode, b *Block) error {
return encodeBlock(fd, b)
}
-func Encode(comment string, u encoding.BinaryMarshaler, r io.Reader) ([]byte, error) {
+func Encode(w io.Writer, comment string, u encoding.BinaryMarshaler, msg []byte) error {
raw, err := u.MarshalBinary()
if err != nil {
- return nil, err
- }
- body, err := ioutil.ReadAll(r)
- if err != io.EOF && err != nil {
- return nil, err
+ return err
}
- block := &Block{
+ b := &Block{
Comment: comment,
Bytes: raw,
- Message: body,
- }
- buf := new(bytes.Buffer)
- if err := encodeBlock(buf, block); err != nil {
- return nil, err
+ Message: msg,
}
- return buf.Bytes(), nil
+ return encodeBlock(w, b)
}