feat(storage): support signed read options and local byte ranges
This commit is contained in:
@@ -151,14 +151,31 @@ func (s *Store) Get(ctx context.Context, key string) (storage.Object, error) {
|
||||
}
|
||||
info.ModifiedAt = stat.ModTime()
|
||||
ok = true
|
||||
return storage.Object{Info: info, Body: &body{Reader: storage.ContextReader{Context: ctx, Reader: io.LimitReader(f, info.Size)}, Closer: f}}, nil
|
||||
// Expose only the payload as a seekable section. Seeks are relative to the
|
||||
// object, never to our private metadata header or other disk bytes.
|
||||
return storage.Object{Info: info, Body: &body{section: io.NewSectionReader(f, int64(length)+4, info.Size), file: f, ctx: ctx}}, nil
|
||||
}
|
||||
|
||||
type body struct {
|
||||
io.Reader
|
||||
io.Closer
|
||||
section *io.SectionReader
|
||||
file *os.File
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (b *body) Read(p []byte) (int, error) {
|
||||
if err := b.ctx.Err(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return b.section.Read(p)
|
||||
}
|
||||
func (b *body) Seek(offset int64, whence int) (int64, error) {
|
||||
if err := b.ctx.Err(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return b.section.Seek(offset, whence)
|
||||
}
|
||||
func (b *body) Close() error { return b.file.Close() }
|
||||
|
||||
func (s *Store) Delete(ctx context.Context, key string) error {
|
||||
if err := storage.Check(ctx, key); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user