CloudflareR2Filesystem class final

A storage_fs filesystem backed by a native Cloudflare R2 binding.

Unlike an S3 client, this adapter uses the CloudflareR2Bucket injected by the Workers runtime and therefore needs no account ID or access-key pair. Configure the binding in Wrangler, obtain it from environment.r2('FILES'), and register this filesystem with the application storage manager.

Object keys are scoped beneath prefix. Absolute paths and relative paths that escape that prefix are rejected before the binding is called.

Constructors

CloudflareR2Filesystem({required CloudflareR2Bucket bucket, String? prefix, bool readOnly = false, bool throwOnError = false})
Creates a filesystem backed by bucket.

Properties

bucket CloudflareR2Bucket
The native R2 bucket binding used by this filesystem.
final
hashCode int
The hash code for this object.
no setterinherited
prefix String?
The normalized object-key prefix, or null for the bucket root.
final
readOnly bool
Whether mutating operations are disabled.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
throwOnError bool
Whether operation failures are rethrown instead of converted to the fallback values used by storage_fs.
final

Methods

allDirectories([String? directory]) Future<List<String>>
Get all the directories within a given directory (recursive).
allFiles([String? directory]) Future<List<String>>
Get all of the files from the given directory (recursive).
append(String path, String data, {String separator = '\n'}) Future<bool>
Append to a file.
checksum(String path, {String algorithm = 'md5'}) Future<String?>
Get the checksum for the given file.
copy(String from, String to) Future<bool>
Copy a file to a new location.
delete(dynamic paths) Future<bool>
Delete the file at a given path.
deleteDirectory(String directory) Future<bool>
Recursively delete a directory.
directories([String? directory, bool recursive = false]) Future<List<String>>
Get all of the directories within a given directory.
exists(String path) Future<bool>
Determine if a file exists.
files([String? directory, bool recursive = false]) Future<List<String>>
Get an array of all files in a directory.
get(String path) Future<String?>
Get the contents of a file.
getVisibility(String path) Future<String>
Get the visibility for the given path.
lastModified(String path) Future<DateTime>
Get the file's last modification time.
makeDirectory(String path) Future<bool>
Create a directory.
mimeType(String path) Future<String?>
Determine the mime type for the given file.
missing(String path) Future<bool>
Determine if a file or directory is missing.
move(String from, String to) Future<bool>
Move a file to a new location.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prepend(String path, String data, {String separator = '\n'}) Future<bool>
Prepend to a file.
put(String path, dynamic contents, {Map<String, dynamic>? options}) Future<bool>
Write the contents of a file.
readStream(String path) Stream<List<int>>
Get the contents of a file as a stream.
resolve(String value) String
Normalizes an application-relative object key.
setVisibility(String path, String visibility) Future<bool>
Set the visibility for the given path.
size(String path) Future<int>
Get the file size of a given file.
toString() String
A string representation of this object.
inherited
writeStream(String path, Stream<List<int>> resource, {Map<String, dynamic>? options}) Future<bool>
Write a new file using a stream.

Operators

operator ==(Object other) bool
The equality operator.
inherited