C# Class 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.
Afficher le fichier Open project: shendongnian/code

Méthodes publiques

Méthode Description
CopyFileAndOpenFileStream ( string sourcePath, string destPath ) : FileStream
CopyFileStreamToFileStream ( string sourcePath, string destPath ) : FileStream
CopyFileStreamToMemoryStream ( string path ) : MemoryStream
ReadAllBytesToMemoryStream ( string path ) : MemoryStream

Method Details

CopyFileAndOpenFileStream() public static méthode

public static CopyFileAndOpenFileStream ( string sourcePath, string destPath ) : FileStream
sourcePath string
destPath string
Résultat FileStream

CopyFileStreamToFileStream() public static méthode

public static CopyFileStreamToFileStream ( string sourcePath, string destPath ) : FileStream
sourcePath string
destPath string
Résultat FileStream

CopyFileStreamToMemoryStream() public static méthode

public static CopyFileStreamToMemoryStream ( string path ) : MemoryStream
path string
Résultat MemoryStream

ReadAllBytesToMemoryStream() public static méthode

public static ReadAllBytesToMemoryStream ( string path ) : MemoryStream
path string
Résultat MemoryStream