Class: Microsandbox::VolumeFs

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(native) ⇒ VolumeFs

Returns a new instance of VolumeFs.



61
62
63
# File 'lib/microsandbox/volume.rb', line 61

def initialize(native)
  @native = native
end

Instance Method Details

#copy(src, dst) ⇒ nil

Copy a file within the volume.

Returns:

  • (nil)


121
122
123
124
# File 'lib/microsandbox/volume.rb', line 121

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.

Returns:

  • (Boolean)

    whether the path exists in the volume



115
116
117
# File 'lib/microsandbox/volume.rb', line 115

def exists?(path)
  @native.exists(path.to_s)
end

#list(path) ⇒ Array<FsEntry>

List the entries of a directory.

Returns:



89
90
91
# File 'lib/microsandbox/volume.rb', line 89

def list(path)
  @native.list(path.to_s).map { |entry| FsEntry.new(entry) }
end

#mkdir(path) ⇒ nil

Create a directory (and any missing parents).

Returns:

  • (nil)


95
96
97
98
# File 'lib/microsandbox/volume.rb', line 95

def mkdir(path)
  @native.mkdir(path.to_s)
  nil
end

#read(path) ⇒ String

Read a file as raw bytes (ASCII-8BIT).

Returns:

  • (String)


67
68
69
# File 'lib/microsandbox/volume.rb', line 67

def read(path)
  @native.read(path.to_s)
end

#read_text(path) ⇒ String

Read a file as a UTF-8 string.

Returns:

  • (String)


73
74
75
# File 'lib/microsandbox/volume.rb', line 73

def read_text(path)
  @native.read_text(path.to_s)
end

#remove_dir(path) ⇒ nil

Remove a directory recursively.

Returns:

  • (nil)


109
110
111
112
# File 'lib/microsandbox/volume.rb', line 109

def remove_dir(path)
  @native.remove_dir(path.to_s)
  nil
end

#remove_file(path) ⇒ nil

Remove a single file.

Returns:

  • (nil)


102
103
104
105
# File 'lib/microsandbox/volume.rb', line 102

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.

Returns:

  • (nil)


128
129
130
131
# File 'lib/microsandbox/volume.rb', line 128

def rename(src, dst)
  @native.rename(src.to_s, dst.to_s)
  nil
end

#stat(path) ⇒ FsMetadata

Stat a path.

Returns:



135
136
137
# File 'lib/microsandbox/volume.rb', line 135

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.

Parameters:

  • data (String)

    raw bytes (binary-safe)

Returns:

  • (nil)

Raises:

  • (TypeError)

    if data is not a String



81
82
83
84
85
# File 'lib/microsandbox/volume.rb', line 81

def write(path, data)
  bytes = Microsandbox.coerce_write_bytes(data)
  @native.write(path.to_s, bytes)
  nil
end