github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/store/nbs/chunk_source_adapter.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package nbs 16 17 import ( 18 "context" 19 20 "github.com/dolthub/dolt/go/store/hash" 21 ) 22 23 type chunkSourceAdapter struct { 24 tableReader 25 h hash.Hash 26 } 27 28 func (csa chunkSourceAdapter) hash() hash.Hash { 29 return csa.h 30 } 31 32 func newReaderFromIndexData(ctx context.Context, q MemoryQuotaProvider, idxData []byte, name hash.Hash, tra tableReaderAt, blockSize uint64) (cs chunkSource, err error) { 33 index, err := parseTableIndexByCopy(ctx, idxData, q) 34 if err != nil { 35 return nil, err 36 } 37 38 tr, err := newTableReader(index, tra, blockSize) 39 if err != nil { 40 return nil, err 41 } 42 return &chunkSourceAdapter{tr, name}, nil 43 } 44 45 func (csa chunkSourceAdapter) close() error { 46 return csa.tableReader.close() 47 } 48 49 func (csa chunkSourceAdapter) clone() (chunkSource, error) { 50 tr, err := csa.tableReader.clone() 51 if err != nil { 52 return &chunkSourceAdapter{}, err 53 } 54 return &chunkSourceAdapter{tr, csa.h}, nil 55 }