Merge pull request #236 from fkautz/pr_out_adding_data_writer

Adding data writer
master
Anand Babu (AB) Periasamy 10 years ago
commit 6515678e87
  1. 27
      pkg/storage/donut/data/data_v1/data.go

@ -1,6 +1,11 @@
package data_v1 package data_v1
import "errors" import (
"bytes"
"encoding/binary"
"encoding/gob"
"io"
)
type DataHeader struct { type DataHeader struct {
Key string Key string
@ -23,6 +28,22 @@ type EncoderParams struct {
Technique EncoderTechnique Technique EncoderTechnique
} }
func Write() error { func Write(target io.Writer, header DataHeader, data io.Reader) error {
return errors.New("Not Implemented") var headerBuffer bytes.Buffer
// encode header
encoder := gob.NewEncoder(&headerBuffer)
encoder.Encode(header)
// write length of header
if err := binary.Write(target, binary.LittleEndian, headerBuffer.Len()); err != nil {
return err
}
// write encoded header
if _, err := io.Copy(target, &headerBuffer); err != nil {
return err
}
// write data
if _, err := io.Copy(target, data); err != nil {
return err
}
return nil
} }

Loading…
Cancel
Save