mirror of
https://github.com/minio/minio.git
synced 2024-12-26 23:25:54 -05:00
Donut structure refined
This commit is contained in:
parent
ab80c0ce12
commit
f7f34d08e8
@ -17,42 +17,39 @@
|
|||||||
package donut
|
package donut
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
|
||||||
"encoding/gob"
|
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** DONUT v1 Spec **
|
** DONUT v1 Spec **
|
||||||
|
|
||||||
BlockStart uint32 // Magic="MINI"
|
BlockStart [4]byte // Magic="MINI"
|
||||||
VersionMajor uint16
|
VersionMajor uint16
|
||||||
VersionMinor uint16
|
VersionMinor uint16
|
||||||
VersionPatch uint16
|
VersionPatch uint16
|
||||||
VersionReserved uint16
|
VersionReserved uint16
|
||||||
Reserved uint64
|
Reserved uint64
|
||||||
GobHeaderLen uint32
|
GobHeaderLen uint32
|
||||||
GobHeader Sizeof(GobHeader)
|
GobHeader io.Reader // matches length
|
||||||
BlockData uint32 // Magic="DATA"
|
BlockData [4]byte // Magic="DATA"
|
||||||
Data []byte
|
Data io.Reader // matches length
|
||||||
BlockLen uint64
|
BlockLen uint64 // length to block start
|
||||||
BlockEnd uint32 // Magic="INIM"
|
BlockEnd [4]byte // Magic="INIM"
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type DonutHeader struct {
|
type DonutStructure struct {
|
||||||
BlockStart uint32 // Magic="MINI"
|
BlockStart [4]byte // Magic="MINI"
|
||||||
VersionMajor uint16
|
VersionMajor uint16
|
||||||
VersionMinor uint16
|
VersionMinor uint16
|
||||||
VersionPatch uint16
|
VersionPatch uint16
|
||||||
VersionReserved uint16
|
VersionReserved uint16
|
||||||
Reserved uint64
|
Reserved uint64
|
||||||
GobHeaderLen uint32
|
GobHeaderLen uint32
|
||||||
}
|
GobHeader GobHeader
|
||||||
|
BlockData [4]byte
|
||||||
type DonutGobHeader struct {
|
Data io.Reader
|
||||||
DataLen uint64
|
BlockLen uint64
|
||||||
|
BlockEnd [4]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type DonutFooter struct {
|
type DonutFooter struct {
|
||||||
@ -62,63 +59,32 @@ type DonutFooter struct {
|
|||||||
|
|
||||||
type Donut struct {
|
type Donut struct {
|
||||||
file io.Writer
|
file io.Writer
|
||||||
|
// mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (donut Donut) Write(header Header, object io.Reader) error {
|
type GobHeader struct{}
|
||||||
var newObjectBuffer bytes.Buffer
|
|
||||||
var headerBuffer bytes.Buffer
|
|
||||||
|
|
||||||
// create gob header
|
func (donut *Donut) Write(gobHeader GobHeader, object io.Reader) error {
|
||||||
headerEncoder := gob.NewEncoder(&headerBuffer)
|
// TODO mutex
|
||||||
err := headerEncoder.Encode(header)
|
// Create bytes buffer representing the new object
|
||||||
if err != nil {
|
donutStructure := DonutStructure{
|
||||||
return err
|
BlockStart: [4]byte{'M', 'I', 'N', 'I'},
|
||||||
|
VersionMajor: 1,
|
||||||
|
VersionMinor: 0,
|
||||||
|
VersionPatch: 0,
|
||||||
|
VersionReserved: 0,
|
||||||
|
Reserved: 0,
|
||||||
|
GobHeaderLen: 0,
|
||||||
|
GobHeader: gobHeader,
|
||||||
|
BlockData: [4]byte{'D', 'A', 'T', 'A'},
|
||||||
|
Data: object,
|
||||||
|
BlockLen: 0,
|
||||||
|
BlockEnd: [4]byte{'I', 'N', 'I', 'M'},
|
||||||
}
|
}
|
||||||
|
if err := WriteStructure(donut.file, donutStructure); err != nil {
|
||||||
// prefix consists of a version number and a length
|
|
||||||
var headerPrefixBuffer bytes.Buffer
|
|
||||||
// write version
|
|
||||||
var version int
|
|
||||||
version = 1
|
|
||||||
err = binary.Write(&headerPrefixBuffer, binary.LittleEndian, version)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// write length
|
|
||||||
var headerLength int
|
|
||||||
headerLength = headerBuffer.Len()
|
|
||||||
err = binary.Write(&headerPrefixBuffer, binary.LittleEndian, headerLength)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// write header prefix
|
|
||||||
io.Copy(&newObjectBuffer, &headerPrefixBuffer)
|
|
||||||
|
|
||||||
// write header
|
|
||||||
io.Copy(&newObjectBuffer, &headerBuffer)
|
|
||||||
|
|
||||||
// write header marker
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// write data
|
|
||||||
_, err = io.Copy(&newObjectBuffer, object)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// write footer
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// write footer marker
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// write new object
|
|
||||||
_, err = io.Copy(donut.file, &newObjectBuffer)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WriteStructure(target io.Writer, donutStructure DonutStructure) error { return nil }
|
||||||
|
Loading…
Reference in New Issue
Block a user