small refactor*
This commit is contained in:
parent
b6b541e050
commit
24a4d30275
232 changed files with 2164 additions and 1906 deletions
plugins/archive
57
plugins/archive/sevenzip.go
Normal file
57
plugins/archive/sevenzip.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package archive
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.kmsign.ru/royalcat/tstor/server/src/vfs"
|
||||
"github.com/bodgit/sevenzip"
|
||||
"github.com/royalcat/ctxio"
|
||||
)
|
||||
|
||||
func (d *Daemon) SevenZipLoader(ctx context.Context, archivePath string, ctxreader vfs.File, size int64) (map[string]fileEntry, error) {
|
||||
hash, err := vfs.FileHash(ctx, ctxreader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reader := ctxio.IoReaderAt(ctx, ctxreader)
|
||||
r, err := sevenzip.NewReader(reader, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make(map[string]fileEntry)
|
||||
for i, f := range r.File {
|
||||
if f.FileInfo().IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
af := func(ctx context.Context) (ctxio.ReadCloser, error) {
|
||||
reader := ctxio.IoReaderAt(ctx, ctxreader)
|
||||
zr, err := sevenzip.NewReader(reader, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rc, err := zr.File[i].Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ctxio.WrapIoReadCloser(rc), nil
|
||||
}
|
||||
|
||||
info := f.FileInfo()
|
||||
|
||||
rr := newRandomReaderFromLinear(d.blockcache, archiveFileIndex{archiveHash: hash, filename: f.Name}, info.Size(), af)
|
||||
|
||||
out[vfs.AbsPath(f.Name)] = fileEntry{
|
||||
FileInfo: f.FileInfo(),
|
||||
open: func(ctx context.Context) (vfs.File, error) {
|
||||
return newArchiveFile(info.Name(), info.Size(), rr), nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue