fix preload alignment for custom buffer sizes

This commit is contained in:
ston1th 2022-04-07 16:13:08 +02:00
commit cb7f2dee54
6 changed files with 12 additions and 46 deletions

View file

@ -4,7 +4,6 @@ import (
"cachefs/pkg/chunk"
"crypto/cipher"
"errors"
"fmt"
"io"
"golang.org/x/crypto/chacha20poly1305"
@ -72,9 +71,7 @@ func (c *chunkWriter) full() bool {
func (c *chunkWriter) flush(last bool) (n int, err error) {
wb := c.buf[:0]
if last {
fmt.Println("last nonce", c.nonce)
setLastChunkFlag(&c.nonce)
fmt.Println("last nonce flag", c.nonce)
s := c.chunks.Size()
wb = c.buf[:s]
n = int(s)
@ -115,16 +112,13 @@ func (w *writer) Write(p []byte) (n int, err error) {
}
func (w *writer) Close() error {
fmt.Println("writer closed", w.err)
if w.err != nil {
return w.err
}
if w.last != nil {
fmt.Println("flushing last chunk")
_, w.err = w.last.flush(lastChunk)
if w.err != nil {
fmt.Println("error flushing last chunk", w.err)
return w.err
}
w.flush = false