@@ -16,11 +16,11 @@ import SystemPackage
1616/// let fd = try FileDescriptor.open("/path/to/file", .readOnly)
1717/// try fs.addFile(at: "/mounted.txt", handle: fd)
1818/// ```
19- public final class MemoryFileSystem : FileSystemProvider , FileSystem {
19+ public final class MemoryFileSystem : FileSystemProvider , FileSystemImplementation {
2020 private static let rootPath = " / "
2121
2222 private var root : MemoryDirectoryNode
23- private let preopenPaths : [ String ]
23+ let preopenPaths : [ String ]
2424
2525 /// Creates a new in-memory file system.
2626 ///
@@ -50,8 +50,8 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
5050 ///
5151 /// - Parameters:
5252 /// - path: The path where the file should be created
53- /// - content: The file content as byte array
54- public func addFile( at path: String , content: [ UInt8 ] ) throws {
53+ /// - content: The file content as a sequence of bytes
54+ public func addFile( at path: String , content: some Sequence < UInt8 > ) throws {
5555 let normalized = normalizePath ( path)
5656 let ( parentPath, fileName) = try splitPath ( normalized)
5757
@@ -65,7 +65,7 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
6565 /// - path: The path where the file should be created
6666 /// - content: The file content as string (converted to UTF-8)
6767 public func addFile( at path: String , content: String ) throws {
68- try addFile ( at: path, content: Array ( content. utf8) )
68+ try addFile ( at: path, content: content. utf8)
6969 }
7070
7171 /// Adds a file to the file system backed by a file descriptor.
@@ -113,13 +113,9 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
113113 }
114114 }
115115
116- // MARK: - FileSystem (Internal WASI API)
116+ // MARK: - FileSystemImplementation ( WASI API)
117117
118- internal func getPreopenPaths( ) -> [ String ] {
119- return preopenPaths
120- }
121-
122- internal func openDirectory( at path: String ) throws -> any WASIDir {
118+ func openDirectory( at path: String ) throws -> any WASIDir {
123119 guard let node = lookup ( at: path) else {
124120 throw WASIAbi . Errno. ENOENT
125121 }
@@ -136,7 +132,7 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
136132 )
137133 }
138134
139- internal func openAt(
135+ func openAt(
140136 dirFd: any WASIDir ,
141137 path: String ,
142138 oflags: WASIAbi . Oflags ,
@@ -227,13 +223,13 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
227223 throw WASIAbi . Errno. ENOTSUP
228224 }
229225
230- internal func createStdioFile( fd: FileDescriptor , accessMode: FileAccessMode ) -> any WASIFile {
226+ func createStdioFile( fd: FileDescriptor , accessMode: FileAccessMode ) -> any WASIFile {
231227 return MemoryStdioFile ( fd: fd, accessMode: accessMode)
232228 }
233229
234- // MARK: - Internal File Operations
230+ // MARK: - File Operations
235231
236- internal func lookup( at path: String ) -> MemFSNode ? {
232+ func lookup( at path: String ) -> MemFSNode ? {
237233 let normalized = normalizePath ( path)
238234
239235 if normalized == Self . rootPath {
@@ -256,7 +252,7 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
256252 return current
257253 }
258254
259- internal func resolve( from directory: MemoryDirectoryNode , at directoryPath: String , path relativePath: String ) -> MemFSNode ? {
255+ func resolve( from directory: MemoryDirectoryNode , at directoryPath: String , path relativePath: String ) -> MemFSNode ? {
260256 if relativePath. isEmpty {
261257 return directory
262258 }
@@ -292,7 +288,7 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
292288 }
293289
294290 @discardableResult
295- internal func ensureDirectory( at path: String ) throws -> MemoryDirectoryNode {
291+ func ensureDirectory( at path: String ) throws -> MemoryDirectoryNode {
296292 let normalized = normalizePath ( path)
297293
298294 if normalized == Self . rootPath {
@@ -342,7 +338,7 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
342338 }
343339
344340 @discardableResult
345- internal func createFile( in directory: MemoryDirectoryNode , at relativePath: String , oflags: WASIAbi . Oflags ) throws -> MemoryFileNode {
341+ func createFile( in directory: MemoryDirectoryNode , at relativePath: String , oflags: WASIAbi . Oflags ) throws -> MemoryFileNode {
346342 try validateRelativePath ( relativePath)
347343
348344 let components = relativePath. split ( separator: " / " ) . map ( String . init)
@@ -367,7 +363,7 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
367363 }
368364 }
369365
370- internal func removeNode( in directory: MemoryDirectoryNode , at relativePath: String , mustBeDirectory: Bool ) throws {
366+ func removeNode( in directory: MemoryDirectoryNode , at relativePath: String , mustBeDirectory: Bool ) throws {
371367 try validateRelativePath ( relativePath)
372368
373369 let components = relativePath. split ( separator: " / " ) . map ( String . init)
@@ -403,7 +399,7 @@ public final class MemoryFileSystem: FileSystemProvider, FileSystem {
403399 current. removeChild ( name: fileName)
404400 }
405401
406- internal func rename( from sourcePath: String , in sourceDir: MemoryDirectoryNode , to destPath: String , in destDir: MemoryDirectoryNode ) throws {
402+ func rename( from sourcePath: String , in sourceDir: MemoryDirectoryNode , to destPath: String , in destDir: MemoryDirectoryNode ) throws {
407403 guard let sourceNode = resolve ( from: sourceDir, at: " " , path: sourcePath) else {
408404 throw WASIAbi . Errno. ENOENT
409405 }
0 commit comments