Skip to content

A cross-platform dart library for saving big amounts of data locally.

Notifications You must be signed in to change notification settings

DaniilAlpha/file-local-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

file_local_storage

A cross-platform library for saving big amounts of data.

Usage

To use this plugin, add file_local_storage as a dependency in your pubspec.yaml file.

import "package:file_local_storage/file_local_storage.dart";
import "package:path_provider/path_provider.dart";

void main() {
  final storage = FileLocalStorage(
    dirPath: getApplicationDocumentsDirectory().then((d) => "${d.path}/MyAppName/"),
    indexedDBName: "MyAppName",
  );

  final str = "Hello world!";

  // saves `ByteBuffer` into file in application documents directory on IO platforms and into IndexedDB on the web 
  storage.save("file.txt", Uint16List.fromList(str.codeUnits).buffer);

  // loads `ByteBuffer` from previously saved location
  final loaded = String.fromCharCodes((await storage.load("file.txt")).asUint16List());

  // deletes entry from previously saved location
  storage.delete("file.txt");

  // all methods can throw `FileStorageException`
  // the `message` field will describe the failure
}