Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] [cross_file] New architecture. #7591

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

ditman
Copy link
Member

@ditman ditman commented Sep 6, 2024

This PR attempts to solve the current issues of XFile by slightly re-architecting it.

In this PR:

  • XFile is now an interface that does not have any code, except for the two "legacy" constructors that are maintained (but deprecated) for backwards-compatibility reasons.
  • Each underlying data structure contains a super simple implementation of the interface.
  • XFile instances are now created from the platform-specific (native vs web) factories.

This does not remove saveAs from the XFile interface.

Note

This is a breaking change because I've made the old XFile constructors deprecated (and throwy) but if we want to, we could possibly re-implement the "old" constructors with the new implementations and a few conditional imports?

This is not a breaking change anymore. Old tests continue passing (test/legacy*), and new tests contain minor changes.

Anyway, just a RFC!

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@ditman
Copy link
Member Author

ditman commented Sep 6, 2024

/cc @stuartmorgan this is my idea for the "next" version of the x-files. PTAL and let me know what you think, or if you want this to go in another direction :)

The_Truth_Is_Out_There_tagline


@override
Future<void> saveTo(String path) async {
final File fileToSave = File(path);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is lifted from the old implementation but... should the File be created from path + this.name?


/// A CrossFile backed by a dart:io [File].
///
/// (Mobile-only).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget desktop :)

Suggested change
/// (Mobile-only).
/// This is only supported on non-web platforms.

/// The [path] variable is ignored.
@override
Future<void> saveTo(String path) async {
// Save a Blob to file...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems a bit redundant.

objects and their URLs.

It seems that Safari hangs when reading Blobs larger than 4GB (your app will stop
without returning any data, or throwing an exception).

This package will attempt to throw an `Exception` before a large file is accessed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, was this comment removed, because we now refer to the browser's behavior? Or was this fixed in recent versions of Safari?


Example:
In order to instantiate a new `XFile`, import the correct factory class,
either from `package:cross_file/native/factory.dart` (for native development) or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small drive-by comment:

Since the two implementations now have platform-specific imports (dart:io or package:web)
users who take the imports at face value might run into compilation issues, because they lack a conditional import?

Can we provide guidance on how to avoid this? With the legacy API we had the File or Blob types as internals and not on the public interface, which allowed for the plugin to provide a conditional import shim.

@stuartmorgan
Copy link
Contributor

Quick note to say I haven't forgotten about this, I just haven't had time to fully context switch to give this the attention it will need. I'll try to do it within the next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants