public static void Copy(string source, string destination) { // TODO: Exception handler, or finally block, to clean up on failures? // We need to copy the tags from the source file to a temporary file. FileStream sourceStream = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read); sourceStream.Seek(0, SeekOrigin.Begin); // Create a temporary file: TemporaryFile tempFile = new TemporaryFile(destination); // Open it. FileStream tempStream = new FileStream(tempFile.Path, FileMode.Create, FileAccess.Write, FileShare.None); // Copy the tags. CopyTags(sourceStream, tempStream); // We don't need the source file any more. sourceStream.Close(); // Get the destination file open: FileStream destinationStream = new FileStream(destination, FileMode.Open, FileAccess.Read, FileShare.None); // Now we need to skip the tags in the destination. TagUtil.SkipTags(destinationStream); // Copy the remainder of the output file into the temporary file. StreamCopier.Copy(destinationStream, tempStream); // We don't need the destination file any more. destinationStream.Close(); // We don't need the temp file any more. tempStream.Close(); // Do the rename shuffle. tempFile.Swap(); }
public static void Remove(string path) { // TODO: Exception handler to clean up on failures. // Open the source file, and then skip over any tags. FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); // Go back to the beginning of the stream. stream.Seek(0, SeekOrigin.Begin); TagUtil.SkipTags(stream); // Create a temporary file: TemporaryFile tempFile = new TemporaryFile(path); FileStream dest = new FileStream(tempFile.Path, FileMode.Create, FileAccess.Write, FileShare.None); StreamCopier.Copy(stream, dest); stream.Close(); dest.Close(); tempFile.Swap(); }