more async improvements and crypto bugfix
This commit is contained in:
parent
120464c0a5
commit
304135be2e
7 changed files with 161 additions and 79 deletions
|
|
@ -139,7 +139,6 @@ func (f *file) Seek(offset int64, whence int) (n int64, err error) {
|
|||
return
|
||||
}
|
||||
f.nonce = [NonceSize]byte{}
|
||||
//inc(&f.nonce, cn)
|
||||
put(&f.nonce, cn)
|
||||
f.r.nonce = f.nonce
|
||||
f.w.nonce = f.nonce
|
||||
|
|
@ -184,26 +183,32 @@ func (f *file) ReadAt(p []byte, pos int64) (n int, err error) {
|
|||
func (f *file) WriteAt(data []byte, pos int64) (n int, err error) {
|
||||
f.wmu.Lock()
|
||||
defer f.wmu.Unlock()
|
||||
cn, off, woff := align(pos)
|
||||
c, ok := f.w.cm[cn]
|
||||
if !ok {
|
||||
c = &chunkWriter{offset: off + KDFNonceSize, w: f.w, cn: cn}
|
||||
//inc(&c.nonce, cn)
|
||||
put(&c.nonce, cn)
|
||||
f.w.cm[cn] = c
|
||||
if f.w.last == nil {
|
||||
f.w.last = c
|
||||
} else if cn > f.w.last.cn {
|
||||
f.w.last = c
|
||||
for n != len(data) {
|
||||
cn, off, woff := align(pos + int64(n))
|
||||
c, ok := f.w.cm[cn]
|
||||
if !ok {
|
||||
c = &chunkWriter{offset: off + KDFNonceSize, w: f.w, cn: cn}
|
||||
put(&c.nonce, cn)
|
||||
f.w.cm[cn] = c
|
||||
if f.w.last == nil {
|
||||
f.w.last = c
|
||||
} else if cn > f.w.last.cn {
|
||||
f.w.last = c
|
||||
}
|
||||
}
|
||||
w, e := c.writeAt(data[n:], woff)
|
||||
n += w
|
||||
if c.full() {
|
||||
// async flush
|
||||
go func() {
|
||||
c.flush(notLastChunk)
|
||||
}()
|
||||
delete(f.w.cm, cn)
|
||||
}
|
||||
if e != nil {
|
||||
err = e
|
||||
return
|
||||
}
|
||||
}
|
||||
n, err = c.writeAt(data, woff)
|
||||
if c.full() {
|
||||
// async flush
|
||||
go func() {
|
||||
c.flush(notLastChunk)
|
||||
}()
|
||||
delete(f.w.cm, cn)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ func (r *reader) readChunk() (last bool, err error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
//outBuf := make([]byte, 0, ChunkSize)
|
||||
out, err := r.a.Open(r.outBuf, r.nonce[:], in, nil)
|
||||
if err != nil && !last {
|
||||
// Check if this was a full-length final chunk.
|
||||
|
|
@ -110,7 +109,6 @@ func (r *reader) readChunk() (last bool, err error) {
|
|||
}
|
||||
|
||||
incNonce(&r.nonce)
|
||||
//r.unread = r.buf[:copy(r.buf[:], out)]
|
||||
size := FullSize
|
||||
if len(out) < FullSize {
|
||||
size = len(out)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue