@@ -3,6 +3,7 @@ package vfs
3
3
import (
4
4
"bytes"
5
5
"encoding/binary"
6
+ "errors"
6
7
"fmt"
7
8
"io/fs"
8
9
"os"
@@ -115,6 +116,12 @@ func FromIOFS(fsys fs.FS, useCaseSensitiveFileNames bool) FS {
115
116
return sub
116
117
},
117
118
realpath : realpath ,
119
+ writeFile : func (string , string , bool ) error {
120
+ return errors .ErrUnsupported
121
+ },
122
+ mkdirAll : func (string ) error {
123
+ return errors .ErrUnsupported
124
+ },
118
125
}
119
126
}
120
127
@@ -138,6 +145,28 @@ func FromOS() FS {
138
145
}
139
146
return tspath .NormalizeSlashes (path ), nil
140
147
},
148
+ writeFile : func (path string , content string , writeByteOrderMark bool ) error {
149
+ file , err := os .Create (path )
150
+ if err != nil {
151
+ return err
152
+ }
153
+ defer file .Close ()
154
+
155
+ if writeByteOrderMark {
156
+ if _ , err := file .WriteString ("\uFEFF " ); err != nil {
157
+ return err
158
+ }
159
+ }
160
+
161
+ if _ , err := file .WriteString (content ); err != nil {
162
+ return err
163
+ }
164
+
165
+ return nil
166
+ },
167
+ mkdirAll : func (path string ) error {
168
+ return os .MkdirAll (path , 0o777 )
169
+ },
141
170
}
142
171
}
143
172
@@ -173,8 +202,10 @@ type vfs struct {
173
202
174
203
useCaseSensitiveFileNames bool
175
204
176
- rootFor func (root string ) fs.FS
177
- realpath func (path string ) (string , error )
205
+ rootFor func (root string ) fs.FS
206
+ realpath func (path string ) (string , error )
207
+ writeFile func (path string , content string , writeByteOrderMark bool ) error
208
+ mkdirAll func (path string ) error
178
209
}
179
210
180
211
func (v * vfs ) UseCaseSensitiveFileNames () bool {
@@ -313,28 +344,8 @@ func (v *vfs) Realpath(path string) string {
313
344
return realpath
314
345
}
315
346
316
- func (v * vfs ) writeFile (path string , content string , writeByteOrderMark bool ) error {
317
- file , err := os .Create (path )
318
- if err != nil {
319
- return err
320
- }
321
- defer file .Close ()
322
-
323
- if writeByteOrderMark {
324
- if _ , err := file .WriteString ("\uFEFF " ); err != nil {
325
- return err
326
- }
327
- }
328
-
329
- if _ , err := file .WriteString (content ); err != nil {
330
- return err
331
- }
332
-
333
- return nil
334
- }
335
-
336
347
func (v * vfs ) ensureDirectoryExists (directoryPath string ) error {
337
- return os . MkdirAll (directoryPath , 0o777 )
348
+ return v . mkdirAll (directoryPath )
338
349
}
339
350
340
351
func (v * vfs ) WriteFile (path string , content string , writeByteOrderMark bool ) error {
0 commit comments