Beispiel #1
0
        public async Task <IFileInfo> WriteFileAsync(Stream stream, string path, IWriteFileOptions options)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!options.OverrideIfExists && await FileExistsAsync(path))
            {
                throw new FileAlreadyExistsException(path);
            }

            CreateDirectoryIfNotExisting(path);

            if (stream.CanSeek && stream.Position != 0)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            using (var fileStream = new FileStream(path, FileMode.CreateNew, FileAccess.Write))
            {
                await stream.CopyToAsync(fileStream);

                fileStream.Close();
            }

            var fileInfo     = new FileInfo(path);
            var physicalinfo = new PhysicalFileInfo(fileInfo);

            return(physicalinfo);
        }
Beispiel #2
0
        public async Task <IFileInfo> WriteFileAsync(byte[] bytes, string path, IWriteFileOptions options)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!options.OverrideIfExists && await FileExistsAsync(path))
            {
                throw new FileAlreadyExistsException(path);
            }

            CreateDirectoryIfNotExisting(path);

            File.WriteAllBytes(path, bytes);
            var fileInfo     = new FileInfo(path);
            var physicalinfo = new PhysicalFileInfo(fileInfo);

            return(physicalinfo);
        }
Beispiel #3
0
        public async Task <IFileInfo> WriteFileAsync(string sourcePath, string path, IWriteFileOptions options)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!options.OverrideIfExists && await FileExistsAsync(path))
            {
                throw new FileAlreadyExistsException(path);
            }


            CreateDirectoryIfNotExisting(path);

            System.IO.File.Copy(sourcePath, path, options.OverrideIfExists);
            var fileInfo = new FileInfo(path);
            var ret      = new PhysicalFileInfo(fileInfo);

            return(ret);
        }