public int nabtoStreamRead(IntPtr stream, out byte[] resultBuffer)
        {
            IntPtr nativeResultBuffer;
            IntPtr resultLength;

            var status = Win32NativeMethods.nabtoStreamRead(stream, out nativeResultBuffer, out resultLength);

            if (status == NABTO_OK)
            {
                if (IntPtr.Zero != resultLength)
                {
                    resultBuffer = MoveBuffer(nativeResultBuffer, resultLength);
                }
                else
                {
                    // Zero-length buffers are returned as null to avoid allocation, copying and garbage collection (especially costly when performing non-blocking polling for data)
                    Free(nativeResultBuffer);
                    resultBuffer = null;
                }
            }
            //else if (status == NABTO_FAILED) // workaround for NABTO_FAILED when a blocking nabtoStreamRead is aborted by calling nabtoShutdown.
            //{
            //    status = NABTO_OK;
            //    resultBuffer = null;
            //}
            //    // Todo
            //else if (status == NABTO_ABORTED) // workaround for NABTO_FAILED when a blocking nabtoStreamRead is aborted by calling nabtoShutdown.
            //{
            //    status = NABTO_OK;
            //    resultBuffer = null;
            //}
            //else if (status == NABTO_STREAM_CLOSED) // workaround for NABTO_FAILED when a blocking nabtoStreamRead is aborted by calling nabtoShutdown.
            //{
            //    status = NABTO_OK;
            //    resultBuffer = null;
            //}
            else
            {
                resultBuffer = null;
            }

            return(status);
        }