예제 #1
0
파일: StreamExm.cs 프로젝트: Albeoris/Spira
 public static void Read(this Stream input, SafeHGlobalHandle buffer, long offset, int length)
 {
     try
     {
         using (UnmanagedMemoryStream output = new UnmanagedMemoryStream(buffer, 0, length, FileAccess.Write))
         {
             byte[] buff = new byte[Math.Min(32 * 1024, length)];
             input.CopyTo(output, length, buff);
         }
     }
     catch
     {
         buffer.Dispose();
         throw;
     }
 }
예제 #2
0
파일: StreamExm.cs 프로젝트: Albeoris/Spira
        public static SafeHGlobalHandle ReadBuff(this Stream input, int size)
        {
            SafeHGlobalHandle handle = new SafeHGlobalHandle(size);

            try
            {
                using (UnmanagedMemoryStream output = new UnmanagedMemoryStream(handle, 0, size, FileAccess.Write))
                {
                    byte[] buff = new byte[Math.Min(32 * 1024, size)];
                    input.CopyTo(output, size, buff);
                }
            }
            catch
            {
                handle.Dispose();
                throw;
            }

            return(handle);
        }