Class: Microsandbox::VolumeFs
- Inherits:
-
Object
- Object
- Microsandbox::VolumeFs
- Defined in:
- lib/microsandbox/volume.rb
Overview
A host-side filesystem view over a named volume, from Microsandbox::Volume.fs or Microsandbox::VolumeInfo#fs. Reads and writes the volume’s contents directly on the host, without booting a sandbox. All paths are relative to the volume root. Mirrors the ‘VolumeFs` of the official Python/Node SDKs.
Instance Method Summary collapse
-
#copy(src, dst) ⇒ nil
Copy a file within the volume.
-
#exists?(path) ⇒ Boolean
Whether the path exists in the volume.
-
#initialize(native) ⇒ VolumeFs
constructor
A new instance of VolumeFs.
-
#list(path) ⇒ Array<FsEntry>
List the entries of a directory.
-
#mkdir(path) ⇒ nil
Create a directory (and any missing parents).
-
#read(path) ⇒ String
Read a file as raw bytes (ASCII-8BIT).
-
#read_text(path) ⇒ String
Read a file as a UTF-8 string.
-
#remove_dir(path) ⇒ nil
Remove a directory recursively.
-
#remove_file(path) ⇒ nil
Remove a single file.
-
#rename(src, dst) ⇒ nil
Rename/move a file or directory within the volume.
-
#stat(path) ⇒ FsMetadata
Stat a path.
-
#write(path, data) ⇒ nil
Write data to a file, creating parent directories as needed.
Constructor Details
#initialize(native) ⇒ VolumeFs
Returns a new instance of VolumeFs.
53 54 55 |
# File 'lib/microsandbox/volume.rb', line 53 def initialize(native) @native = native end |
Instance Method Details
#copy(src, dst) ⇒ nil
Copy a file within the volume.
113 114 115 116 |
# File 'lib/microsandbox/volume.rb', line 113 def copy(src, dst) @native.copy(src.to_s, dst.to_s) nil end |
#exists?(path) ⇒ Boolean
Returns whether the path exists in the volume.
107 108 109 |
# File 'lib/microsandbox/volume.rb', line 107 def exists?(path) @native.exists(path.to_s) end |
#list(path) ⇒ Array<FsEntry>
List the entries of a directory.
81 82 83 |
# File 'lib/microsandbox/volume.rb', line 81 def list(path) @native.list(path.to_s).map { |entry| FsEntry.new(entry) } end |
#mkdir(path) ⇒ nil
Create a directory (and any missing parents).
87 88 89 90 |
# File 'lib/microsandbox/volume.rb', line 87 def mkdir(path) @native.mkdir(path.to_s) nil end |
#read(path) ⇒ String
Read a file as raw bytes (ASCII-8BIT).
59 60 61 |
# File 'lib/microsandbox/volume.rb', line 59 def read(path) @native.read(path.to_s) end |
#read_text(path) ⇒ String
Read a file as a UTF-8 string.
65 66 67 |
# File 'lib/microsandbox/volume.rb', line 65 def read_text(path) @native.read_text(path.to_s) end |
#remove_dir(path) ⇒ nil
Remove a directory recursively.
101 102 103 104 |
# File 'lib/microsandbox/volume.rb', line 101 def remove_dir(path) @native.remove_dir(path.to_s) nil end |
#remove_file(path) ⇒ nil
Remove a single file.
94 95 96 97 |
# File 'lib/microsandbox/volume.rb', line 94 def remove_file(path) @native.remove_file(path.to_s) nil end |
#rename(src, dst) ⇒ nil
Rename/move a file or directory within the volume.
120 121 122 123 |
# File 'lib/microsandbox/volume.rb', line 120 def rename(src, dst) @native.rename(src.to_s, dst.to_s) nil end |
#stat(path) ⇒ FsMetadata
Stat a path.
127 128 129 |
# File 'lib/microsandbox/volume.rb', line 127 def stat(path) FsMetadata.new(@native.stat(path.to_s)) end |
#write(path, data) ⇒ nil
Write data to a file, creating parent directories as needed.
73 74 75 76 77 |
# File 'lib/microsandbox/volume.rb', line 73 def write(path, data) bytes = Microsandbox.coerce_write_bytes(data) @native.write(path.to_s, bytes) nil end |