opendal icon indicating copy to clipboard operation
opendal copied to clipboard

Tracking Issue: dart binding examples, tests, docs && publish

Open asukaminato0721 opened this issue 9 months ago • 5 comments

continue of

https://github.com/apache/opendal/pull/5591#issuecomment-2709719186

  • [x] examples
  • [x] tests
  • [ ] docs
  • [ ] publish

asukaminato0721 avatar Mar 10 '25 08:03 asukaminato0721

Hi, @asukaminato0721. It would be great if we could list all the tasks here directly.

Xuanwo avatar Mar 10 '25 09:03 Xuanwo

The current usage is:

import 'opendal.dart';

void main() async {
  await RustLib.init();
  final File = FileManager.initOp(schemeStr: "fs", map: {"root": "/tmp"});
  // drop-in
  final file = File('file.txt');
  var is_exists = await file.exists();
  print(is_exists);
}
  • Is this how the end users will use opendal after we publish it?
  • Is RustLib.init() required? What will happen if users have multiple rust lib? Can we hide it under FileManager::init?
  • FileManager.initOp seems not a good API name. Op shouldn't have any meaning to dart users I guess. Can we use FileManager.init or FileManager.new?

Xuanwo avatar Mar 11 '25 07:03 Xuanwo

The initialization might be related to some system resources, so we expect users to initialize it only once and use it everywhere instead of creating a new one each time. Can we share the same instance? For example, can we use the same manager for Directory?

Xuanwo avatar Mar 11 '25 08:03 Xuanwo

The users will use import 'package:opendal/opendal.dart'; since this is the mainstream style.

Is RustLib.init() required?

yes

What will happen if users have multiple rust lib?

Warning but no error.

Can we hide it under FileManager::init?

~~My consideration is that, if user want multiple op, this will be triggered many times,~~

I find out how to check the state now.

    expect(RustLib.instance.initialized, false);
    expect(() => RustLib.instance.api, throwsA(isA<StateError>()));

    await RustLib.init();

    expect(RustLib.instance.initialized, true);

may be useful.

The api name will be changed afterwards.

asukaminato0721 avatar Mar 11 '25 09:03 asukaminato0721

The initialization might be related to some system resources, so we expect users to initialize it only once and use it everywhere instead of creating a new one each time. Can we share the same instance? For example, can we use the same manager for Directory?

Oh, just add another init method is enough.

asukaminato0721 avatar Mar 11 '25 09:03 asukaminato0721