createSync method

K createSync(
  1. T data
)

Creates a file in the data directory with the given data.

The data parameter represents the data to be stored in the file. The idGetterFunction is a function that retrieves the ID for the data. The toJsonFunction is a function that converts the data to JSON format. The encriptionKey is an optional encryption key used to encrypt the JSON data.

Throws an exception if there is an error writing the file.

Implementation

K createSync(T data) {
  final id = idGetterFunction(data);
  final file = File('${directory.path}/$id.json');
  final json = jsonEncode(toJsonFunction(data));
  final encryptedJson = encriptionKey.isNotBlank ? json.applyXorEncrypt(encriptionKey) : json; // Encrypt the JSON if key is not blank
  file.writeAsStringSync(encryptedJson);
  return id;
}