cuelang.org/go@v0.10.1/internal/registrytest/fileio.go (about)

     1  package registrytest
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  	"os"
     7  	"path"
     8  	"time"
     9  
    10  	"golang.org/x/tools/txtar"
    11  )
    12  
    13  // txtarFileIO implements mod/zip.FileIO[txtar.File].
    14  type txtarFileIO struct{}
    15  
    16  func (txtarFileIO) Path(f txtar.File) string {
    17  	return f.Name
    18  }
    19  
    20  func (txtarFileIO) Lstat(f txtar.File) (os.FileInfo, error) {
    21  	return txtarFileInfo{f}, nil
    22  }
    23  
    24  func (txtarFileIO) Open(f txtar.File) (io.ReadCloser, error) {
    25  	return io.NopCloser(bytes.NewReader(f.Data)), nil
    26  }
    27  
    28  func (txtarFileIO) Mode() os.FileMode {
    29  	return 0o444
    30  }
    31  
    32  type txtarFileInfo struct {
    33  	f txtar.File
    34  }
    35  
    36  func (fi txtarFileInfo) Name() string {
    37  	return path.Base(fi.f.Name)
    38  }
    39  
    40  func (fi txtarFileInfo) Size() int64 {
    41  	return int64(len(fi.f.Data))
    42  }
    43  
    44  func (fi txtarFileInfo) Mode() os.FileMode {
    45  	return 0o644
    46  }
    47  
    48  func (fi txtarFileInfo) ModTime() time.Time { return time.Time{} }
    49  func (fi txtarFileInfo) IsDir() bool        { return false }
    50  func (fi txtarFileInfo) Sys() interface{}   { return nil }