mirror of
https://github.com/minio/minio.git
synced 2024-12-26 07:05:55 -05:00
Adding data writer
This commit is contained in:
parent
be12a6b3d9
commit
7414dc9b75
@ -1,6 +1,11 @@
|
||||
package data_v1
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/gob"
|
||||
"io"
|
||||
)
|
||||
|
||||
type DataHeader struct {
|
||||
Key string
|
||||
@ -23,6 +28,22 @@ type EncoderParams struct {
|
||||
Technique EncoderTechnique
|
||||
}
|
||||
|
||||
func Write() error {
|
||||
return errors.New("Not Implemented")
|
||||
func Write(target io.Writer, header DataHeader, data io.Reader) error {
|
||||
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…
Reference in New Issue
Block a user