go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/fs/file.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package fs 5 6 import ( 7 "os" 8 9 "github.com/spf13/afero" 10 ) 11 12 func NewMountedFile(path string, f afero.File) *FileWrapper { 13 return &FileWrapper{ 14 path: path, 15 mountedFile: f, 16 } 17 } 18 19 type FileWrapper struct { 20 path string 21 mountedFile afero.File 22 } 23 24 func (f *FileWrapper) Name() string { 25 return f.path 26 } 27 28 func (f *FileWrapper) Close() error { 29 return f.mountedFile.Close() 30 } 31 32 func (f *FileWrapper) Stat() (os.FileInfo, error) { 33 return f.mountedFile.Stat() 34 } 35 36 func (f *FileWrapper) Sync() error { 37 return notSupported 38 } 39 40 func (f *FileWrapper) Truncate(size int64) error { 41 return notSupported 42 } 43 44 func (f *FileWrapper) Read(b []byte) (n int, err error) { 45 return f.mountedFile.Read(b) 46 } 47 48 func (f *FileWrapper) ReadAt(b []byte, off int64) (n int, err error) { 49 return f.mountedFile.ReadAt(b, off) 50 } 51 52 func (f *FileWrapper) Readdir(n int) ([]os.FileInfo, error) { 53 return f.mountedFile.Readdir(n) 54 } 55 56 func (f *FileWrapper) Readdirnames(n int) ([]string, error) { 57 return f.mountedFile.Readdirnames(n) 58 } 59 60 func (f *FileWrapper) Seek(offset int64, whence int) (int64, error) { 61 return f.mountedFile.Seek(offset, whence) 62 } 63 64 func (f *FileWrapper) Write(b []byte) (n int, err error) { 65 return 0, notSupported 66 } 67 68 func (f *FileWrapper) WriteAt(b []byte, off int64) (n int, err error) { 69 return 0, notSupported 70 } 71 72 func (f *FileWrapper) WriteString(s string) (ret int, err error) { 73 return 0, notSupported 74 }