address PR feedback

This commit is contained in:
Fabian Jakobs 2024-09-17 11:21:15 +02:00
parent 84d1bbf2d5
commit 6bf59ff981
No known key found for this signature in database
2 changed files with 4 additions and 12 deletions

View File

@ -141,8 +141,7 @@ func Detect(name string) (notebook bool, language workspace.Language, err error)
} }
type inMemoryFile struct { type inMemoryFile struct {
content []byte buffer bytes.Buffer
readIndex int64
} }
type inMemoryFS struct { type inMemoryFS struct {
@ -158,20 +157,12 @@ func (f *inMemoryFile) Stat() (fs.FileInfo, error) {
} }
func (f *inMemoryFile) Read(b []byte) (n int, err error) { func (f *inMemoryFile) Read(b []byte) (n int, err error) {
if f.readIndex >= int64(len(f.content)) { return f.buffer.Read(b)
err = io.EOF
return
}
n = copy(b, f.content[f.readIndex:])
f.readIndex += int64(n)
return
} }
func (fs inMemoryFS) Open(name string) (fs.File, error) { func (fs inMemoryFS) Open(name string) (fs.File, error) {
return &inMemoryFile{ return &inMemoryFile{
content: fs.content, buffer: *bytes.NewBuffer(fs.content),
readIndex: 0,
}, nil }, nil
} }

View File

@ -153,6 +153,7 @@ func (r *renderer) computeFile(relPathTemplate string) (file, error) {
return nil, err return nil, err
} }
// we need the absolute path in case we need to write notebooks using the REST API
rootPath, err := filepath.Abs(r.instanceRoot) rootPath, err := filepath.Abs(r.instanceRoot)
if err != nil { if err != nil {
return nil, err return nil, err