C# Класс CodeSnippets.IO.FileCloner

This class demonstrates multiple ways to clone files stored in the file system. In all cases, the source file is stored in the file system. Where the return type is a MemoryStream, the destination file will be stored only on that MemoryStream. Where the return type is a FileStream, the destination file will be stored in the file system and opened on that FileStream.
The contents of the MemoryStream instances returned by the sample methods can be written to a file as follows: var stream = ReadAllBytesToMemoryStream(sourcePath); File.WriteAllBytes(destPath, stream.GetBuffer()); You can use MemoryStream.GetBuffer in cases where the MemoryStream was created using MemoryStream() or MemoryStream(int). In other cases, you can use the MemoryStream.ToArray method, which copies the internal buffer to a new byte array. Thus, GetBuffer() should be a tad faster.
Показать файл Открыть проект

Открытые методы

Метод Описание
CopyFileAndOpenFileStream ( string sourcePath, string destPath ) : FileStream
CopyFileStreamToFileStream ( string sourcePath, string destPath ) : FileStream
CopyFileStreamToMemoryStream ( string path ) : MemoryStream
ReadAllBytesToMemoryStream ( string path ) : MemoryStream

Описание методов

CopyFileAndOpenFileStream() публичный статический Метод

public static CopyFileAndOpenFileStream ( string sourcePath, string destPath ) : FileStream
sourcePath string
destPath string
Результат FileStream

CopyFileStreamToFileStream() публичный статический Метод

public static CopyFileStreamToFileStream ( string sourcePath, string destPath ) : FileStream
sourcePath string
destPath string
Результат FileStream

CopyFileStreamToMemoryStream() публичный статический Метод

public static CopyFileStreamToMemoryStream ( string path ) : MemoryStream
path string
Результат MemoryStream

ReadAllBytesToMemoryStream() публичный статический Метод

public static ReadAllBytesToMemoryStream ( string path ) : MemoryStream
path string
Результат MemoryStream