public LocalFileStorageWorker(LocalFileStorageConfig config)
 => this.Config = config;
        public static FileStream CreateFileStream(
            this LocalFileStorageConfig config,
            Uri resourceUri)
        {
            DirectoryInfo rootDir;

            if (false == File.Exists(config.RootDirectory))
            {
                if (false == config.IsCreatePathEnabled)
                {
                    throw new FileNotFoundException($"Directory {config.RootDirectory} does not exists, and creation not enabled.");
                }
                else
                {
                    rootDir = Directory.CreateDirectory(config.RootDirectory);
                }
            }
            else
            {
                var pathAttr = File.GetAttributes(config.RootDirectory);
                if ((pathAttr & FileAttributes.Directory) != FileAttributes.Directory)
                {
                    throw new DirectoryNotFoundException($"Path {config.RootDirectory} already exists and not a directory");
                }
                else
                {
                    rootDir = Directory.CreateDirectory(config.RootDirectory);
                }
            }
            if (config.IsCreatePathEnabled && config.IsKeepDirStructureEnabled)
            {
                var paramsList = new List <string> {
                    config.RootDirectory
                };
                foreach (var fldename in resourceUri.AbsolutePath.Split('/'))
                {
                    paramsList.Add(fldename);
                }

                var folderPath = Path.GetDirectoryName(Path.Combine(paramsList.ToArray()));

                var folder   = Directory.CreateDirectory(folderPath);
                var fileName = Path.GetFileName(resourceUri.AbsolutePath);

                var filePath = Path.Combine(folderPath, fileName);

                if (File.Exists(filePath))
                {
                    if (false == config.IsFileOverwriteEnabled)
                    {
                        throw new IOException($"File {filePath} already exists and overwrite is not enabled.");
                    }
                    return(new FileStream(filePath, FileMode.Truncate, FileAccess.Write));
                }
                else
                {
                    return(new FileStream(filePath, FileMode.Create, FileAccess.Write));
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }