예제 #1
0
        public static List <byte> ReadContents(BinaryFileHandle fileHandle, Action <string> logger)
        {
            fileHandle.TryPrepareForRead();

            try
            {
                FileStream fileStream = fileHandle.GetFileStream();
                byte[]     buffer     = new byte[fileStream.Length];
                fileStream.Read(buffer, 0, Convert.ToInt32(fileStream.Length));
                logger(string.Format("Read {0} bytes.", buffer.Length));
                return(buffer.ToList());
            }
            finally
            {
                fileHandle.Close();
            }
        }
예제 #2
0
        public static string WriteFile(BinaryFileHandle fileHandle, bool closeFileHandle, IEnumerable <byte> contents, DoesNotExistOptions fileDoesNotExist, ExistOptions fileExist, Action <string> logger)
        {
            fileHandle.TryPrepareForWrite(fileDoesNotExist, fileExist);

            try
            {
                byte[] arrayContents = contents.ToArray();
                var    fileStream    = fileHandle.GetFileStream();
                logger(string.Format("Writing {0} bytes.", arrayContents.Length));
                fileStream.Write(arrayContents, 0, arrayContents.Length);
            }
            finally
            {
                if (closeFileHandle)
                {
                    fileHandle.Close();
                }
            }

            return(fileHandle.FilePath);
        }