FileHandler.fromDir constructor

FileHandler.fromDir(
  1. Dir dir
)

Factory constructor that creates a FileHandler from a Dir instance.

The dir parameter specifies the directory from which files are served.

Implementation

factory FileHandler.fromDir(Dir dir) {
  final pathContext = dir.fileSystem.path;
  final currentDir = pathContext.normalize(
    dir.fileSystem.currentDirectory.path,
  );
  final normalizedPath = pathContext.normalize(
    pathContext.isAbsolute(dir.path)
        ? dir.path
        : pathContext.join(currentDir, dir.path),
  );

  return FileHandler._(
    rootPath: normalizedPath,
    fileSystem: dir.fileSystem,
    allowDirectoryListing: dir.listDirectory,
  );
}