DimitarSerg

Untitled

May 16th, 2023
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1.         private static bool ByteArrayToFile(string fileName, byte[] byteArray, int offset)
  2.         {
  3.             try
  4.             {
  5.                 if (offset == 0)
  6.                 {
  7.                     using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
  8.                     {
  9.                         fs.Write(byteArray, 0, byteArray.Length);
  10.                         return true;
  11.                     }
  12.                 }
  13.                 else
  14.                 {
  15.                     using (var fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
  16.                     {
  17.                         Console.WriteLine(offset + " " + byteArray.Length);
  18.                         fs.Write(byteArray, offset, byteArray.Length);
  19.                         return true;
  20.                     }
  21.                 }
  22.  
  23.             }
  24.             catch (Exception ex)
  25.             {
  26.                 Console.WriteLine("Exception caught in process: {0}", ex);
  27.                 return false;
  28.             }
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment