示例#1
0
 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
        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);
        }