getFileSize function

Future<int> getFileSize(
  1. String path, {
  2. bool cacheSize = false,
  3. bool verbose = false,
})

Implementation

Future<int> getFileSize(String path,
    {bool cacheSize = false, bool verbose = false}) async {
  if (verbose) await prnt("${trunc("\r> Checking size of file $path")}");
  /*final fileBytes = await File(path).readAsBytes();
  int size = fileBytes.lengthInBytes;*/
  try {
    final size = await File(path).length();

    if (verbose)
      await prnt("${trunc("\r>> Size of file $path")} is $size bytes");

    if (cacheSize) {
      FileInformationCache FIC = FileInformationCache.obtain();
      FIC.addFile(path, FileInfo(path: path, size: size, isFile: true));
    }

    return size;
  } catch (E) {
    return 0;
  }
}