Class: OpenDAL::Operator
- Inherits:
-
Object
- Object
- OpenDAL::Operator
- Defined in:
- src/operator.rs
Overview
The entrypoint for operating with file services and files.
Instance Method Summary collapse
-
#capability ⇒ Capability
Gets capabilities of the current operator.
-
#copy(from, to) ⇒ nil
Copies a file from
from
toto
. -
#create_dir(path) ⇒ nil
Creates directory recursively similar as
mkdir -p
The ending path must be/
. -
#delete(path) ⇒ nil
Deletes given path.
-
#exist?(path) ⇒ Boolean
Returns if this path exists.
-
#list(limit: nil, start_after: nil, recursive: nil) ⇒ Lister
Lists the directory.
-
#open(path, mode) ⇒ OpenDAL::IO
Opens a
IO
-like reader for the given path. -
#read(path) ⇒ Metadata
Gets current path's metadata without cache directly.
-
#remove_all(path) ⇒ nil
Removes the path and all nested directories and files recursively.
-
#rename(from, to) ⇒ nil
Renames a file from
from
toto
. -
#write(path, buffer) ⇒ nil
Writes string into given path.
Instance Method Details
#capability ⇒ Capability
Gets capabilities of the current operator
115 116 117 118 |
# File 'src/operator.rs', line 115
fn capability(&self) -> Result<Capability, Error> {
let capability = self.0.info().full_capability();
Ok(Capability::new(capability))
}
|
#copy(from, to) ⇒ nil
Copies a file from from
to to
.
188 189 190 191 192 193 |
# File 'src/operator.rs', line 188
fn copy(ruby: &Ruby, rb_self: &Self, from: String, to: String) -> Result<(), Error> {
rb_self
.0
.copy(&from, &to)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#create_dir(path) ⇒ nil
Creates directory recursively similar as mkdir -p
The ending path must be /
. Otherwise, OpenDAL throws NotADirectory
error.
126 127 128 129 130 131 |
# File 'src/operator.rs', line 126
fn create_dir(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.0
.create_dir(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#delete(path) ⇒ nil
Deletes given path
138 139 140 141 142 143 |
# File 'src/operator.rs', line 138
fn delete(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.0
.delete(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#exist?(path) ⇒ Boolean
Returns if this path exists
150 151 152 153 154 155 |
# File 'src/operator.rs', line 150
fn exists(ruby: &Ruby, rb_self: &Self, path: String) -> Result<bool, Error> {
rb_self
.0
.exists(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#list(limit: nil, start_after: nil, recursive: nil) ⇒ Lister
Lists the directory.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'src/operator.rs', line 214
pub fn list(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Lister, Error> {
let args = scan_args::<(String,), (), (), (), _, ()>(args)?;
let (path,) = args.required;
let kwargs = get_kwargs::<_, (), (Option<usize>, Option<String>, Option<bool>), ()>(
args.keywords,
&[],
&["limit", "start_after", "recursive"],
)?;
let (limit, start_after, recursive) = kwargs.optional;
let mut builder = rb_self.0.clone().lister_with(&path);
if let Some(limit) = limit {
builder = builder.limit(limit);
}
if let Some(start_after) = start_after {
builder = builder.start_after(start_after.as_str());
}
if let Some(true) = recursive {
builder = builder.recursive(true);
}
let lister = builder
.call()
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))?;
Ok(Lister::new(lister))
}
}
|
#open(path, mode) ⇒ OpenDAL::IO
Opens a IO
-like reader for the given path.
202 203 204 205 |
# File 'src/operator.rs', line 202
fn open(ruby: &Ruby, rb_self: &Self, path: String, mode: String) -> Result<Io, Error> {
let operator = rb_self.0.clone();
Ok(Io::new(&ruby, operator, path, mode)?)
}
|
#read(path) ⇒ Metadata
Gets current path's metadata without cache directly.
76 77 78 79 80 81 82 |
# File 'src/operator.rs', line 76
fn read(ruby: &Ruby, rb_self: &Self, path: String) -> Result<bytes::Bytes, Error> {
let buffer = rb_self
.0
.read(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))?;
Ok(buffer.to_bytes())
}
|
#remove_all(path) ⇒ nil
Removes the path and all nested directories and files recursively
175 176 177 178 179 180 |
# File 'src/operator.rs', line 175
fn remove_all(ruby: &Ruby, rb_self: &Self, path: String) -> Result<(), Error> {
rb_self
.0
.remove_all(&path)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#rename(from, to) ⇒ nil
Renames a file from from
to to
163 164 165 166 167 168 |
# File 'src/operator.rs', line 163
fn rename(ruby: &Ruby, rb_self: &Self, from: String, to: String) -> Result<(), Error> {
rb_self
.0
.rename(&from, &to)
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|
#write(path, buffer) ⇒ nil
Writes string into given path.
90 91 92 93 94 95 96 |
# File 'src/operator.rs', line 90
fn write(ruby: &Ruby, rb_self: &Self, path: String, bs: RString) -> Result<(), Error> {
rb_self
.0
.write(&path, bs.to_bytes())
.map(|_| ())
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
}
|