forked from folbricht/desync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriter.go
More file actions
27 lines (23 loc) · 648 Bytes
/
Copy pathwriter.go
File metadata and controls
27 lines (23 loc) · 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package desync
import (
"bytes"
"encoding/binary"
"io"
)
type writer struct {
io.Writer
}
// WriteUint64 converts a number of uint64 values into bytes and writes them
// into the stream. Simplifies working with the casync format since almost
// everything is expressed as uint64.
func (w writer) WriteUint64(values ...uint64) (int64, error) {
b := make([]byte, 8*len(values))
for i, v := range values {
binary.LittleEndian.PutUint64(b[i*8:i*8+8], v)
}
return io.Copy(w, bytes.NewReader(b))
}
// WriteID serializes a ChunkID into a stream
func (w writer) WriteID(c ChunkID) (int64, error) {
return io.Copy(w, bytes.NewReader(c[:]))
}