How to read file from an imported library

后端 未结 2 894
小蘑菇
小蘑菇 2021-01-21 05:51

I have two packages: webserver and utils which provides assets to webserver.

The webserver needs access to static files inside uti

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-21 06:49

    Use the Resource class, a new class in Dart SDK 1.12.

    Usage example:

    var resource = new Resource('package:myapp/myfile.txt');
    var contents = await resource.loadAsString();
    print(contents);
    

    This works on the VM, as of 1.12.

    However, this doesn't directly address your need to get to the actual File entity, from a package: URI. Given the Resource class today, you'd have to route the bytes from loadAsString() into the HTTP server's Response object.

提交回复
热议问题