Beispiel #1
0
        /// <summary>
        /// Write the content of a stream (from the current position to the end) to a file. Does not advance the stream's position.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="path">Path to the file</param>
        /// <param name="promptId"></param>
        /// <param name="copyFunction"></param>
        /// <returns>True if the operation succeeded, otherwise false. Exceptions might be thrown depending on the <paramref name="copyFunction"/>.</returns>
        public static bool WriteToFileRelative(this Stream input, string path, string promptId = null, Action <Stream, Stream> copyFunction = null)
        {
            if (copyFunction == null)
            {
                copyFunction = (inputStream, outputStream) => inputStream.Copy(outputStream);
            }

            using (var fileStream = Bio.CreateFile(path, promptId)) {
                input.KeepPosition(() => copyFunction(input, fileStream));
            }

            return(true);
        }