internet_file

Last updated:

0 purchases

internet_file Image
internet_file Images
Add to Cart

Description:

internet file

A internet file getter (also optional downloader) that works in all platforms (browsers, mobile, desktop, and server-side)







Purpose •
Getting Started •
Api •
Credits

Purpose #
The library is made to allow direct access to Internet files on all platforms.
It also has the middleware to store files locally if needed.
Aimed primarily at use with plugins, without the ability to work with the Internet
Getting Started #
Simple usage anywhere:
import 'package:internet_file/internet_file.dart';

final Uint8List bytes = await InternetFile.get(
'https://github.com/rbcprolabs/icon_font_generator/raw/master/example/lib/icon_font/ui_icons.ttf',
progress: (receivedLength, contentLength) {
final percentage = receivedLength / contentLength * 100;
print(
'download progress: $receivedLength of $contentLength ($percentage%)');
},
);
copied to clipboard
For local store files you can usage InternetFileStorageIO (not works on web):
import 'package:internet_file/storage_io.dart';

final storageIO = InternetFileStorageIO();

await InternetFile.get(
'https://github.com/rbcprolabs/icon_font_generator/raw/master/example/lib/icon_font/ui_icons.ttf',
storage: storageIO,
storageAdditional: storageIO.additional(
filename: 'ui_icons.ttf',
location: '',
),
);
copied to clipboard
Or you can write you own storage not requires io (web support etc.):
class MyOwnInternetFileStorage extends InternetFileStorage {
@override
Future<Uint8List?> findExist(
String url,
InternetFileStorageAdditional additional,
) {
# find local here

# access you own string property:
print(additional['my_string_property'] as String);

# access you own any type property:
print((additional['my_date_property'] as DateTime).toString())
}

@override
Future<void> save(
String url,
InternetFileStorageAdditional additional,
Uint8List bytes,
) async {
# save file here
}
}

final myOwnStorage = MyOwnInternetFileStorage();
await InternetFile.get(
'https://github.com/rbcprolabs/icon_font_generator/raw/master/example/lib/icon_font/ui_icons.ttf',
storage: myOwnStorage,
storageAdditional: {
'my_string_property': 'string',
'my_int_property': 99,
'my_date_property': DateTime.now(),
},
);
copied to clipboard
Api #
InternetFile.get params



Parameter
Description
Optional
Default




url
Link to network file
required
-


headers
Headers passed for wile load
optional
-


progress
Callback with received & all bytes length progress value called when file loads
optional
-


storage
Implements of InternetFileStorage with save & find local methods for saving files
optional
-


storageAdditional
Additional args for pass to InternetFileStorage implementation passed in storage
optional
{}



Full api reference available here
Credits #
Inspired by flutter_cache_manager, but make for support all platforms
Uses:

http - for file loading from internet
path - for filename & location joint in InternetFileStorageIO
universal_file - for work File in web

Created for usage in:

pdfx
native_pdf_renderer
native_pdf_view
epub_view

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.