github.com/rgonomic/rgo@v0.2.2-0.20220708095818-4747f0905d6e/internal/vfs/osfs/osfs.go (about) 1 // Copyright ©2019 The rgonomic Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package osfs provides a basic write-only file system interface to the 6 // underlying OS file system. 7 package osfs 8 9 import ( 10 "io" 11 "os" 12 "path/filepath" 13 ) 14 15 // FileSystem is a handle to the OS file system. 16 type FileSystem struct{} 17 18 // Open returns a file for writing, creating any necessary directories. 19 // The file must be closed after use. 20 func (FileSystem) Open(path string) (io.WriteCloser, error) { 21 dir := filepath.Dir(path) 22 err := os.MkdirAll(dir, 0o775) 23 if err != nil { 24 return nil, err 25 } 26 return os.Create(path) 27 } 28 29 // Flush is a no-op. 30 func (fs FileSystem) Flush() error { return nil }