Skip to content

Commit

Permalink
[app_fs] add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Oct 11, 2024
1 parent bb74db3 commit 6385f44
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app_fs/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# tekartik flutter recommended lints (extension over google lints and pedantic)
include: package:tekartik_lints_flutter/strict.yaml
include: package:tekartik_lints_flutter/package.yaml
4 changes: 4 additions & 0 deletions app_fs/lib/fs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export 'package:fs_shim/fs_shim.dart';
/// For testing you can use an in memory implementation for idb_shim.
FileSystem get fs => src.fs;

/// The memory file system to use for your flutter application.
FileSystem fsMemory = newFileSystemMemory();

/// path provider file system extension
extension AppFileSystem on FileSystem {
/// Path to a directory where the application may place data that is
/// user-generated, or that cannot otherwise be recreated by your application.
Expand All @@ -27,6 +29,8 @@ extension AppFileSystem on FileSystem {
/// to the user.
///
/// On the web, it is the data root directory
///
/// [packageName] only used on linux and windows for now
Future<Directory> getApplicationDocumentsDirectory(
{String? packageName}) async {
if (this == fs) {
Expand Down
4 changes: 4 additions & 0 deletions app_fs/lib/src/fs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ export 'fs_stub.dart'
if (dart.library.js_interop) 'fs_web.dart'
if (dart.library.io) 'fs_io.dart';

/// Data directory
const dataDirectory = 'data';

/// Data directory path
final String dataDirectoryPath = '${context.separator}$dataDirectory';

/// Get the application file system
Directory getFsApplicationDocumentsDirectory(FileSystem fs) {
return fs.directory(dataDirectoryPath);
}
2 changes: 2 additions & 0 deletions app_fs/lib/src/fs_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import 'package:fs_shim/fs_io.dart' show fileSystemIo, wrapIoDirectory;
import 'package:path_provider/path_provider.dart' as plugin;
import 'package:process_run/shell_run.dart';

/// File system
FileSystem get fs => fileSystemIo;

///
Future<Directory> getApplicationDocumentsDirectory(
{String? packageName}) async {
if (io.Platform.isLinux || io.Platform.isWindows) {
Expand Down
1 change: 1 addition & 0 deletions app_fs/lib/src/fs_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FileSystem get fs => _stub('fs');
/// Get the application file system
FileSystem get testFs => _stub('testFs');

/// Get the application file system
Future<Directory> getApplicationDocumentsDirectory({String? packageName}) =>
_stub('getApplicationDocumentsDirectory');

Expand Down
1 change: 1 addition & 0 deletions app_fs/lib/src/fs_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:tekartik_app_flutter_fs/src/fs.dart';

FileSystem? _fs;

/// Get the application file system
FileSystem get fs => _fs ??= newFileSystemIdb(idbFactoryNative);

/// Package name ignored for indexed_db, we are already in a sandbox
Expand Down

0 comments on commit 6385f44

Please sign in to comment.