Example #1
0
        public async Task CopyToAsync(VirtualDirectory destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            foreach (VirtualFile file in Entries.OfType <VirtualFile>())
            {
                VirtualFile destinationFile = destination.File(file.Name);
                using (Stream destinationStream = destinationFile.OpenWrite())
                    using (Stream sourceStream = file.OpenRead())
                    {
                        await sourceStream.CopyToAsync(destinationStream).ConfigureAwait(false);
                    }
            }

            foreach (VirtualDirectory directory in Directories)
            {
                await directory.CopyToAsync(destination.Directory(directory.Name)).ConfigureAwait(false);
            }
        }
Example #2
0
        public VirtualFile CopyTo(VirtualDirectory destinationDirectory)
        {
            if (destinationDirectory == null)
            {
                throw new ArgumentNullException(nameof(destinationDirectory));
            }

            if (destinationDirectory.FileExists(Name))
            {
                throw new FormattableIoException($"File {Name} already exists in {destinationDirectory.FullName}");
            }

            VirtualFile result = destinationDirectory.File(Name);

            using (Stream readStream = OpenRead())
                using (Stream writeStream = result.OpenWrite())
                {
                    readStream.CopyTo(writeStream);
                }

            return(result);
        }