github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/readervfs/reader.go (about)

     1  package readervfs
     2  
     3  import (
     4  	"github.com/ncruces/go-sqlite3"
     5  	"github.com/ncruces/go-sqlite3/util/ioutil"
     6  	"github.com/ncruces/go-sqlite3/vfs"
     7  )
     8  
     9  type readerVFS struct{}
    10  
    11  func (readerVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, error) {
    12  	if flags&vfs.OPEN_MAIN_DB == 0 {
    13  		return nil, flags, sqlite3.CANTOPEN
    14  	}
    15  	readerMtx.RLock()
    16  	defer readerMtx.RUnlock()
    17  	if ra, ok := readerDBs[name]; ok {
    18  		return readerFile{ra}, flags | vfs.OPEN_READONLY, nil
    19  	}
    20  	return nil, flags, sqlite3.CANTOPEN
    21  }
    22  
    23  func (readerVFS) Delete(name string, dirSync bool) error {
    24  	return sqlite3.IOERR_DELETE
    25  }
    26  
    27  func (readerVFS) Access(name string, flag vfs.AccessFlag) (bool, error) {
    28  	return false, nil
    29  }
    30  
    31  func (readerVFS) FullPathname(name string) (string, error) {
    32  	return name, nil
    33  }
    34  
    35  type readerFile struct{ ioutil.SizeReaderAt }
    36  
    37  func (readerFile) Close() error {
    38  	return nil
    39  }
    40  
    41  func (readerFile) WriteAt(b []byte, off int64) (n int, err error) {
    42  	return 0, sqlite3.READONLY
    43  }
    44  
    45  func (readerFile) Truncate(size int64) error {
    46  	return sqlite3.READONLY
    47  }
    48  
    49  func (readerFile) Sync(flag vfs.SyncFlag) error {
    50  	return nil
    51  }
    52  
    53  func (readerFile) Lock(lock vfs.LockLevel) error {
    54  	return nil
    55  }
    56  
    57  func (readerFile) Unlock(lock vfs.LockLevel) error {
    58  	return nil
    59  }
    60  
    61  func (readerFile) CheckReservedLock() (bool, error) {
    62  	return false, nil
    63  }
    64  
    65  func (readerFile) SectorSize() int {
    66  	return 0
    67  }
    68  
    69  func (readerFile) DeviceCharacteristics() vfs.DeviceCharacteristic {
    70  	return vfs.IOCAP_IMMUTABLE
    71  }