mirror of
https://github.com/minio/minio.git
synced 2025-01-14 16:25:01 -05:00
Writing data out with error handling
This commit is contained in:
parent
97b2e7fb3b
commit
8129d8fd0b
@ -18,6 +18,7 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,18 +98,45 @@ func (donut *Donut) Write(gobHeader GobHeader, object io.Reader) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (donut *Donut) WriteFormat(target io.Writer, donutFormat DonutFormat) error {
|
func (donut *Donut) WriteFormat(target io.Writer, donutFormat DonutFormat) error {
|
||||||
err := binary.Write(target, binary.LittleEndian, donutFormat.BlockStart)
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.BlockStart); err != nil {
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.VersionMajor)
|
return err
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.VersionMinor)
|
}
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.VersionPatch)
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.VersionMajor); err != nil {
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.VersionReserved)
|
return err
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.Reserved)
|
}
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.GobHeaderLen)
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.VersionMinor); err != nil {
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.GobHeader)
|
return err
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.BlockData)
|
}
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.Data)
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.VersionPatch); err != nil {
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.BlockLen)
|
return err
|
||||||
err = binary.Write(target, binary.LittleEndian, donutFormat.BlockEnd)
|
}
|
||||||
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.VersionReserved); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.Reserved); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.GobHeaderLen); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.GobHeader); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.BlockData); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if count, err := io.Copy(target, donutFormat.Data); uint64(count) != donutFormat.BlockLen || err != nil {
|
||||||
|
if err == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return errors.New("Copy failed, count incorrect.")
|
||||||
|
}
|
||||||
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.BlockLen); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := binary.Write(target, binary.LittleEndian, donutFormat.BlockEnd); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user