Disk class
One named place to keep files: a folder on the device, the app bundle, memory, or any DiskDriver.
Get one with disk('name') or FileStorage.disk('name'). Paths are
relative to the disk and always use /; .. can never climb above the
disk's root. Every failure throws a DiskException that names the disk
and the path.
await disk('documents').put('reports/q3.pdf', pdfBytes);
final String avatar = await disk().putFile('avatars', photo);
final List<Order>? orders = await disk().json<List<Order>>('orders.json');
- Implementers
Constructors
Properties
- driver → DiskDriver
-
The backend that stores the bytes.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
The disk's name, e.g.
local.final - prefix → String
-
The folder inside driver this disk treats as its root.
final
- readOnly → bool
-
Whether writes are refused.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
allDirectories(
[String directory = '']) → Future< List< String> > -
The paths of the folders in
directoryand all its sub-folders. -
allFiles(
[String directory = '']) → Future< List< String> > -
The paths of the files in
directoryand all its sub-folders. -
append(
String path, String text, {String separator = '\n'}) → Future< void> -
Adds
textto the end of the file atpath, afterseparatorwhen the file already has content. Creates the file if needed. -
bytes(
String path) → Future< Uint8List> -
The file at
pathas bytes. -
checksum(
String path, {String algorithm = 'md5'}) → Future< String> -
A hash of the file at
path, as lowercase hex.algorithmismd5(the default, as in Laravel),sha1,sha224,sha256,sha384orsha512. -
copy(
String from, String to) → Future< void> -
Copies the file at
fromtoto. -
copyToDisk(
String disk, String path, [String? to]) → Future< void> -
Copies the file at
pathto the same path ondisk, or toto. -
delete(
Object paths) → Future< bool> -
Deletes one path, or every path in an
Iterable<String>. -
deleteDirectory(
String path) → Future< bool> -
Deletes the folder at
pathand everything in it. Returns false when there was no folder. -
directories(
[String directory = '']) → Future< List< String> > -
The paths of the folders in
directory. -
directoryExists(
String path) → Future< bool> -
Whether a folder exists at
path. -
download(
String url, String path, {ProgressCallback? onProgress, CancelToken? cancelToken, Map< String, dynamic> ? headers, Map<String, dynamic> ? queryParameters}) → Future<void> -
Downloads
urlintopath, replacing any file there only once the download has finished. -
exists(
String path) → Future< bool> -
Whether a file exists at
path. -
files(
[String directory = '']) → Future< List< String> > -
The paths of the files in
directory. -
get(
String path) → Future< String> -
The file at
pathas UTF-8 text. -
json<
T> (String path, {Map< Type, dynamic> ? modelDecoders}) → Future<T?> -
The file at
path, decoded from JSON. -
lastModified(
String path) → Future< DateTime> -
When the file at
pathlast changed. -
list(
[String directory = '', bool recursive = false]) → Future< List< DiskEntry> > -
The files and folders in
directory, with their size and date, or in all its sub-folders whenrecursive. Sorted by path. -
makeDirectory(
String path) → Future< void> -
Creates the folder at
pathand any missing parents. -
mimeType(
String path) → Future< String?> -
The MIME type of the file at
path, from its first bytes and its extension, e.g.image/png. Null when neither says. -
missing(
String path) → Future< bool> -
Whether no file exists at
path. -
move(
String from, String to) → Future< void> -
Moves the file at
fromtoto. -
moveToDisk(
String disk, String path, [String? to]) → Future< void> -
Moves the file at
pathto the same path ondisk, or toto. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
path(
String path) → Future< String> -
The absolute path of
pathon the device, for plugins that need a real file. Throws for disks with no files on the device, such as memory disks and the app bundle. -
prepend(
String path, String text, {String separator = '\n'}) → Future< void> -
Adds
textto the start of the file atpath, beforeseparatorwhen the file already has content. Creates the file if needed. -
prune(
{required Duration olderThan}) → Future< int> -
Deletes the files last changed longer ago than
olderThan, and returns how many were deleted. -
put(
String path, Object contents) → Future< void> -
Writes
contentstopath: aString(as UTF-8), aList<int>of bytes, or aStream<List<int>>. Replaces any file there. -
putFile(
String directory, Object file) → Future< String> -
Stores
fileindirectoryunder a random 40-character name, with the extension its contents show it to have, and returns the path. -
putFileAs(
String directory, Object file, String name) → Future< String> -
Stores
fileindirectoryasname, and returns the path. -
putJson(
String path, Object? value) → Future< void> -
Writes
valueas JSON. Models are encoded through theirtoJson(). -
readStream(
String path) → Stream< List< int> > -
The file at
path, in chunks, without loading it all into memory. -
scope(
String directory) → Disk -
A disk rooted at
directoryinside this one, e.g. one per user:disk().scope('users/${user.id}'). -
size(
String path) → Future< int> -
The size of the file at
path, in bytes. -
toString(
) → String -
A string representation of this object.
inherited
-
url(
String path) → Future< Uri> -
A
file://URL forpath, for web views and video players. -
usage(
) → Future< int> - The total size of the files on this disk, in bytes.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited