Debian Codegraph @

writer.go

raw
1 package desync
2
3 import (
4 "bytes"
5 "encoding/binary"
6 "io"
7 )
8
9 type writer struct {
10 io.Writer
11 }
12
13 // WriteUint64 converts a number of uint64 values into bytes and writes them
14 // into the stream. Simplifies working with the casync format since almost
15 // everything is expressed as uint64.
16 func (w writer) WriteUint64(values ...uint64) (int64, error) {
17 b := make([]byte, 8*len(values))
18 for i, v := range values {
19 binary.LittleEndian.PutUint64(b[i*8:i*8+8], v)
20 }
21 return io.Copy(w, bytes.NewReader(b))
22 }
23
24 // WriteID serializes a ChunkID into a stream
25 func (w writer) WriteID(c ChunkID) (int64, error) {
26 return io.Copy(w, bytes.NewReader(c[:]))
27 }