Skip to content

Commit

Permalink
Fix file system ío read implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Aug 15, 2024
1 parent e844798 commit f6f47c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/lw_file_system/lib/src/api/file_system_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef CreateFileCallback = FutureOr<Uint8List> Function(

void defaultCreateDefault(GeneralFileSystem fileSystem) {}

final _pathContext = p.posix;
final _pathContext = p.Context(style: p.Style.posix, current: '/');

abstract class GeneralFileSystem {
final FileSystemConfig config;
Expand Down Expand Up @@ -77,7 +77,8 @@ abstract class GeneralFileSystem {
FutureOr<String> getAbsolutePath(String relativePath) async {
relativePath = normalizePath(relativePath);
final root = await getDirectory();
return p.join(root, relativePath);
return p.Context(style: p.Style.posix, current: root)
.absolute(relativePath);
}

Future<String> getDirectory() async => config.getDirectory(storage);
Expand Down
8 changes: 5 additions & 3 deletions packages/lw_file_system/lib/src/api/file_system_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:lw_file_system/lw_file_system.dart';
import 'package:path/path.dart' as p;

class IODirectoryFileSystem extends DirectoryFileSystem {
@override
Expand Down Expand Up @@ -105,15 +106,16 @@ class IODirectoryFileSystem extends DirectoryFileSystem {
AssetLocation(path: path, remote: remoteName),
assets: (await directory.list(followLinks: false).toList())
.map((e) {
final current = normalizePath(
p.relative(p.basename(e.path), from: absolutePath));
if (e is File) {
return RawFileSystemFile(
AssetLocation(path: e.path, remote: remoteName),
AssetLocation(path: current, remote: remoteName),
data: readData ? e.readAsBytesSync() : null,
);
} else if (e is Directory) {
return RawFileSystemDirectory(
AssetLocation(path: e.path, remote: remoteName),
assets: [],
AssetLocation(path: current, remote: remoteName),
);
}
return null;
Expand Down

0 comments on commit f6f47c6

Please sign in to comment.