fix preload alignment for custom buffer sizes
This commit is contained in:
parent
880e2f06b3
commit
cb7f2dee54
6 changed files with 12 additions and 46 deletions
|
|
@ -64,28 +64,12 @@ func (f *file) Stat() (fs.FileInfo, error) {
|
|||
if f.dir {
|
||||
return dir{FileInfo: fi, name: f.name}, nil
|
||||
}
|
||||
|
||||
rs := RealSize(fi.Size())
|
||||
f.stat = &stat{
|
||||
FileInfo: fi,
|
||||
size: rs,
|
||||
size: RealSize(fi.Size()),
|
||||
name: f.name,
|
||||
}
|
||||
return f.stat, nil
|
||||
|
||||
//fmt.Println("rs", rs)
|
||||
//_, err = f.ReadAt(nil, rs)
|
||||
//if err != nil && err != io.EOF {
|
||||
// return nil, err
|
||||
//}
|
||||
//f.stat = &stat{
|
||||
// FileInfo: fi,
|
||||
// size: rs - (ChunkSize - int64(len(f.r.unread))),
|
||||
// name: f.name,
|
||||
//}
|
||||
//fmt.Println("size", f.stat.Size())
|
||||
//f.Seek(0, io.SeekStart)
|
||||
//return f.stat, nil
|
||||
}
|
||||
|
||||
func (f *file) Name() string {
|
||||
|
|
@ -146,7 +130,8 @@ func (f *file) Seek(offset int64, whence int) (n int64, err error) {
|
|||
_, err = f.File.Seek(f.offset, io.SeekStart)
|
||||
n = offset
|
||||
}
|
||||
f.reset()
|
||||
f.r.err = nil
|
||||
f.r.unread = f.r.unread[:0]
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -158,11 +143,6 @@ func (f *file) Seek(offset int64, whence int) (n int64, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (f *file) reset() {
|
||||
f.r.err = nil
|
||||
f.r.unread = f.r.unread[:0]
|
||||
}
|
||||
|
||||
func (f *file) Read(p []byte) (n int, err error) {
|
||||
n, err = f.r.Read(p)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package crypto
|
|||
import (
|
||||
"crypto/cipher"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/chacha20poly1305"
|
||||
|
|
@ -87,9 +86,7 @@ func (r *reader) readChunk() (last bool, err error) {
|
|||
// The last chunk can be short.
|
||||
in = in[:n]
|
||||
last = true
|
||||
fmt.Println("last nonce", r.nonce)
|
||||
setLastChunkFlag(&r.nonce)
|
||||
fmt.Println("last nonce flag", r.nonce)
|
||||
case err != nil:
|
||||
return false, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue